diff mbox series

elf: Build tst-relr-mod[34]a.so with $(LDFLAGS-rpath-ORIGIN)

Message ID 20221028221632.500817-1-hjl.tools@gmail.com
State New
Headers show
Series elf: Build tst-relr-mod[34]a.so with $(LDFLAGS-rpath-ORIGIN) | expand

Commit Message

H.J. Lu Oct. 28, 2022, 10:16 p.m. UTC
When --enable-hardcoded-path-in-tests is used only with DT_RUNPATH,
elf/tst-relr3 and elf/tst-relr4 failed to run.  Their dependency
libraries, tst-relr-mod3a.so and tst-relr-mod4a.so, are failed to
load since DT_RUNPATH on executable doesn't apply to them.  Build
tst-relr-mod3a.so and tst-relr-mod4a.so with $(LDFLAGS-rpath-ORIGIN)
to add DT_RUNPATH for their dependency libraries.
---
 elf/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Fangrui Song Oct. 28, 2022, 11:57 p.m. UTC | #1
On 2022-10-28, H.J. Lu via Libc-alpha wrote:
>When --enable-hardcoded-path-in-tests is used only with DT_RUNPATH,
>elf/tst-relr3 and elf/tst-relr4 failed to run.  Their dependency
>libraries, tst-relr-mod3a.so and tst-relr-mod4a.so, are failed to
>load since DT_RUNPATH on executable doesn't apply to them.  Build
>tst-relr-mod3a.so and tst-relr-mod4a.so with $(LDFLAGS-rpath-ORIGIN)
>to add DT_RUNPATH for their dependency libraries.
>---
> elf/Makefile | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/elf/Makefile b/elf/Makefile
>index 86c960cf8a..5f7d222bb1 100644
>--- a/elf/Makefile
>+++ b/elf/Makefile
>@@ -2872,7 +2872,7 @@ $(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
> $(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
>   $(objpfx)tst-relr-mod3b.so
> 	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>-	$(LDFLAGS-soname-fname) \
>+	$(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
> 	-shared -o $@.new $(filter-out $(map-file),$^)
> 	$(call after-link,$@.new)
> 	mv -f $@.new $@
>@@ -2891,7 +2891,7 @@ $(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
> $(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
>   $(objpfx)tst-relr-mod4b.so
> 	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>-	$(LDFLAGS-soname-fname) \
>+	$(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
> 	-shared -o $@.new $(filter-out $(map-file),$^)
> 	$(call after-link,$@.new)
> 	mv -f $@.new $@
>-- 
>2.37.3

When --enable-hardcoded-path-in-tests is specified, the test is not run
with `ld.so --library-path`.  elf/tst-relr-mod3a.so's DT_NEEDED
elf/tst-relr-mod3b.so fails to load.  This patch makes
elf/tst-relr-mod3a.so have `Library runpath: [$ORIGIN]` and allows
elf/tst-relr-mod3b.so to be loaded.

Tested that the tests pass with or without --enable-hardcoded-path-in-tests.

Reviewed-by: Fangrui Song <maskray@google.com>
Carlos O'Donell Nov. 1, 2022, 1:57 p.m. UTC | #2
On 10/28/22 19:57, Fangrui Song via Libc-alpha wrote:
> On 2022-10-28, H.J. Lu via Libc-alpha wrote:
>> When --enable-hardcoded-path-in-tests is used only with DT_RUNPATH,
>> elf/tst-relr3 and elf/tst-relr4 failed to run.  Their dependency
>> libraries, tst-relr-mod3a.so and tst-relr-mod4a.so, are failed to
>> load since DT_RUNPATH on executable doesn't apply to them.  Build
>> tst-relr-mod3a.so and tst-relr-mod4a.so with $(LDFLAGS-rpath-ORIGIN)
>> to add DT_RUNPATH for their dependency libraries.
>> ---
>> elf/Makefile | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/elf/Makefile b/elf/Makefile
>> index 86c960cf8a..5f7d222bb1 100644
>> --- a/elf/Makefile
>> +++ b/elf/Makefile
>> @@ -2872,7 +2872,7 @@ $(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
>> $(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
>>   $(objpfx)tst-relr-mod3b.so
>>     $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>> -    $(LDFLAGS-soname-fname) \
>> +    $(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
>>     -shared -o $@.new $(filter-out $(map-file),$^)
>>     $(call after-link,$@.new)
>>     mv -f $@.new $@
>> @@ -2891,7 +2891,7 @@ $(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
>> $(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
>>   $(objpfx)tst-relr-mod4b.so
>>     $(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
>> -    $(LDFLAGS-soname-fname) \
>> +    $(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
>>     -shared -o $@.new $(filter-out $(map-file),$^)
>>     $(call after-link,$@.new)
>>     mv -f $@.new $@
>> -- 
>> 2.37.3
> 
> When --enable-hardcoded-path-in-tests is specified, the test is not run
> with `ld.so --library-path`.  elf/tst-relr-mod3a.so's DT_NEEDED
> elf/tst-relr-mod3b.so fails to load.  This patch makes
> elf/tst-relr-mod3a.so have `Library runpath: [$ORIGIN]` and allows
> elf/tst-relr-mod3b.so to be loaded.
> 
> Tested that the tests pass with or without --enable-hardcoded-path-in-tests.
> 
> Reviewed-by: Fangrui Song <maskray@google.com>
> 

Thanks to the both of you for a prompt fix!

This returns my Fedora testers back to clean runs and helps me review more patches :-)
diff mbox series

Patch

diff --git a/elf/Makefile b/elf/Makefile
index 86c960cf8a..5f7d222bb1 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2872,7 +2872,7 @@  $(objpfx)tst-relr-mod3b.so: $(objpfx)tst-relr-mod3b.os
 $(objpfx)tst-relr-mod3a.so: $(objpfx)tst-relr-mod3a.os \
   $(objpfx)tst-relr-mod3b.so
 	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
-	$(LDFLAGS-soname-fname) \
+	$(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
 	-shared -o $@.new $(filter-out $(map-file),$^)
 	$(call after-link,$@.new)
 	mv -f $@.new $@
@@ -2891,7 +2891,7 @@  $(objpfx)tst-relr-mod4b.so: $(objpfx)tst-relr-mod4b.os
 $(objpfx)tst-relr-mod4a.so: $(objpfx)tst-relr-mod4a.os \
   $(objpfx)tst-relr-mod4b.so
 	$(LINK.o) -nostdlib -nostartfiles -Wl,-z,pack-relative-relocs \
-	$(LDFLAGS-soname-fname) \
+	$(LDFLAGS-soname-fname) $(LDFLAGS-rpath-ORIGIN) \
 	-shared -o $@.new $(filter-out $(map-file),$^)
 	$(call after-link,$@.new)
 	mv -f $@.new $@