mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 09:16:08 +00:00

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) ```
34 lines
1.0 KiB
ArmAsm
34 lines
1.0 KiB
ArmAsm
## Variables with line number information
|
|
.file 1 "dir/undef-debug.s"
|
|
.loc 1 3
|
|
.quad zed3
|
|
|
|
.section .text.1,"ax"
|
|
.loc 1 7
|
|
.quad zed4
|
|
|
|
.section .text.2,"ax"
|
|
.loc 1 11
|
|
.quad zed5
|
|
|
|
.section .debug_abbrev,"",@progbits
|
|
.byte 1 # Abbreviation Code
|
|
.byte 17 # DW_TAG_compile_unit
|
|
.byte 0 # DW_CHILDREN_no
|
|
.byte 16 # DW_AT_stmt_list
|
|
.byte 23 # DW_FORM_sec_offset
|
|
.byte 0 # EOM(1)
|
|
.byte 0 # EOM(2)
|
|
.byte 0 # EOM(3)
|
|
|
|
.section .debug_info,"",@progbits
|
|
.long .Lend0 - .Lbegin0 # Length of Unit
|
|
.Lbegin0:
|
|
.short 4 # DWARF version number
|
|
.long .debug_abbrev # Offset Into Abbrev. Section
|
|
.byte 8 # Address Size (in bytes)
|
|
.byte 1 # Abbrev [1] 0xb:0x1f DW_TAG_compile_unit
|
|
.long .debug_line # DW_AT_stmt_list
|
|
.Lend0:
|
|
.section .debug_line,"",@progbits
|