Skip to content

Commit 7650a01

Browse files
authored
[DWARF5][COFF] Emit section-relative .debug_line_str relocations (#83773)
Dwarf 5 allows separating filenames from .debug_line into a separate .debug_line_str section. The strings are referenced relative to the start of the .debug_line_str section. Previously, on COFF, the relocation information instead caused offsets to be relocated to the base address of the COFF-File. This lead to wrong offsets in linked COFF (PE) files which caused the debugger to be unable to find the correct source files. This patch fixes this problem by making the offsets relative to the start of the .debug_line_str section instead. There should be no changes for ELF-Files as everything seems to be working there. A test is also added to ensure that the correct relocation entries are emitted.
1 parent 50801f1 commit 7650a01

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/MC/MCDwarf.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ void MCDwarfLineStr::emitRef(MCStreamer *MCOS, StringRef Path) {
360360
size_t Offset = addString(Path);
361361
if (UseRelocs) {
362362
MCContext &Ctx = MCOS->getContext();
363-
MCOS->emitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset), RefSize);
363+
if (Ctx.getAsmInfo()->needsDwarfSectionOffsetDirective()) {
364+
MCOS->emitCOFFSecRel32(LineStrLabel, Offset);
365+
} else {
366+
MCOS->emitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset),
367+
RefSize);
368+
}
364369
} else
365370
MCOS->emitIntValue(Offset, RefSize);
366371
}

llvm/test/MC/COFF/dwarf5lineinfo.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-windows-gnu %s -o - | llvm-readobj -r - | FileCheck %s
2+
3+
// CHECK: Relocations [
4+
// CHECK: Section (4) .debug_line {
5+
// CHECK: 0x22 IMAGE_REL_AMD64_SECREL .debug_line_str (8)
6+
// CHECK: 0x2C IMAGE_REL_AMD64_SECREL .debug_line_str (8)
7+
// CHECK: 0x36 IMAGE_REL_AMD64_ADDR64 .text (0)
8+
// CHECK: }
9+
10+
main:
11+
.file 0 "/" "test.c"
12+
.loc 0 1 0
13+
retq

0 commit comments

Comments
 (0)