[llvm-commits] [PATCH] Emit DWARF relocation from .debug_aranges to .debug_info for asm files.

Kevin Enderby enderby at apple.com
Tue Nov 13 10:29:50 PST 2012


Adding Greg Clayton our lldb and dwarf expert. While I implemented producing dwarf for assembly source in llvm-mc what I know about dwarf I learned from Greg.

But your change looks fine to me.

Kev

On Nov 13, 2012, at 5:52 AM, Alexey Samsonov wrote:

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121113/cefba917/attachment.html>


More information about the llvm-commits mailing list