diff mbox series

elf: unconditionally add dl-static to sysdep-dl-routines in Makefile

Message ID 20210315210103.3040700-1-carlos.seo@linaro.org
State Under Review
Delegated to: Szabolcs Nagy
Headers show
Series elf: unconditionally add dl-static to sysdep-dl-routines in Makefile | expand

Commit Message

Carlos Seo March 15, 2021, 9:01 p.m. UTC
Building dl-static is also needed when building glibc with --disable-shared.

Tested on aarch64-linux-gnu and powerpc64le-linux-gnu.
---
 sysdeps/unix/sysv/linux/aarch64/Makefile | 2 --
 sysdeps/unix/sysv/linux/arc/Makefile     | 2 --
 sysdeps/unix/sysv/linux/mips/Makefile    | 2 --
 sysdeps/unix/sysv/linux/powerpc/Makefile | 2 --
 4 files changed, 8 deletions(-)

Comments

Szabolcs Nagy March 19, 2021, 6:01 p.m. UTC | #1
The 03/15/2021 18:01, Carlos Eduardo Seo via Libc-alpha wrote:
> Building dl-static is also needed when building glibc with --disable-shared.
> 
> Tested on aarch64-linux-gnu and powerpc64le-linux-gnu.

This looks good to me.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

> ---
>  sysdeps/unix/sysv/linux/aarch64/Makefile | 2 --
>  sysdeps/unix/sysv/linux/arc/Makefile     | 2 --
>  sysdeps/unix/sysv/linux/mips/Makefile    | 2 --
>  sysdeps/unix/sysv/linux/powerpc/Makefile | 2 --
>  4 files changed, 8 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
> index 3f22f71bef..41b284df17 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
> @@ -1,9 +1,7 @@
>  ifeq ($(subdir),elf)
> -ifeq ($(build-shared),yes)
>  # This is needed for DSO loading from static binaries.
>  sysdep-dl-routines += dl-static
>  endif
> -endif
>  
>  ifeq ($(subdir),misc)
>  sysdep_headers += sys/elf.h
> diff --git a/sysdeps/unix/sysv/linux/arc/Makefile b/sysdeps/unix/sysv/linux/arc/Makefile
> index 25d7bbecac..4a49f34088 100644
> --- a/sysdeps/unix/sysv/linux/arc/Makefile
> +++ b/sysdeps/unix/sysv/linux/arc/Makefile
> @@ -13,11 +13,9 @@ sysdep_routines += cacheflush
>  endif
>  
>  ifeq ($(subdir),elf)
> -ifeq ($(build-shared),yes)
>  # This is needed for DSO loading from static binaries.
>  sysdep-dl-routines += dl-static
>  endif
> -endif
>  
>  abi-variants := arcle arcbe
>  
> diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
> index 026ba242cf..805dd59bab 100644
> --- a/sysdeps/unix/sysv/linux/mips/Makefile
> +++ b/sysdeps/unix/sysv/linux/mips/Makefile
> @@ -57,10 +57,8 @@ abi-n64_hard_2008-condition := defined(__mips_nan2008) \
>  			       && (_MIPS_SIM == _MIPS_SIM_ABI64)
>  
>  ifeq ($(subdir),elf)
> -ifeq ($(build-shared),yes)
>  # This is needed for DSO loading from static binaries.
>  sysdep-dl-routines += dl-static
> -endif
>  # If the compiler doesn't use GNU.stack note,
>  # this test is expected to fail.
>  ifneq ($(mips-has-gnustack),yes)
> diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
> index a093cda68b..c567d6782a 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/Makefile
> +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
> @@ -13,10 +13,8 @@ gen-as-const-headers += ucontext_i.sym
>  endif
>  
>  ifeq ($(subdir),elf)
> -ifeq ($(build-shared),yes)
>  # This is needed for DSO loading from static binaries.
>  sysdep-dl-routines += dl-static
> -endif
>  # Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
>  LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
>  endif
> -- 
> 2.25.1
>
Florian Weimer March 19, 2021, 6:02 p.m. UTC | #2
* Carlos Eduardo Seo via Libc-alpha:

> Building dl-static is also needed when building glibc with
> --disable-shared.

Given

>  # This is needed for DSO loading from static binaries.

I think this suggests that ideally, the code that needs this would be
disabled at build time, given that there is no DSO left to load in a
static-only build.
Carlos Seo March 30, 2021, 8:45 p.m. UTC | #3
On Fri, 19 Mar 2021 at 15:03, Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * Carlos Eduardo Seo via Libc-alpha:
>
> > Building dl-static is also needed when building glibc with
> > --disable-shared.
>
> Given
>
> >  # This is needed for DSO loading from static binaries.
>
> I think this suggests that ideally, the code that needs this would be
> disabled at build time, given that there is no DSO left to load in a
> static-only build.

Do you want me to modify the original comment, or... ?
Szabolcs Nagy April 20, 2021, 8:12 a.m. UTC | #4
The 03/19/2021 19:02, Florian Weimer wrote:
> * Carlos Eduardo Seo via Libc-alpha:
> 
> > Building dl-static is also needed when building glibc with
> > --disable-shared.
> 
> Given
> 
> >  # This is needed for DSO loading from static binaries.
> 
> I think this suggests that ideally, the code that needs this would be
> disabled at build time, given that there is no DSO left to load in a
> static-only build.

hm, yes dynamic loading from static linked binaries is not
needed in a static only build, but i think currently we
don't distinguish a static libc.a and a "static only" libc.a

we also need to keep some elf code because static pie still
needs self relocation.

i think if it's easy to rip out the dynamic loading code,
then it makes sense to do so (assuming static pie still works)
and if it's hard then it's ok to fix --disable-shared with
minimal effort and apply the patch.
Florian Weimer April 20, 2021, 9:48 a.m. UTC | #5
* Szabolcs Nagy:

> i think if it's easy to rip out the dynamic loading code,
> then it makes sense to do so (assuming static pie still works)
> and if it's hard then it's ok to fix --disable-shared with
> minimal effort and apply the patch.

Agreed.  I think it's become more difficult to rip out the dynamically
linked parts because the vDSO is now used in static binaries, too.
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 3f22f71bef..41b284df17 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -1,9 +1,7 @@ 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
 endif
-endif
 
 ifeq ($(subdir),misc)
 sysdep_headers += sys/elf.h
diff --git a/sysdeps/unix/sysv/linux/arc/Makefile b/sysdeps/unix/sysv/linux/arc/Makefile
index 25d7bbecac..4a49f34088 100644
--- a/sysdeps/unix/sysv/linux/arc/Makefile
+++ b/sysdeps/unix/sysv/linux/arc/Makefile
@@ -13,11 +13,9 @@  sysdep_routines += cacheflush
 endif
 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
 endif
-endif
 
 abi-variants := arcle arcbe
 
diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
index 026ba242cf..805dd59bab 100644
--- a/sysdeps/unix/sysv/linux/mips/Makefile
+++ b/sysdeps/unix/sysv/linux/mips/Makefile
@@ -57,10 +57,8 @@  abi-n64_hard_2008-condition := defined(__mips_nan2008) \
 			       && (_MIPS_SIM == _MIPS_SIM_ABI64)
 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
-endif
 # If the compiler doesn't use GNU.stack note,
 # this test is expected to fail.
 ifneq ($(mips-has-gnustack),yes)
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
index a093cda68b..c567d6782a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -13,10 +13,8 @@  gen-as-const-headers += ucontext_i.sym
 endif
 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
-endif
 # Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
 LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
 endif