Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DWARF5][COFF] Fix wrong relocation in .debug_line #83773

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llvm/lib/MC/MCDwarf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,12 @@ void MCDwarfLineStr::emitRef(MCStreamer *MCOS, StringRef Path) {
size_t Offset = addString(Path);
if (UseRelocs) {
MCContext &Ctx = MCOS->getContext();
MCOS->emitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset), RefSize);
if (Ctx.getAsmInfo()->needsDwarfSectionOffsetDirective()) {
MCOS->emitCOFFSecRel32(LineStrLabel, Offset);
} else {
MCOS->emitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset),
RefSize);
}
} else
MCOS->emitIntValue(Offset, RefSize);
}
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/MC/COFF/dwarf5lineinfo.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-windows-gnu %s -o - | llvm-readobj -r - | FileCheck %s

// CHECK: Relocations [
// CHECK: Section (4) .debug_line {
// CHECK: 0x22 IMAGE_REL_AMD64_SECREL .debug_line_str (8)
// CHECK: 0x2C IMAGE_REL_AMD64_SECREL .debug_line_str (8)
// CHECK: 0x36 IMAGE_REL_AMD64_ADDR64 .text (0)
// CHECK: }

main:
.file 0 "/" "test.c"
.loc 0 1 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear - if I understand correctly, the distinction between DWARF 4 and 5 gets activated by these directives here, with DWARF 4, I see that the first parameter to these directives is 1 instead of 0. Is that right?

Copy link
Contributor Author

@timoh-ba timoh-ba Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you're asking a really good question there. I tested around a bit and you seem to be correct about the difference between dwarf4 & dwarf5 here. I tried to find some llvm documentation about this but couldn't find anything, I'll probably need to look through the assembly parser to find out what each of those fields mean? I got the assembly out of clang, I haven't written it myself.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DWARF 5 defined file number 0 as the main source file. DWARF 4 doesn't have that, file numbers start at 1 and there isn't a distinguished "main" file. LMK if you need more detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, very interesting

retq
Loading