| Issue |
203761
|
| Summary |
LLD crash in Temporal PGO scenario with a wrong path to a non-existent IRPGO profile
|
| Labels |
lld
|
| Assignees |
|
| Reporter |
zamazan4ik
|
Hi!
During my local experiments with Temporal PGO (Clang `-ftemporal-profile` [switch](https://clang.llvm.org/docs/UsersManual.html#cmdoption-ftemporal-profile)), I mistakenly passed a non-existent PGO profile to the following command-line:
```
clang++ -O2 -fuse-ld=lld -Wl,--irpgo-profile="" main.cpp
```
`ld.lld --version` is `LLD 22.1.6 (compatible with GNU linkers)` (from Fedora 44 repos).
As a result, LLD segfaults:
```
0. Program arguments: /usr/bin/ld.lld --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtbegin.o -L/usr/bin/../lib/clang/22/lib/x86_64-redhat-linux-gnu -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/lib -L/usr/lib --irpgo-profile="" --bp-startup-sort=function /tmp/main-0fc52c.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crtn.o
#0 0x00007f85dcc421a9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM.so.22.1+0x56421a9)
#1 0x00007f85dcc42b7d (/lib64/libLLVM.so.22.1+0x5642b7d)
#2 0x00007f85d70210b0 __restore_rt (/lib64/libc.so.6+0x1a0b0)
#3 0x00007f85d707bdcc __pthread_kill_implementation (/lib64/libc.so.6+0x74dcc)
#4 0x00007f85d7020f8e gsignal (/lib64/libc.so.6+0x19f8e)
#5 0x00007f85d70087b3 abort (/lib64/libc.so.6+0x17b3)
#6 0x00007f85d720b64a (/lib64/libstdc++.so.6+0xb64a)
#7 0x00007f85e04ee701 lld::elf::runBalancedPartitioning(lld::elf::Ctx&, llvm::StringRef, bool, bool, bool, bool) (/lib64/liblldELF.so.22.1+0xee701)
#8 0x00007f85e06bbf22 (/lib64/liblldELF.so.22.1+0x2bbf22)
#9 0x00007f85e06d3779 (/lib64/liblldELF.so.22.1+0x2d3779)
#10 0x00007f85e06ac91e void lld::elf::writeResult<llvm::object::ELFType<(llvm::endianness)1, true>>(lld::elf::Ctx&) (/lib64/liblldELF.so.22.1+0x2ac91e)
#11 0x00007f85e0520ef9 (/lib64/liblldELF.so.22.1+0x120ef9)
#12 0x00007f85e0504514 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/lib64/liblldELF.so.22.1+0x104514)
#13 0x00007f85e0501079 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/lib64/liblldELF.so.22.1+0x101079)
#14 0x00007f85e01a5826 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/lib64/liblldCommon.so.22.1+0x12826)
#15 0x000055aa7359549b lld_main(int, char**, llvm::ToolContext const&) (/usr/bin/ld.lld+0x349b)
#16 0x000055aa73595357 main (/usr/bin/ld.lld+0x3357)
#17 0x00007f85d700a681 __libc_start_call_main (/lib64/libc.so.6+0x3681)
#18 0x00007f85d700a798 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3798)
#19 0x000055aa73595645 _start (/usr/bin/ld.lld+0x3645)
```
I've also built a fresh LLD locally from LLVM repo on the `cf004c900376a60386d8cc7c643ea07cd61217e9` commit (from June 13, 2026) - the issue is the same - LLD crashes. LLD version is `LLD 23.0.0 (https://github.com/llvm/llvm-project.git cf004c900376a60386d8cc7c643ea07cd61217e9) (compatible with GNU linkers)`.
`clang++ -O2 -fuse-ld=lld --ld-path=/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld -Wl,--irpgo-profile="" main.cpp`
gives the following error:
```
0. Program arguments: /home/zamazan4ik/open_source/build_lld/install/bin/ld.lld --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtbegin.o -L/usr/bin/../lib/clang/22/lib/x86_64-redhat-linux-gnu -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/lib -L/usr/lib --irpgo-profile="" --bp-startup-sort=function /tmp/main-1122b3.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crtn.o
#0 0x00000000006804f1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x6804f1)
#1 0x000000000067d087 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00007f1a08d0a0b0 __restore_rt (/lib64/libc.so.6+0x1a0b0)
#3 0x0000000000a7b09a llvm::InstrProfIterator<llvm::NamedInstrProfRecord, llvm::InstrProfReader>::increment() (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0xa7b09a)
#4 0x0000000000a85bb1 lld::BPOrderer<(anonymous namespace)::BPOrdererELF>::computeOrder(llvm::StringRef, llvm::ArrayRef<lld::BPCompressionSortSpec>, bool, bool, bool, bool, llvm::ArrayRef<lld::elf::InputSectionBase*>, llvm::DenseMap<llvm::CachedHashStringRef, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int>>, llvm::DenseMapInfo<llvm::CachedHashStringRef, void>, llvm::detail::DenseMapPair<llvm::CachedHashStringRef, std::set<unsigned int, std::less<unsigned int>, std::allocator<unsigned int>>>> const&) BPSectionOrderer.cpp:0:0
#5 0x0000000000a87251 lld::elf::runBalancedPartitioning(lld::elf::Ctx&, llvm::StringRef, llvm::ArrayRef<lld::BPCompressionSortSpec>, bool, bool, bool, bool) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0xa87251)
#6 0x000000000099366b buildSectionOrder(lld::elf::Ctx&) Writer.cpp:0:0
#7 0x00000000009a4bd3 (anonymous namespace)::Writer<llvm::object::ELFType<(llvm::endianness)1, true>>::sortSections() Writer.cpp:0:0
#8 0x00000000009b8462 (anonymous namespace)::Writer<llvm::object::ELFType<(llvm::endianness)1, true>>::finalizeSections() Writer.cpp:0:0
#9 0x00000000009bb585 void lld::elf::writeResult<llvm::object::ELFType<(llvm::endianness)1, true>>(lld::elf::Ctx&) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x9bb585)
#10 0x0000000000819c71 void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x819c71)
#11 0x0000000000822e7e lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x822e7e)
#12 0x0000000000823380 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x823380)
#13 0x00000000006c119c lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x6c119c)
#14 0x00000000005e6191 lld_main(int, char**, llvm::ToolContext const&) (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x5e6191)
#15 0x0000000000471a71 main (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x471a71)
#16 0x00007f1a08cf3681 __libc_start_call_main (/lib64/libc.so.6+0x3681)
#17 0x00007f1a08cf3798 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3798)
#18 0x00000000005e5b75 _start (/home/zamazan4ik/open_source/build_lld/install/bin/ld.lld+0x5e5b75)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: linker command failed due to signal (use -v to see invocation)
zamazan4ik@fedora ~/o/test_rustc_temporal_pgo [1]> clang++ -O2 -fuse-ld=lld -Wl,--irpgo-profile="" main.cpp
ld.lld: error: No such file or directory
/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/unique_ptr.h:474: typename add_lvalue_reference<element_type>::type std::unique_ptr<llvm::InstrProfReader>::operator*() const [_Tp = llvm::InstrProfReader, _Dp = std::default_delete<llvm::InstrProfReader>]: Assertion 'get() != pointer()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /usr/bin/ld.lld --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtbegin.o -L/usr/bin/../lib/clang/22/lib/x86_64-redhat-linux-gnu -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/lib -L/usr/lib --irpgo-profile="" --bp-startup-sort=function /tmp/main-0fc52c.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-redhat-linux/16/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../lib64/crtn.o
#0 0x00007f85dcc421a9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM.so.22.1+0x56421a9)
#1 0x00007f85dcc42b7d (/lib64/libLLVM.so.22.1+0x5642b7d)
#2 0x00007f85d70210b0 __restore_rt (/lib64/libc.so.6+0x1a0b0)
#3 0x00007f85d707bdcc __pthread_kill_implementation (/lib64/libc.so.6+0x74dcc)
#4 0x00007f85d7020f8e gsignal (/lib64/libc.so.6+0x19f8e)
#5 0x00007f85d70087b3 abort (/lib64/libc.so.6+0x17b3)
#6 0x00007f85d720b64a (/lib64/libstdc++.so.6+0xb64a)
#7 0x00007f85e04ee701 lld::elf::runBalancedPartitioning(lld::elf::Ctx&, llvm::StringRef, bool, bool, bool, bool) (/lib64/liblldELF.so.22.1+0xee701)
#8 0x00007f85e06bbf22 (/lib64/liblldELF.so.22.1+0x2bbf22)
#9 0x00007f85e06d3779 (/lib64/liblldELF.so.22.1+0x2d3779)
#10 0x00007f85e06ac91e void lld::elf::writeResult<llvm::object::ELFType<(llvm::endianness)1, true>>(lld::elf::Ctx&) (/lib64/liblldELF.so.22.1+0x2ac91e)
#11 0x00007f85e0520ef9 (/lib64/liblldELF.so.22.1+0x120ef9)
#12 0x00007f85e0504514 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/lib64/liblldELF.so.22.1+0x104514)
#13 0x00007f85e0501079 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/lib64/liblldELF.so.22.1+0x101079)
#14 0x00007f85e01a5826 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/lib64/liblldCommon.so.22.1+0x12826)
#15 0x000055aa7359549b lld_main(int, char**, llvm::ToolContext const&) (/usr/bin/ld.lld+0x349b)
#16 0x000055aa73595357 main (/usr/bin/ld.lld+0x3357)
#17 0x00007f85d700a681 __libc_start_call_main (/lib64/libc.so.6+0x3681)
#18 0x00007f85d700a798 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3798)
#19 0x000055aa73595645 _start (/usr/bin/ld.lld+0x3645)
```
The issue is reproduced if the linker is used from other compilers as well - originally I've found the issue during my tries of adoption Temporal PGO into Rustc.
Thank you.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs