[1/4] elf: Introduce the rtld-stubbed-symbols makefile variable

Message ID 3e85b3e4993068ae16d283c548c17823106f132a.1581182210.git.fweimer@redhat.com
State New
Headers show
Series
  • Avoid malloc symbol interposition in the dynamic loader [BZ #25486]
Related show

Commit Message

Florian Weimer Feb. 8, 2020, 7 p.m.
This generalizes a mechanism used for stack-protector support, so
that it can be applied to other symbols if required.

Tested on i686-linux-gnu without the stack protector, and on
x86_64-linux-gnu with stack-protector-strong.
---
 elf/Makefile | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

-- 
2.24.1

Comments

Carlos O'Donell Feb. 14, 2020, 10:36 p.m. | #1
On 2/8/20 2:00 PM, Florian Weimer wrote:
> This generalizes a mechanism used for stack-protector support, so

> that it can be applied to other symbols if required.

> 

> Tested on i686-linux-gnu without the stack protector, and on

> x86_64-linux-gnu with stack-protector-strong.


OK for master.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>


> ---

>  elf/Makefile | 22 +++++++++++++---------

>  1 file changed, 13 insertions(+), 9 deletions(-)

> 

> diff --git a/elf/Makefile b/elf/Makefile

> index 632a4d8b0f..60c8082d06 100644

> --- a/elf/Makefile

> +++ b/elf/Makefile

> @@ -482,21 +482,25 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)

>  # are compiled with special flags, and puts these modules into rtld-libc.a

>  # for us.  Then we do the real link using rtld-libc.a instead of libc_pic.a.

>  

> -# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail

> -# and __stack_chk_fail_local symbols defined, to prevent the real things

> -# being dragged into rtld even though rtld is never built with stack-

> -# protection.

> +# These symbols need to be stubbed out during symbol discovery because

> +# their implementation is provided differently in rtld, and the symbol

> +# discovery mechanism is not compatible with the libc implementation

> +# when compiled for libc.

> +rtld-stubbed-symbols =

> +

> +# The GCC arguments that implement $(rtld-stubbed-symbols).

> +rtld-stubbed-symbols-args = \

> +  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))

>  

>  ifeq ($(have-ssp),yes)

> -dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \

> -			-Wl,--defsym='__stack_chk_fail_local=0'

> -else

> -dummy-stack-chk-fail :=

> +# rtld is not built with the stack protector, so these references will

> +# go away in the rebuilds.

> +rtld-stubbed-symbols += __stack_chk_fail __stack_chk_fail_local

>  endif

>  

>  $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a

>  	@-rm -f $@T

> -	$(reloc-link) -o $@.o $(dummy-stack-chk-fail) \

> +	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \

>  		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T

>  	rm -f $@.o

>  	mv -f $@T $@

> 



-- 
Cheers,
Carlos.

Patch

diff --git a/elf/Makefile b/elf/Makefile
index 632a4d8b0f..60c8082d06 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -482,21 +482,25 @@  $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
 # are compiled with special flags, and puts these modules into rtld-libc.a
 # for us.  Then we do the real link using rtld-libc.a instead of libc_pic.a.
 
-# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail
-# and __stack_chk_fail_local symbols defined, to prevent the real things
-# being dragged into rtld even though rtld is never built with stack-
-# protection.
+# These symbols need to be stubbed out during symbol discovery because
+# their implementation is provided differently in rtld, and the symbol
+# discovery mechanism is not compatible with the libc implementation
+# when compiled for libc.
+rtld-stubbed-symbols =
+
+# The GCC arguments that implement $(rtld-stubbed-symbols).
+rtld-stubbed-symbols-args = \
+  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
 
 ifeq ($(have-ssp),yes)
-dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \
-			-Wl,--defsym='__stack_chk_fail_local=0'
-else
-dummy-stack-chk-fail :=
+# rtld is not built with the stack protector, so these references will
+# go away in the rebuilds.
+rtld-stubbed-symbols += __stack_chk_fail __stack_chk_fail_local
 endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(dummy-stack-chk-fail) \
+	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
 		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
 	rm -f $@.o
 	mv -f $@T $@