Issue 134933
Summary [LLD][ELF] Incorrect source location in undefined symbol error
Labels lld
Assignees
Reporter mysterymath
    We've hit a situation where an undefined symbol error in LLD shows an incorrect source location:
```
ld.lld: error: undefined hidden symbol: std::__ktl::__hash_memory(void const*, unsigned long)
>>> referenced by span:561 (../../prebuilt/third_party/clang/linux-x64/bin/../include/c++/v1/span:561)
>>> libboot-shim.devicetree-riscv-cpu-topology-item.cc.o:(boot_shim::RiscvDevicetreeCpuTopologyItemBase::OnDone()) in archive usr/local/google/home/mcgrathr/tq/fuchsia/out/bringup.riscv64-clang/kernel.phys_riscv64/obj/zircon/kernel/phys/lib/boot-shim/libboot-shim.a
>>> referenced by alloc_checker.h:66 (../../zircon/system/ulib/fbl/include/fbl/alloc_checker.h:66)
>>> libboot-shim.devicetree-riscv-cpu-topology-item.cc.o:(boot_shim::RiscvDevicetreeCpuTopologyItemBase::OnDone()) in archive usr/local/google/home/mcgrathr/tq/fuchsia/out/bringup.riscv64-clang/kernel.phys_riscv64/obj/zircon/kernel/phys/lib/boot-shim/libboot-shim.a
```

A disassembly with `llvm-objdump --demangle -dlr` shows the correct location:
```
; ./../../prebuilt/third_party/clang/linux-x64/bin/../include/c++/v1/__string/char_traits.h:537
 390: 8566         	mv	a0, s9
     392: 85d2         	mv	a1, s4
 394: 00000097     	auipc	ra, 0x0
		0000000000000394: R_RISCV_CALL_PLT	std::__ktl::__hash_memory(void const*, unsigned long)
		0000000000000394:  R_RISCV_RELAX	*ABS*
     398: 000080e7 	jalr	ra <.Lpcrel_hi2+0x21e>
```

I noticed that the code in LLD wasn't using the usual `getLineInfoForAddress` in `DWARFContext`, but changing it to do so didn't make any difference. It looks like `llvm-objdump` is using the LLVM symbolizer library instead of directly using the DWARF library; maybe there's some smarts there that are making the difference? I haven't yet tried getting LLD to use the symbolizer library.

Originally found in Fuchsia. See here for the LLD reproducer: https://issuetracker.google.com/407569434
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to