ziyao233 wrote: > (Sorry for the late reply. I have many notifications.) > > Can you print the relevant command line arguments before and after this > patch? I think the current `-lc` is added in the normal no-as-needed mode: > `... --no-as-needed -lc `
No, it isn't. Without the patch, ```shell ../build/bin/clang test.c -o libtest.so -fPIC -shared -v -Wl,--as-needed -Wl,--trace-symbol=__cxa_finalize clang version 19.0.0git (https://github.com/llvm/llvm-project.git 3ae10fde39419d7c985b9fff210ed44b699e438c) Target: x86_64-ewe-linux-musl Thread model: posix InstalledDir: /root/Source/llvm-project/build/bin "/root/Source/llvm-project/build/bin/clang-19" -cc1 -triple x86_64-ewe-linux-musl -emit-obj -mrelax-all -dumpdir libtest.so- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/Source/llvm-project/bug -v -fcoverage-compilation-dir=/root/Source/llvm-project/bug -resource-dir /root/Source/llvm-project/build/lib/clang/19 -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /root/Source/llvm-project/build/lib/clang/19/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-24f226.o -x c test.c clang -cc1 version 19.0.0git based upon LLVM 19.0.0git default target x86_64-ewe-linux-musl ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/include /root/Source/llvm-project/build/lib/clang/19/include End of search list. "/usr/sbin/ld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -shared -o libtest.so /lib/../lib64/crti.o /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o -L/root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-24f226.o --as-needed --trace-symbol=__cxa_finalize /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a -lc /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtend.o /lib/../lib64/crtn.o trace-symbol: /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o: weak reference to __cxa_finalize trace-symbol: /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o: unresolved weak symbol __cxa_finalize ``` With the patch, ```shell ../build/bin/clang test.c -o libtest.so -fPIC -shared -v -Wl,--as-needed -Wl,--trace-symbol=__cxa_finalize clang version 19.0.0git (https://github.com/llvm/llvm-project.git 515e09198c6d9da95df3357552cb7b41b03b6e8c) Target: x86_64-ewe-linux-musl Thread model: posix InstalledDir: /root/Source/llvm-project/build/bin "/root/Source/llvm-project/build/bin/clang-19" -cc1 -triple x86_64-ewe-linux-musl -emit-obj -mrelax-all -dumpdir libtest.so- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/Source/llvm-project/bug -v -fcoverage-compilation-dir=/root/Source/llvm-project/bug -resource-dir /root/Source/llvm-project/build/lib/clang/19 -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /root/Source/llvm-project/build/lib/clang/19/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-350534.o -x c test.c clang -cc1 version 19.0.0git based upon LLVM 19.0.0git default target x86_64-ewe-linux-musl ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/include /root/Source/llvm-project/build/lib/clang/19/include End of search list. "/usr/sbin/ld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -shared -o libtest.so /lib/../lib64/crti.o /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o -L/root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-350534.o --as-needed --trace-symbol=__cxa_finalize /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a --push-state --no-as-needed -lc --pop-state /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtend.o /lib/../lib64/crtn.o trace-symbol: /lib64/libc.so: definition of __cxa_finalize trace-symbol: /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o: weak reference to __cxa_finalize ``` LLVM is configured like ```shell $ cmake -S llvm -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS='-D_LARGEFILE64_SOURCE' \ -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-ewe-linux-musl" \ -DCLANG_DEFAULT_CXX_STDLIB='libc++' \ -DCLANG_DEFAULT_RTLIB='compiler-rt' \ -DLLVM_ENABLE_LLD=ON \ -DLLVM_TARGETS_TO_BUILD="X86" \ -DLLVM_ENABLE_PROJECTS="clang" ``` in a musl and llvm only environment. Another linker `mold` is used here instead of `lld` to make the problem more clear, since `lld` seems to always create an internal reference to `__cxa_finalize`, though I didn't find why. ```shell # with -fuse-ld=lld "/usr/sbin/ld.lld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -shared -o libtest.so /lib/../lib64/crti.o /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o -L/root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-076bce.o --as-needed --trace-symbol=__cxa_finalize /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a -lc /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/libclang_rt.builtins.a /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtend.o /lib/../lib64/crtn.o /root/Source/llvm-project/build/lib/clang/19/lib/x86_64-ewe-linux-musl/clang_rt.crtbegin.o: reference to __cxa_finalize /lib/../lib64/libc.so: shared definition of __cxa_finalize <internal>: reference to __cxa_finalize ``` Thanks again for your review. https://github.com/llvm/llvm-project/pull/95848 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits