[PATCH v3] elf: Add back support for programs that do not load libc.so

Florian Weimer fweimer@redhat.com
Tue Nov 12 21:16:41 GMT 2024


* Adhemerval Zanella Netto:

> On 12/11/24 10:56, Florian Weimer wrote:
>> * Andreas Schwab:
>> 
>>> On Nov 12 2024, Florian Weimer wrote:
>>>
>>>> +/* On some build configurations, the main program contains a reference
>>>> +   to __stack_chk_guard, but that cannot be resolved because this test
>>>> +   does not link against libc.so. Provide a definition here, so that
>>>> +   program is able to run.  Zero is a permitted, but unlikely value
>>>> +   for the stack guard.  */
>>>> +void *__stack_chk_guard;
>>>
>>> Why is that not resolved by the definition in ld.so?  It is never
>>> exported by libc.so.
>> 
>> Good question.  The Linaro CI reports this (on aarch64):
>> 
>> /home/tcwg-build/workspace/tcwg_gnu_4/abe/builds/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/glibc-glibc.git~master/elf/tst-nolink-libc: symbol lookup error: /home/tcwg-build/workspace/tcwg_gnu_4/abe/builds/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/glibc-glibc.git~master/elf/ld.so: undefined symbol: __stack_chk_guard, version GLIBC_2.17
>> 
>> I have not been able to reproduce it with my own aarch64 builds.  Given
>> the error, it did not occur to me to search for a definition in ld.so
>> itself.  I agree it must be there.
>> 
>> I suspect it's a corner case in how the search scope is set up, but I'm
>> out of ideas here.
>
> I can reproduce with Ubuntu system compiler, which is what Linaro CI uses
> for the buildbots:

Thanks for digging into this.

> aarch64-linux-gnu-system$ LD_DEBUG=all elf/tst-nolink-libc
>     866454:     symbol=__kernel_clock_gettime;  lookup in file=linux-vdso.so.1 [0]
>     866454:     binding file linux-vdso.so.1 [0] to linux-vdso.so.1 [0]: normal symbol `__kernel_clock_gettime' [LINUX_2.6.39]
>     866454:     symbol=__kernel_gettimeofday;  lookup in file=linux-vdso.so.1 [0]
>     866454:     binding file linux-vdso.so.1 [0] to linux-vdso.so.1 [0]: normal symbol `__kernel_gettimeofday' [LINUX_2.6.39]
>     866454:     symbol=__kernel_clock_getres;  lookup in file=linux-vdso.so.1 [0]
>     866454:     binding file linux-vdso.so.1 [0] to linux-vdso.so.1 [0]: normal symbol `__kernel_clock_getres' [LINUX_2.6.39]
>     866454:
>     866454:     Initial object scopes
>     866454:     object=elf/tst-nolink-libc [0]
>     866454:      scope 0: elf/tst-nolink-libc
>     866454:
>     866454:     object=linux-vdso.so.1 [0]
>     866454:      scope 0: elf/tst-nolink-libc
>     866454:      scope 1: linux-vdso.so.1
>     866454:
>     866454:     object=/mnt/projects/glibc/build/aarch64-linux-gnu-system/elf/ld.so [0]
>     866454:      no scope

That looks … wrong.  No scope?  This object should contain at least its
own scope.  Anyway, this isn't the bug I want to test, so I've added
--as-needed to the link.  Hopefully that will make CI pass.

I wonder if this variant of ld.so is compatible with Cristian
Rodríguez's example binary?

Thanks,
Florian



More information about the Libc-alpha mailing list