S390: Always enable static PIE if build with lld.

Message ID 20240219154931.653686-1-stli@linux.ibm.com
State Superseded
Headers
Series S390: Always enable static PIE if build with lld. |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Stefan Liebler Feb. 19, 2024, 3:49 p.m. UTC
  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 lld.
---
 sysdeps/s390/s390-64/configure    | 10 ++++++++--
 sysdeps/s390/s390-64/configure.ac | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)
  

Comments

Adhemerval Zanella Netto Feb. 20, 2024, 2:49 p.m. UTC | #1
On 19/02/24 12:49, 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.

What about old lld that does not have the cherry-picked commits? Should
we follow other practice and check this with a proper test instead?

> 
> This patch just enables static PIE if build with lld.
> ---
>  sysdeps/s390/s390-64/configure    | 10 ++++++++--
>  sysdeps/s390/s390-64/configure.ac | 10 ++++++++--
>  2 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/sysdeps/s390/s390-64/configure b/sysdeps/s390/s390-64/configure
> index 824ae9c129..c26785f32f 100644
> --- a/sysdeps/s390/s390-64/configure
> +++ b/sysdeps/s390/s390-64/configure
> @@ -12,8 +12,14 @@ 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
>      ;;
>    *)
>      # 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..2b5bffc107 100644
> --- a/sysdeps/s390/s390-64/configure.ac
> +++ b/sysdeps/s390/s390-64/configure.ac
> @@ -12,8 +12,14 @@ 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
>      ;;
>    *)
>      # The required binutils patches are available with bintuils 2.39
  
Stefan Liebler Feb. 21, 2024, 7:51 a.m. UTC | #2
On 20.02.24 15:49, Adhemerval Zanella Netto wrote:
> 
> 
> On 19/02/24 12:49, 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.
> 
> What about old lld that does not have the cherry-picked commits? Should
> we follow other practice and check this with a proper test instead?
In case of s390x, older lld also do not support s390x at all and the
common link-configure tests will fail.

If you fear that somebody might backport the s390-lld-support patch
without the TPOFF patch, e.g. ldconfig is linked as static PIE and will
fail at startup.

But yes, I can just add a version check to lld 18 as known minimum
version. Then if somebody has backported the support to a previous
version, the PIE configure check will detect if both patches were
backported.
  
Stefan Liebler Feb. 21, 2024, 3:05 p.m. UTC | #3
On 21.02.24 08:51, Stefan Liebler wrote:
> On 20.02.24 15:49, Adhemerval Zanella Netto wrote:
>>
>>
>> On 19/02/24 12:49, 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.
>>
>> What about old lld that does not have the cherry-picked commits? Should
>> we follow other practice and check this with a proper test instead?
> In case of s390x, older lld also do not support s390x at all and the
> common link-configure tests will fail.
> 
> If you fear that somebody might backport the s390-lld-support patch
> without the TPOFF patch, e.g. ldconfig is linked as static PIE and will
> fail at startup.
> 
> But yes, I can just add a version check to lld 18 as known minimum
> version. Then if somebody has backported the support to a previous
> version, the PIE configure check will detect if both patches were
> backported.
I've just posted v2 with an additional version check:
https://sourceware.org/pipermail/libc-alpha/2024-February/154896.html

One further hint:
If somebody bootstraps the toolchain from scratch, then there are no
crt-files and the linking configure-tests always fail. Thus static PIE
would not be enabled. Therefore there is the additional version check
which checks for known lld version which allows static PIE.
  

Patch

diff --git a/sysdeps/s390/s390-64/configure b/sysdeps/s390/s390-64/configure
index 824ae9c129..c26785f32f 100644
--- a/sysdeps/s390/s390-64/configure
+++ b/sysdeps/s390/s390-64/configure
@@ -12,8 +12,14 @@  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
     ;;
   *)
     # 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..2b5bffc107 100644
--- a/sysdeps/s390/s390-64/configure.ac
+++ b/sysdeps/s390/s390-64/configure.ac
@@ -12,8 +12,14 @@  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
     ;;
   *)
     # The required binutils patches are available with bintuils 2.39