Open petrhosek opened 11 months ago
@llvm/issue-subscribers-lld-elf
Author: Petr Hosek (petrhosek)
I think it is likely a bug in your environment. 1981b1b6b92f7579a30c9ed32dbdf3bc749c1b40 was to improve /DISCARD/
, and unexpectedly but correctly improved --no-allow-shlib-undefined
error checking.
You can see 3343d000a3511a4ea6fbd73bad86a3bbef8117e4 for some test cases.
In linkers' model, as a relocatable object file defines _Znam
, other definitions from shared objects are ignored (e.g. libclang_rt.asan.so
). libfdio.so
has an empty DT_NEEDED list. lld thinks that the _Znam
reference from libfdio.so
will be resolved by the executable. However, the executable's definition is hidden, unable to satisfy a DSO's reference at run-time, therefore a --no-allow-shlib-undefined
error is issued.
% fld.lld @response.txt -y _Znam
usr/local/google/home/phosek/fuchsia/out/core.x64-asan/x64-asan-ubsan-shared/link_stub/libfdio.so: reference to _Znam
usr/local/google/home/phosek/fuchsia/clang/lib/clang/18/lib/x86_64-unknown-fuchsia/libclang_rt.asan.so: shared definition of _Znam
usr/local/google/home/phosek/fuchsia/clang/lib/x86_64-unknown-fuchsia/libc++.a(stdlib_new_delete.cpp.obj): definition of _Znam
usr/local/google/home/phosek/fuchsia/clang/lib/x86_64-unknown-fuchsia/libc++.a(ios.instantiations.cpp.obj): reference to _Znam
usr/local/google/home/phosek/fuchsia/out/core.x64-asan/x64-asan-ubsan/obj/sdk/lib/syslog/cpp/backend_fuchsia_lib.logging_backend_fuchsia.cc.o: reference to _Znam
usr/local/google/home/phosek/fuchsia/clang/lib/x86_64-unknown-fuchsia/libc++.a(stdlib_new_delete.cpp.obj): reference to _Znam
ld.lld: error: undefined reference due to --no-allow-shlib-undefined: operator new[](unsigned long)
>>> referenced by usr/local/google/home/phosek/fuchsia/out/core.x64-asan/x64-asan-ubsan-shared/link_stub/libfdio.so
% readelf -Ws stdlib_new_delete.cpp.obj | grep -w _Znam
7: 0000000000000000 0 SECTION LOCAL DEFAULT 11 .text._Znam
53: 0000000000000000 5 FUNC WEAK HIDDEN 11 _Znam
The error will go away if libfdio.so
does not reference _Znam
.
libfdio
doesn't have an empty DT_NEEDED
list:
$ llvm-readelf -d usr/local/google/home/phosek/fuchsia/out/core.x64-asan/x64-asan-ubsan-shared/link_stub/libfdio.so
Dynamic section at offset 0x2fb0 contains 8 entries:
Tag Type Name/Value
0x0000000000000006 (SYMTAB) 0x40
0x0000000000000005 (STRTAB) 0x1de0
0x000000000000000a (STRSZ) 7584 (bytes)
0x0000000000000001 (NEEDED) Shared library: [libzircon.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x0000000000000001 (NEEDED) Shared library: [libclang_rt.asan.so]
0x000000000000000e (SONAME) Library soname: [libfdio.so]
0x0000000000000000 (NULL) 0x0
The reference to _Znam
is expected and should be satisfied by libclang_rt.asan.so
at runtime.
libfdio
doesn't have an emptyDT_NEEDED
list:$ llvm-readelf -d usr/local/google/home/phosek/fuchsia/out/core.x64-asan/x64-asan-ubsan-shared/link_stub/libfdio.so Dynamic section at offset 0x2fb0 contains 8 entries: Tag Type Name/Value 0x0000000000000006 (SYMTAB) 0x40 0x0000000000000005 (STRTAB) 0x1de0 0x000000000000000a (STRSZ) 7584 (bytes) 0x0000000000000001 (NEEDED) Shared library: [libzircon.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so] 0x0000000000000001 (NEEDED) Shared library: [libclang_rt.asan.so] 0x000000000000000e (SONAME) Library soname: [libfdio.so] 0x0000000000000000 (NULL) 0x0
Sorry for my typo. All of libfdio.so
's DT_NEEDED
entries are seen as input files, so --no-allow-shlib-undefined
kicks in, just like if the DT_NEEDED list were empty.
The reference to
_Znam
is expected and should be satisfied bylibclang_rt.asan.so
at runtime.
Yes that the reference will be satisfied. With glibc, there will not be a runtime error symbol lookup error: ... undefined symbol:
.
However, the detected problem is legitimate and the reference to _Znam
may not be expected. As I commented,
In linkers' model, as a relocatable object file defines _Znam, other definitions from shared objects are ignored (e.g. libclang_rt.asan.so)
The reference to _Znam
is due to "shared object overriding archive".
We're seeing the following link error in the ASan build after #69295:
I have uploaded the reproducer to https://storage.googleapis.com/fuchsia-build/undef-new-reference.tar.xz.