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

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Tue Nov 12 17:26:10 GMT 2024



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:

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
    866454:
    866454:
    866454:     relocation processing: elf/tst-nolink-libc
    866454:
    866454:     relocation processing: /mnt/projects/glibc/build/aarch64-linux-gnu-system/elf/ld.so
    866454:     symbol=__stack_chk_guard;  lookup in file=elf/tst-nolink-libc [0]
    866454:     /mnt/projects/glibc/build/aarch64-linux-gnu-system/elf/ld.so: error: symbol lookup error: undefined symbol: __stack_chk_guard, version GLIBC_2.17 (fatal)
elf/tst-nolink-libc: symbol lookup error: /mnt/projects/glibc/build/aarch64-linux-gnu-system/elf/ld.so: undefined symbol: __stack_chk_guard, version GLIBC_2.17

The problem is there is no $buildir/elf on the scope for elf/tst-nolink-libc, and 
this is because the Ubuntu system compiler defaults to -as-needed.  You need
to link ld.so with -Wl,-as-needed:

$(objpfx)tst-nolink-libc: $(objpfx)tst-nolink-libc.o $(objpfx)ld.so
        $(LINK.o) -nostdlib -nostartfiles -o $@ $< \
          -Wl,-E,--dynamic-link=$(objpfx)ld.so -Wl,--no-as-needed $(objpfx)ld.so


More information about the Libc-alpha mailing list