[PATCH] Debug Info on Windows

Carlo Kok ck at remobjects.com
Fri Jul 26 00:44:29 PDT 2013


Op 25-7-2013 22:14, David Blaikie schreef:
> On Thu, Jul 25, 2013 at 1:06 PM, Carlo Kok <ck at remobjects.com> wrote:
>> Attached is a possible fix for:
>> Bug 16249 - LLVM generates broken debug info on Windows
>>
>>  From what I can find out the issue is that DIE Labels to strings and other
>> objects should be emitted as a coff "secrel32" symbol, not a .long.
>>
>> After applying this patch gdb and llvm-dwarfdump can properly read the file.
>
> Can you provide test coverage for this?

Attached is a patch that checks the asm output for the proper sections.

I tried creating a testcase that uses dwarfdump but
llvm-dwarfdump doesn't properly support the coff secrel32 relocations 
(prints stderr like:
error: failed to compute relocation: IMAGE_REL_I386_SECREL
error: failed to compute relocation: IMAGE_REL_I386_SECREL
error: failed to compute relocation: IMAGE_REL_I386_SECREL
error: failed to compute relocation: IMAGE_REL_I386_SECREL
error: failed to compute relocation: IMAGE_REL_I386_SECREL

even for gcc generated debug info).
-------------- next part --------------
 lib/CodeGen/AsmPrinter/DwarfDebug.cpp     |  8 +++++++-
 test/DebugInfo/X86/coff_relative_names.ll | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 8dc44b7..c3ec326 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1957,8 +1957,14 @@ void DwarfDebug::emitDIE(DIE *Die, std::vector<DIEAbbrev *> *Abbrevs) {
       break;
     }
     default:
+      const DIEValue* value = Values[i];
+
+      if (value->getType() == DIEValue::isLabel && Asm->MAI->needsDwarfSectionOffsetDirective()) {
+        Asm->OutStreamer.EmitCOFFSecRel32(((DIELabel*)value)->getValue());
+        break;
+      }
       // Emit an attribute using the defined form.
-      Values[i]->EmitValue(Asm, Form);
+      value->EmitValue(Asm, Form);
       break;
     }
   }
diff --git a/test/DebugInfo/X86/coff_relative_names.ll b/test/DebugInfo/X86/coff_relative_names.ll
new file mode 100644
index 0000000..6351f0f
--- /dev/null
+++ b/test/DebugInfo/X86/coff_relative_names.ll
@@ -0,0 +1,20 @@
+; RUN: llc -mtriple=i686-w64-mingw32 -filetype=asm -O0 < %s | FileCheck %s
+
+; CHECK:  	.secrel32 Linfo_string0
+; CHECK:  	.secrel32 Linfo_string1
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"
+target triple = "i686-w64-mingw32"
+
+define i32 @main() {
+entry:
+  %retval = alloca i32, align 4
+  store i32 0, i32* %retval
+  ret i32 0
+}
+
+!llvm.dbg.cu = !{!0}
+
+!0 = metadata !{i32 786449, metadata !1, i32 12, metadata !"clang version 3.4 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !2, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [C:\Projects/test.c] [DW_LANG_C99]
+!1 = metadata !{metadata !"test.c", metadata !"C:\5CProjects"}
+!2 = metadata !{i32 0}


More information about the llvm-commits mailing list