<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt">+enderby<br><br><div class="gmail_quote">On Tue, Nov 13, 2012 at 5:49 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rafael,<br>
<br>
According to DWARF standard, header of each entry set in .debug_aranges<br>
section contains an offset into .debug_info section for the corresponging compile<br>
unit. Typically this should be a relocation into .debug_info section, not<br>
hard-coded zero. Otherwise the binary compiled from multiple assembler sources<br>
will have inconsistent debug_aranges and debug_info.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D115" target="_blank">http://llvm-reviews.chandlerc.com/D115</a><br>
<br>
Files:<br>
  test/MC/ELF/gen-dwarf.s<br>
  lib/MC/MCDwarf.cpp<br>
<br>
Index: test/MC/ELF/gen-dwarf.s<br>
===================================================================<br>
--- test/MC/ELF/gen-dwarf.s<br>
+++ test/MC/ELF/gen-dwarf.s<br>
@@ -1,8 +1,9 @@<br>
 // RUN: llvm-mc -g -triple  i686-pc-linux-gnu %s -filetype=obj -o - | elf-dump | FileCheck %s<br>
<br>
<br>
-// Test that on ELF the debug info has a relocation to debug_abbrev and one to<br>
-// to debug_line.<br>
+// Test that on ELF:<br>
+// 1. the debug info has a relocation to debug_abbrev and one to to debug_line.<br>
+// 2. the debug_aranges has relocations to text and debug_line.<br>
<br>
<br>
     .text<br>
@@ -47,6 +48,34 @@<br>
 // CHECK:       # Section 8<br>
 // CHECK-NEXT:  (('sh_name', 0x00000001) # '.debug_abbrev'<br>
<br>
+// Section 9 is .debug_aranges<br>
+// CHECK:       # Section 9<br>
+// CHECK-NEXT:  (('sh_name', 0x0000001e) # '.debug_aranges'<br>
+<br>
+// Two relocations in .debug_aranges, one to text and one to debug_info.<br>
+// CHECK:       # '.rel.debug_aranges'<br>
+// CHECK:       # Relocation 0<br>
+// CHECK-NEXT:  (('r_offset', 0x00000006)<br>
+// CHECK-NEXT:   ('r_sym', 0x000005)<br>
+// CHECK-NEXT:   ('r_type', 0x01)<br>
+// CHECK-NEXT:  ),<br>
+// CHECK-NEXT:  # Relocation 1<br>
+// CHECK-NEXT: (('r_offset', 0x00000010)<br>
+// CHECK-NEXT:  ('r_sym', 0x000001)<br>
+// CHECK-NEXT:  ('r_type', 0x01)<br>
+// CHECK-NEXT: ),<br>
+<br>
+// Symbol 1 is section 1 (.text)<br>
+// CHECK:         # Symbol 1<br>
+// CHECK-NEXT:    (('st_name', 0x00000000) # ''<br>
+// CHECK-NEXT:     ('st_value', 0x00000000)<br>
+// CHECK-NEXT:     ('st_size', 0x00000000)<br>
+// CHECK-NEXT:     ('st_bind', 0x0)<br>
+// CHECK-NEXT:     ('st_type', 0x3)<br>
+// CHECK-NEXT:     ('st_other', 0x00)<br>
+// CHECK-NEXT:     ('st_shndx', 0x0001)<br>
+// CHECK-NEXT:    ),<br>
+<br>
 // Symbol 4 is section 4 (.debug_line)<br>
 // CHECK:         # Symbol 4<br>
 // CHECK-NEXT:    (('st_name', 0x00000000) # ''<br>
@@ -58,6 +87,17 @@<br>
 // CHECK-NEXT:     ('st_shndx', 0x0004)<br>
 // CHECK-NEXT:    ),<br>
