The undefined symbol message suggests the source line when line number information is available (see https://reviews.llvm.org/D31481). When the undefined symbol is from a global variable, we won't get the line information. ``` extern int undef; namespace ns { int *var[] = { &undef }; // DW_TAG_variable(DW_AT_decl_file/DW_AT_decl_line) is available while // line number information is unavailable. } ld.lld: error: undefined symbol: undef >>> referenced by undef-debug2.cc >>> undef-debug2.o:(ns::var) ``` This patch utilizes `getEnclosingSymbol` to locate `var` and find DW_TAG_variable for `var`: ``` ld.lld: error: undefined symbol: undef >>> referenced by undef-debug2.cc:3 (/tmp/c/undef-debug2.cc:3) >>> undef-debug2.o:(ns::var) ```
91 KiB
91 KiB