Reland "[lld-macho] Show source information for undefined references"
The error used to look like this:
ld64.lld: error: undefined symbol: _foo
>>> referenced by /path/to/bar.o:(symbol _baz+0x4)
If DWARF line information is available, we now show where in the source
the references are coming from:
ld64.lld: error: unreferenced symbol: _foo
>>> referenced by: bar.cpp:42 (/path/to/bar.cpp:42)
>>> /path/to/bar.o:(symbol _baz+0x4)
The reland is identical to the first time this landed. The fix was in D128294.
This reverts commit 0cc7ad417585b3185c32e395cc5e6cf082a347af.
Differential Revision: https://reviews.llvm.org/D128184
diff --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp
index c142cc1..357503a 100644
--- a/lld/MachO/Dwarf.cpp
+++ b/lld/MachO/Dwarf.cpp
@@ -20,15 +20,16 @@
std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
auto dObj = std::make_unique<DwarfObject>();
bool hasDwarfInfo = false;
- // LLD only needs to extract the source file path from the debug info, so we
- // initialize DwarfObject with just the sections necessary to get that path.
- // The debugger will locate the debug info via the object file paths that we
- // emit in our STABS symbols, so we don't need to process & emit them
- // ourselves.
+ // LLD only needs to extract the source file path and line numbers from the
+ // debug info, so we initialize DwarfObject with just the sections necessary
+ // to get that path. The debugger will locate the debug info via the object
+ // file paths that we emit in our STABS symbols, so we don't need to process &
+ // emit them ourselves.
for (const InputSection *isec : obj->debugSections) {
if (StringRef *s =
StringSwitch<StringRef *>(isec->getName())
.Case(section_names::debugInfo, &dObj->infoSection.Data)
+ .Case(section_names::debugLine, &dObj->lineSection.Data)
.Case(section_names::debugAbbrev, &dObj->abbrevSection)
.Case(section_names::debugStr, &dObj->strSection)
.Default(nullptr)) {