From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 78C513858CD1 for ; Fri, 23 Feb 2024 14:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78C513858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 78C513858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708699743; cv=none; b=MQzlCcz26Hol7ZJqvci2UJQGXYdchOoGYlsF3sxw4BQ8Zww4bzvb3S6wZ+54LiuN/2vwqpocSxrT9NRwaKvtbZZc3MwCkuF6mGMLmEBSCEjnlGDaHpuxr6zCXJyQ7usTJkW4nNiM2cuh1dCZF/8c7dFScDVSubleAomSs+kEFik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708699743; c=relaxed/simple; bh=/RGBcd9ysWqAAGcFoogFiPxiVmcEWxl8edDLleYI1Lw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=spYYZyCgaSG5fD+ophfRznUHA1MJxNTU/Ggum2M6T5eb8FossTUx7pc+q1r5Auu3vX0vhfGGXe+uG2Okkvlkdil3gIk7aKbZgZyff2rxaKPK35VY/Q0s0Kd0tInHVsiQYVznGd2fhe8bdDN86QM62BZ2svmTlfds80g1SA/Qf2E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e32a92e0fdso179003b3a.0 for ; Fri, 23 Feb 2024 06:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708699739; x=1709304539; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=uOt1nEF77cifqegtmOd3eSzl5OMFup6tCN3Ibtt+gI4=; b=MVew3DGUitAwqfNLHPALMtBRWqzWGc+Yoj9aflYEkd1mb/yHkV/OOeoq/VO/HRTat8 ysLp5ryAO8n9fTh28wt+7BoIYVmzV7CrxDXYXM/0bGOIAOMqMyG4+30oz31mnoNeyj7N rbNBm4KvkWHaqfttCalB+D5+bf3jc+onviXZyWpH/mVk3N8pzDScXqG1mQUWJBu03l0C uIUJMvaF8jORMEqu1Tu28xTBHzEDKpCSjLHJYYO2kCzRk+6YdK9j4NqLCej6oOgv/98I mVSK7/rJkZpeXp9aAhEFGT9SXHYQpFYlN8FhuANwwrcN7TaaeuVkRZ1itYb+LCw5km41 86NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708699739; x=1709304539; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uOt1nEF77cifqegtmOd3eSzl5OMFup6tCN3Ibtt+gI4=; b=M80jLt3GJfpEpzw3l4+2gXh2LFBHK+ih9bJsG2Ilh4Nk51kb+bgL6gW1YVHLT7wVGO NPAikp9eKQ4ZMZTx6Zs93lkHvP6amkKLWj6YuXZRuP1M4s7O3xMZNPVJ0exbpNWdbeMB Qdce3cqliziCs1zp5VV8Ky4HlHwM/fzpmB2SBAmEXgz75ytKaY9Vg1x46pTmxqjXg5VN BXSb9yRcNdCIoppB62mroSdwjTyfU+amJHnLqZL7tSztssPBrTWXxP1iwaOb3+XFITHX a1w2XgCHGhL0iCAnbHft1CXM2GvWtoVQ6W1K4JNyN9bNtECAeajIPnhrTqKpXoa2myLn lk9Q== X-Forwarded-Encrypted: i=1; AJvYcCUsD0TKJoAgcBsc8lhGxiIkejs/PQk3+3R2VeQDdEhipKyIrVsMjvJ9jZjfXmVvK54QCU2rTMq4HsixLnE07Y+vpR5KRcY5JsTO X-Gm-Message-State: AOJu0Yw5vHbcoEl0qn30mHQOLgOqLTctM6ulshaSi/fixcCbrliV95kc 3jCVAdSWlV0OmoWSYw5IVLANR8cj6TpsQwW6Opu2xjuH2bzdq6ZuB9sWUBTKB7o= X-Google-Smtp-Source: AGHT+IGQCwmNrheY1js0SUXrHVqsdpZhY+DXrpX7BP6zAFnkhfhECMtURdewiZedU3A29NP+KYiJFw== X-Received: by 2002:a05:6a00:c96:b0:6e0:f3f4:8da9 with SMTP id a22-20020a056a000c9600b006e0f3f48da9mr49590pfv.4.1708699739216; Fri, 23 Feb 2024 06:48:59 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:18f8:a449:b2c5:f320:f4d1? ([2804:1b3:a7c1:18f8:a449:b2c5:f320:f4d1]) by smtp.gmail.com with ESMTPSA id k6-20020a635a46000000b005db034d1514sm12174409pgm.82.2024.02.23.06.48.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Feb 2024 06:48:58 -0800 (PST) Message-ID: <6b7a72dc-cbfa-4d5c-871f-fc9591e2252d@linaro.org> Date: Fri, 23 Feb 2024 11:48:55 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] S390: Always enable static PIE if build with lld. Content-Language: en-US To: Stefan Liebler , libc-alpha@sourceware.org References: <20240221145610.962170-1-stli@linux.ibm.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20240221145610.962170-1-stli@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 21/02/24 11:56, Stefan Liebler wrote: > LLVM ld.lld now also supports s390x and avoids unnecessary TPOFF > relocations for position independent executables. Both recent > commits were also cherry-picked to LLVM 18. > > This patch just enables static PIE if build with supported lld. > --- > sysdeps/s390/s390-64/configure | 80 ++++++++++++++++++++++++++++++- > sysdeps/s390/s390-64/configure.ac | 16 ++++++- > 2 files changed, 92 insertions(+), 4 deletions(-) > > diff --git a/sysdeps/s390/s390-64/configure b/sysdeps/s390/s390-64/configure > index 824ae9c129..d79a25ecf7 100644 > --- a/sysdeps/s390/s390-64/configure > +++ b/sysdeps/s390/s390-64/configure > @@ -12,8 +12,84 @@ case $($LD --version) in > libc_cv_s390x_staticpie_req_version=no > ;; > "LLD"*) > - # As of 2023-08-07, there is no lld which supports s390x. > - libc_cv_s390x_staticpie_req_version=no > + # The required lld patches are available with LLVM 18: > + # - [lld] Add target support for SystemZ (s390x) #75643 > + # https://github.com/llvm/llvm-project/pull/75643 > + # 2024-02-13: https://github.com/llvm/llvm-project/commit/fe3406e349884e4ef61480dd0607f1e237102c74 > + # - [lld/ELF] Avoid unnecessary TPOFF relocations in GOT for -pie #81739 > + # https://github.com/llvm/llvm-project/pull/81739 > + # 2024-02-14: https://github.com/llvm/llvm-project/commit/6f907733e65d24edad65f763fb14402464bd578b > + libc_cv_s390x_staticpie_req_version=yes > + # Skip AC_CHECK_PROGS and just use the result from main configure.ac. > + libc_cv_s390x_staticpie_req_LD=$LD > + for ac_prog in $LD > +do > + # Extract the first word of "$ac_prog", so it can be a program name with args. > +set dummy $ac_prog; ac_word=$2 > +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 > +printf %s "checking for $ac_word... " >&6; } > +if test ${ac_cv_prog_libc_cv_s390x_staticpie_req_LD+y} > +then : > + printf %s "(cached) " >&6 > +else $as_nop > + if test -n "$libc_cv_s390x_staticpie_req_LD"; then > + ac_cv_prog_libc_cv_s390x_staticpie_req_LD="$libc_cv_s390x_staticpie_req_LD" # Let the user override the test. > +else > +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR > +for as_dir in $PATH > +do > + IFS=$as_save_IFS > + case $as_dir in #((( > + '') as_dir=./ ;; > + */) ;; > + *) as_dir=$as_dir/ ;; > + esac > + for ac_exec_ext in '' $ac_executable_extensions; do > + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then > + ac_cv_prog_libc_cv_s390x_staticpie_req_LD="$ac_prog" > + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 > + break 2 > + fi > +done > + done > +IFS=$as_save_IFS > + > +fi > +fi > +libc_cv_s390x_staticpie_req_LD=$ac_cv_prog_libc_cv_s390x_staticpie_req_LD > +if test -n "$libc_cv_s390x_staticpie_req_LD"; then > + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_s390x_staticpie_req_LD" >&5 > +printf "%s\n" "$libc_cv_s390x_staticpie_req_LD" >&6; } > +else > + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 > +printf "%s\n" "no" >&6; } > +fi > + > + > + test -n "$libc_cv_s390x_staticpie_req_LD" && break > +done > + > +if test -z "$libc_cv_s390x_staticpie_req_LD"; then > + ac_verc_fail=yes > +else > + # Found it, now check the version. > + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking version of $libc_cv_s390x_staticpie_req_LD" >&5 > +printf %s "checking version of $libc_cv_s390x_staticpie_req_LD... " >&6; } > + ac_prog_version=`$libc_cv_s390x_staticpie_req_LD --version 2>&1 | sed -n 's/^.*LLD.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'` > + case $ac_prog_version in > + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; > + 1[8-9].*|[2-9][0-9].*) > + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; > + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; > + > + esac > + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5 > +printf "%s\n" "$ac_prog_version" >&6; } > +fi > +if test $ac_verc_fail = yes; then > + libc_cv_s390x_staticpie_req_version=no > +fi > + > ;; > *) > # The required binutils patches are available with bintuils 2.39 > diff --git a/sysdeps/s390/s390-64/configure.ac b/sysdeps/s390/s390-64/configure.ac > index 4657de0d37..0c1b276086 100644 > --- a/sysdeps/s390/s390-64/configure.ac > +++ b/sysdeps/s390/s390-64/configure.ac > @@ -12,8 +12,20 @@ case $($LD --version) in > libc_cv_s390x_staticpie_req_version=no > ;; > "LLD"*) > - # As of 2023-08-07, there is no lld which supports s390x. > - libc_cv_s390x_staticpie_req_version=no > + # The required lld patches are available with LLVM 18: > + # - [lld] Add target support for SystemZ (s390x) #75643 > + # https://github.com/llvm/llvm-project/pull/75643 > + # 2024-02-13: https://github.com/llvm/llvm-project/commit/fe3406e349884e4ef61480dd0607f1e237102c74 > + # - [lld/ELF] Avoid unnecessary TPOFF relocations in GOT for -pie #81739 > + # https://github.com/llvm/llvm-project/pull/81739 > + # 2024-02-14: https://github.com/llvm/llvm-project/commit/6f907733e65d24edad65f763fb14402464bd578b > + libc_cv_s390x_staticpie_req_version=yes > + # Skip AC_CHECK_PROGS and just use the result from main configure.ac. > + libc_cv_s390x_staticpie_req_LD=$LD > + AC_CHECK_PROG_VER(libc_cv_s390x_staticpie_req_LD, $LD, --version, > + [LLD.* \([0-9][0-9]*\.[0-9.]*\)], > + [1[8-9].*|[2-9][0-9].*], > + libc_cv_s390x_staticpie_req_version=no) > ;; > *) > # The required binutils patches are available with bintuils 2.39 Sorry, but all the PIE tests on s390x are overcomplicated and brittle. The version check is really unecessary and I think we should move away from it, instead check for either linker support and resulting relocations on generated code. The gold supports could be just filtered out by using -Wl,--no-dynamic-linker on the -pie check. Also, the relocation check does not seem correct: at least with binutils 2.36 ld generates R_390_TLS_DTPMOD/R_390_TLS_DTPOFF for the 'foo' access. So I think we should use something as the below. The libc_cv_s390x_staticpie_req_runtime is correctly set for old binutils and lld version 17, while being true for recent binutils and lld version 18+. I also think all the comments of the requirement are confusing and does not help much (it also references others ABI, like i386 and ia64 which is not straightforward to understand why it matter for s390x), so I would recommend to just remove them altogether. diff --git a/sysdeps/s390/s390-64/configure.ac b/sysdeps/s390/s390-64/configure.ac index 4657de0d37..5117b424f3 100644 --- a/sysdeps/s390/s390-64/configure.ac +++ b/sysdeps/s390/s390-64/configure.ac @@ -1,34 +1,6 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/s390/s390-64. -# Bypass result of runtime configure check for known linker versions as -# e.g. crt-files or libc.so might not be available in bootstrapping -# environments. -case $($LD --version) in - "GNU gold"*) - # As of 2023-08-07, gold does not support static PIE due to - # Bug 22221 - add --no-dynamic-linker option - # https://sourceware.org/bugzilla/show_bug.cgi?id=22221 - libc_cv_s390x_staticpie_req_version=no - ;; - "LLD"*) - # As of 2023-08-07, there is no lld which supports s390x. - libc_cv_s390x_staticpie_req_version=no - ;; - *) - # The required binutils patches are available with bintuils 2.39 - libc_cv_s390x_staticpie_req_version=yes - # Skip AC_CHECK_PROGS and just use the result from main configure.ac. - libc_cv_s390x_staticpie_req_LD=$LD - AC_CHECK_PROG_VER(libc_cv_s390x_staticpie_req_LD, $LD, --version, - [GNU ld.* \([0-9][0-9]*\.[0-9.]*\)], - [2.1[0-9][0-9]*|2.39*|2.[4-9][0-9]*|[3-9].*|[1-9][0-9]*], - libc_cv_s390x_staticpie_req_version=no) - ;; -esac -AC_MSG_CHECKING([for s390-specific static PIE requirements (version check)]) -AC_MSG_RESULT($libc_cv_s390x_staticpie_req_version) - # Minimal checking for static PIE support in ld. # Compare to ld testcase/bugzilla: # /ld/testsuite/ld-elf/pr22263-1.rd @@ -58,15 +30,14 @@ EOF libc_cv_s390x_staticpie_req_runtime=no if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest1.c -o conftest1.o]) \ && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest2.c -o conftest2.o]) \ - && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -o conftest conftest1.o conftest2.o]) \ - && AC_TRY_COMMAND([! LC_ALL=C $READELF -Wr conftest | grep R_390_TLS_TPOFF]) + && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,--no-dynamic-linker -pie -o conftest conftest1.o conftest2.o]) \ + && AC_TRY_COMMAND([! LC_ALL=C $READELF -Wr conftest | grep -E '\''R_390_TLS_DTPMOD|R_390_TLS_DTPOFF'\'']) then libc_cv_s390x_staticpie_req_runtime=yes fi rm -rf conftest.*]) -if test $libc_cv_s390x_staticpie_req_runtime = yes \ - || test $libc_cv_s390x_staticpie_req_version = yes; then +if test $libc_cv_s390x_staticpie_req_runtime = yes; then # Static PIE is supported only on 64bit. # Ensure you also have those patches for: # - binutils (ld)