MC: correct DWARF header for PE/COFF assembly input
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 17 Jul 2014 16:27:44 +0000 (16:27 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 17 Jul 2014 16:27:44 +0000 (16:27 +0000)
The header contains an offset to the DWARF abbreviations for the CU.  The offset
must be section relative for COFF and absolute for others.  The non-assembly
code path for the DWARF header generation already had the correct emission for
the headers.  This corrects just the assembly path.  Due to the invalid
relocation, processing of the debug information would halt previously on the
first assembly input as the associated abbreviations would be out of range as
they would have the location increased by image base and the section offset.

This address PR20332.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213275 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCDwarf.cpp
test/DebugInfo/X86/dbg-asm.s [new file with mode: 0644]

index b14a452d85d8e59b74e01a654ecd97e3f828f2f8..ae27686819869a0ab95f46a5ca9492339d8ff740 100644 (file)
@@ -657,11 +657,12 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
 
   // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
   // it is at the start of that section so this is zero.
-  if (AbbrevSectionSymbol) {
-    MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4);
-  } else {
+  if (AbbrevSectionSymbol == nullptr)
     MCOS->EmitIntValue(0, 4);
-  }
+  else if (context.getAsmInfo()->needsDwarfSectionOffsetDirective())
+    MCOS->EmitCOFFSecRel32(AbbrevSectionSymbol);
+  else
+    MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4);
 
   const MCAsmInfo *asmInfo = context.getAsmInfo();
   int AddrSize = asmInfo->getPointerSize();
diff --git a/test/DebugInfo/X86/dbg-asm.s b/test/DebugInfo/X86/dbg-asm.s
new file mode 100644 (file)
index 0000000..66a0292
--- /dev/null
@@ -0,0 +1,22 @@
+# RUN: llvm-mc -triple i686-windows-gnu -g %s -filetype obj -o - \
+# RUN:   | llvm-readobj -r - | FileCheck -check-prefix CHECK-COFF %s
+# RUN: llvm-mc -triple i686-windows-itanium -g %s -filetype obj -o - \
+# RUN:   | llvm-readobj -r - | FileCheck -check-prefix CHECK-COFF %s
+# RUN: llvm-mc -triple i686-linux-gnu -g %s -filetype obj -o - \
+# RUN:   | llvm-readobj -r - | FileCheck -check-prefix CHECK-ELF %s
+
+_a:
+       movl $65, %eax
+       ret
+
+# CHECK-COFF: Relocations [
+# CHECK-COFF:   Section {{.*}} .debug_info {
+# CHECK-COFF:     0x6 IMAGE_REL_I386_SECREL .debug_abbrev
+# CHECK-COFF:   }
+# CHECK-COFF: ]
+
+# CHECK-ELF: Relocations [
+# CHECK-ELF:   Section {{.*}} .rel.debug_info {
+# CHECK-ELF:     0x6 R_386_32 .debug_abbrev
+# CHECK-ELF:   }
+# CHECK-ELF: ]