[DebugInfo] Fix end_sequence of debug_line in LTO Object
authorKyungwoo Lee <kyulee@fb.com>
Mon, 15 Nov 2021 04:18:36 +0000 (20:18 -0800)
committerKyungwoo Lee <kyulee@fb.com>
Mon, 15 Nov 2021 04:19:47 +0000 (20:19 -0800)
commit6747d44bda8c460c90c2276ac6e2402d434e0780
treeeda99b5316d527599fcc4f3b98f0bc0808942dbe
parentcda72e92971bc8b4e88f89fd01e18ee55376b84f
[DebugInfo] Fix end_sequence of debug_line in LTO Object

In a LTO build, the `end_sequence` in debug_line table for each compile unit (CU) points the end of text section which merged all CUs. The `end_sequence` needs to point to the end of each CU's range. This bug often causes invalid `debug_line` table in the final `.dSYM` binary for MachO after running `dsymutil` which tries to compensate an out-of-range address of `end_sequence`.
The fix is to sync the line table termination with the range operations that are already maintained in DwarfDebug. When CU or section changes, or nodebug functions appear or module is finished, the prior pending line table is terminated using the last range label. In the MC path where no range is tracked, the old logic is conservatively used to end the line table using the section end symbol.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D108261
llvm/include/llvm/MC/MCDwarf.h
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/lib/MC/MCDwarf.cpp
llvm/test/DebugInfo/XCOFF/empty.ll
llvm/test/DebugInfo/XCOFF/explicit-section.ll
llvm/test/DebugInfo/XCOFF/function-sections.ll
llvm/test/DebugInfo/debugline-endsequence.ll [new file with mode: 0644]
llvm/test/DebugInfo/debugline-endsequence.s [new file with mode: 0644]