| Issue |
176890
|
| Summary |
lld: --why-live=* crashes
|
| Labels |
lld:ELF,
crash-on-valid
|
| Assignees |
|
| Reporter |
bevin-hansson
|
If you try using the `--why-live` option with a wildcard argument, something seems to go wrong. See the [linked Godbolt](https://godbolt.org/z/neYEc3bWv).
```
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: /cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /app/output.s /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.1/crtbeginS.o -L./lib -L/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/../lib/x86_64-unknown-linux-gnu -L/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/lib/clang/23/lib/x86_64-unknown-linux-gnu -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.1 -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.1/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib64 -L/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.1/../../../../x86_64-linux-gnu/lib -L/lib -L/usr/lib --gc-sections --why-live=* /tmp/example-966c45.o -rpath ./lib -rpath /opt/compiler-explorer/gcc-snapshot/lib64 -rpath /opt/compiler-explorer/gcc-snapshot/lib32 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.1/crtendS.o /lib/x86_64-linux-gnu/crtn.o
#0 0x0000000000a77618 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xa77618)
#1 0x0000000000a745b4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x000079500ee42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x000079500ee969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x000079500ee42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x000079500ee287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000000000c764c4 (anonymous namespace)::MarkLive<llvm::object::ELFType<(llvm::endianness)1, true>, true>::printWhyLive(lld::elf::Symbol*) const MarkLive.cpp:0:0
#7 0x0000000000c84c77 void lld::elf::markLive<llvm::object::ELFType<(llvm::endianness)1, true>>(lld::elf::Ctx&) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xc84c77)
#8 0x0000000000bdc324 void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xbdc324)
#9 0x0000000000beb4d2 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xbeb4d2)
#10 0x0000000000bebe6c lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xbebe6c)
#11 0x0000000000ab0009 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0xab0009)
#12 0x00000000009e90e9 lld_main(int, char**, llvm::ToolContext const&) (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0x9e90e9)
#13 0x00000000008b8984 main (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0x8b8984)
#14 0x000079500ee29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#15 0x000079500ee29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#16 0x00000000009e8a25 _start (/cefs/29/29ba929dd1acfd4678d88c97_clang-trunk-20260120/bin/ld.lld+0x9e8a25)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)
```
The issue seems to be here, in printWhyLive:
```
// This item is live, but it has no tracked reason. It must be an
// unreferenced symbol in a live section or a symbol with no section.
InputSectionBase *sec = nullptr;
if (auto *d = dyn_cast<Defined>(std::get<Symbol *>(cur)))
sec = dyn_cast_or_null<InputSectionBase>(d->section);
reason = sec ? LiveReason{sec, "in live section"}
: LiveReason{std::nullopt, "no section"};
```
`cur` here is not a `Symbol*`, but rather an `InputSectionBase*` (at least in my local reproduction).
I'm not sure if it's enough to guard against this here, or if the root cause is elsewhere.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs