Debug info: On ARM ensure that the data sections come before the
authorAdrian Prantl <aprantl@apple.com>
Mon, 23 Dec 2013 22:24:47 +0000 (22:24 +0000)
committerAdrian Prantl <aprantl@apple.com>
Mon, 23 Dec 2013 22:24:47 +0000 (22:24 +0000)
(optional) DWARF sections, so compiling with -g does not result in
different code being generated.

rdar://problem/15623193

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

lib/Target/ARM/ARMAsmPrinter.cpp
test/DebugInfo/ARM/sectionorder.ll [new file with mode: 0644]

index 0c65ea891d17474fe28b6c03f9dddbd590dead5a..0d724b0610e9190c33125023a23fb09651a48fad 100644 (file)
@@ -488,6 +488,19 @@ void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
                                    SectionKind::getText());
       OutStreamer.SwitchSection(StaticInitSect);
     }
                                    SectionKind::getText());
       OutStreamer.SwitchSection(StaticInitSect);
     }
+
+    // Compiling with debug info should not affect the code
+    // generation!  Since some of the data sections are first switched
+    // to only in ASMPrinter::doFinalization(), the debug info
+    // sections would come before the data sections in the object
+    // file.  This is problematic, since PC-relative loads have to use
+    // different instruction sequences in order to reach global data
+    // in the same object file.
+    OutStreamer.SwitchSection(getObjFileLowering().getCStringSection());
+    OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
+    OutStreamer.SwitchSection(getObjFileLowering().getDataCommonSection());
+    OutStreamer.SwitchSection(getObjFileLowering().getDataBSSSection());
+    OutStreamer.SwitchSection(getObjFileLowering().getNonLazySymbolPointerSection());
   }
 
   // Use unified assembler syntax.
   }
 
   // Use unified assembler syntax.
diff --git a/test/DebugInfo/ARM/sectionorder.ll b/test/DebugInfo/ARM/sectionorder.ll
new file mode 100644 (file)
index 0000000..4e9b226
--- /dev/null
@@ -0,0 +1,26 @@
+; RUN: llc  -filetype=asm %s -o - | FileCheck %s
+
+; Verifies that the DWARF* sections come _after_ the data sections.
+; rdar://problem/15623193
+
+; CHECK: .section      __TEXT,__text,
+; CHECK-NOT: __DWARF,__debug
+; CHECK: .section      __TEXT,__cstring,cstring_literals
+; CHECK-NOT: __DWARF,__debug
+; CHECK: .section      __DATA,__data
+; CHECK-NOT: __DWARF,__debug
+; CHECK: .section      __DATA,__common
+; CHECK-NOT: __DWARF,__debug
+; CHECK: .section      __DATA,__bss
+; CHECK-NOT: __DWARF,__debug
+; CHECK: .section      __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
+target triple = "thumbv7-apple-ios"
+
+!llvm.module.flags = !{!3, !4}
+!llvm.dbg.cu = !{!0}
+
+!0 = metadata !{i32 786449, i32 0, i32 12, metadata !"test.c", metadata !"/Volumes/Data/radar/15623193", metadata !"LLVM", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !1, metadata !1} ; [ DW_TAG_compile_unit ] [/Volumes/Data/radar/15623193/test.c] [DW_LANG_C99]
+!1 = metadata !{metadata !2}
+!2 = metadata !{i32 0}
+!3 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
+!4 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}