[PATCH v3] elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263]

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Fri Mar 21 13:42:17 GMT 2025



On 20/03/25 11:11, Adhemerval Zanella Netto wrote:
> 
> 
> On 19/03/25 11:47, Adhemerval Zanella Netto wrote:
>>
>>
>> On 19/03/25 11:02, Adhemerval Zanella Netto wrote:
>>>
>>>
>>> On 19/03/25 09:42, Joseph Myers wrote:
>>>> This still isn't working for me; the build fails with "cannot find 
>>>> -lorigin-mod".  (Before 5291d9f1e274dd869bc0b3d044fd4cbae486893d it was 
>>>> also broken with a lint-makefiles failure.)
>>>>
>>>
>>> I forgot that rules dependencies are evaluated in no defined order. I am
>>> trying to come up a fix, the main issue is making the build with
>>> --enable-hardcoded-path-in-tests.
>>
>> I had to reinstate a custom rule to avoid the DT_NEEDED with a full path
>> and also link tst-origin with built libc:
>>
>> diff --git a/elf/Makefile b/elf/Makefile
>> index 3d60000ec9..fd73b68308 100644
>> --- a/elf/Makefile
>> +++ b/elf/Makefile
>> @@ -456,7 +456,6 @@ tests += \
>>    tst-noload \
>>    tst-non-directory-path \
>>    tst-null-argv \
>> -  tst-origin \
>>    tst-p_align1 \
>>    tst-p_align2 \
>>    tst-p_align3 \
>> @@ -3451,8 +3450,15 @@ $(objpfx)tst-dlopen-constructor-null-mod2.so: \
>>
>>  CFLAGS-tst-origin.c += $(no-stack-protector)
>>  CFLAGS-liborigin-mod.c += $(no-stack-protector)
>> -LDFLAGS-tst-origin += -Wl,-rpath,\$$ORIGIN -L$(subst :, -L,$(rpath-link)) -lorigin-mod
>> -$(objpfx)tst-origin.out: tst-origin.sh $(objpfx)liborigin-mod.so $(objpfx)tst-origin
>> +# The test requires liborigin-mod.so as dependency without a path, which is
>> +# added by default.
>> +$(objpfx)tst-origin: $(objpfx)tst-origin.o $(objpfx)liborigin-mod.so
>> +       $(LINK.o) $(sysdep-LDFLAGS) $(rtld-LDFLAGS) -B$(csu-objpfx) \

It is missing a -nostdlib -nostartfiles here to avoid linking with the
toochain sysroot one.

>> +               $(link-test-modules-rpath-link) \
>> +               $(objpfx)tst-origin.o \
>> +               -o $@ \
>> +               -Wl,-rpath,\$$ORIGIN -L$(subst :, -L,$(rpath-link)) -lorigin-mod
>> +$(objpfx)tst-origin.out: tst-origin.sh $(objpfx)tst-origin
>>         $(SHELL) \
>>                 $< \
>>                 '$(common-objpfx)' \
> 
> Is this ok to fix this issue Florian? I have tested with and without
> --enable-hardcoded-path-in-tests and it seems to work as expected
> by fixing the prerequisite rule and creating a dependency without
> the full path.

I have tested it with different gcc (9, 10, 11, 12, 13) built with 
different glibcs (2.32, 2.33, 2.34, 2.35, 2.38) and I saw no issue.

I will install this patch to avoid the breakage of tst-origin. 


More information about the Libc-alpha mailing list