<br>
+// Symbol 5 is section 6 (.debug_info)<br>
+// CHECK:         # Symbol 5<br>
+// CHECK-NEXT:    (('st_name', 0x00000000) # ''<br>
+// CHECK-NEXT:     ('st_value', 0x00000000)<br>
+// CHECK-NEXT:     ('st_size', 0x00000000)<br>
+// CHECK-NEXT:     ('st_bind', 0x0)<br>
+// CHECK-NEXT:     ('st_type', 0x3)<br>
+// CHECK-NEXT:     ('st_other', 0x00)<br>
+// CHECK-NEXT:     ('st_shndx', 0x0006)<br>
+// CHECK-NEXT:    ),<br>
+<br>
 // Symbol 6 is section 8 (.debug_abbrev)<br>
 // CHECK:         # Symbol 6<br>
 // CHECK-NEXT:    (('st_name', 0x00000000) # ''<br>
Index: lib/MC/MCDwarf.cpp<br>
===================================================================<br>
--- lib/MC/MCDwarf.cpp<br>
+++ lib/MC/MCDwarf.cpp<br>
@@ -484,7 +484,8 @@<br>
 // .debug_aranges section.  Which contains a header and a table of pairs of<br>
 // PointerSize'ed values for the address and size of section(s) with line table<br>
 // entries (just the default .text in our case) and a terminating pair of zeros.<br>
-static void EmitGenDwarfAranges(MCStreamer *MCOS) {<br>
+static void EmitGenDwarfAranges(MCStreamer *MCOS,<br>
+                                const MCSymbol *InfoSectionSymbol) {<br>
   MCContext &context = MCOS->getContext();<br>
<br>
   // Create a symbol at the end of the section that we are creating the dwarf<br>
@@ -523,8 +524,11 @@<br>
   // The 2 byte version, which is 2.<br>
   MCOS->EmitIntValue(2, 2);<br>
   // The 4 byte offset to the compile unit in the .debug_info from the start<br>
-  // of the .debug_info, it is at the start of that section so this is zero.<br>
-  MCOS->EmitIntValue(0, 4);<br>
+  // of the .debug_info.<br>
+  if (InfoSectionSymbol)<br>
+    MCOS->EmitSymbolValue(InfoSectionSymbol, 4);<br>
+  else<br>
+    MCOS->EmitIntValue(0, 4);<br>
   // The 1 byte size of an address.<br>
   MCOS->EmitIntValue(AddrSize, 1);<br>
   // The 1 byte size of a segment descriptor, we use a value of zero.<br>
@@ -705,24 +709,30 @@<br>
   // Create the dwarf sections in this order (.debug_line already created).<br>
   MCContext &context = MCOS->getContext();<br>
   const MCAsmInfo &AsmInfo = context.getAsmInfo();<br>
+  bool CreateDwarfSectionSymbols =<br>
+      AsmInfo.doesDwarfUseRelocationsAcrossSections();<br>
+  if (!CreateDwarfSectionSymbols)<br>
+    LineSectionSymbol = NULL;<br>
+  MCSymbol *AbbrevSectionSymbol = NULL;<br>
+  MCSymbol *InfoSectionSymbol = NULL;<br>
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());<br>
+  if (CreateDwarfSectionSymbols) {<br>
+    InfoSectionSymbol = context.CreateTempSymbol();<br>
+    MCOS->EmitLabel(InfoSectionSymbol);<br>
+  }<br>
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());<br>
-  MCSymbol *AbbrevSectionSymbol;<br>
-  if (AsmInfo.doesDwarfUseRelocationsAcrossSections()) {<br>
+  if (CreateDwarfSectionSymbols) {<br>
     AbbrevSectionSymbol = context.CreateTempSymbol();<br>
     MCOS->EmitLabel(AbbrevSectionSymbol);<br>
-  } else {<br>
-    AbbrevSectionSymbol = NULL;<br>
-    LineSectionSymbol = NULL;<br>
   }<br>
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());<br>
<br>
   // If there are no line table entries then do not emit any section contents.<br>
   if (context.getMCLineSections().empty())<br>
     return;<br>
<br>
   // Output the data for .debug_aranges section.<br>
-  EmitGenDwarfAranges(MCOS);<br>
+  EmitGenDwarfAranges(MCOS, InfoSectionSymbol);<br>
<br>
   // Output the data for .debug_abbrev section.<br>
   EmitGenDwarfAbbrev(MCOS);<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>
</div>