Skip to content

Commit

Permalink
[ObjectYAML][ELF] Let the endianness of DWARF sections be inferred fr…
Browse files Browse the repository at this point in the history
…om FileHeader.

This patch helps infer the endianness of DWARF sections from `FileHeader`.

Reviewed By: jhenderson, grimar

Differential Revision: https://reviews.llvm.org/D81051
  • Loading branch information
higuoxing committed Jun 4, 2020
1 parent a50f4eb commit b6020c3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,9 @@ void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
IO.mapOptional("Symbols", Object.Symbols);
IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
IO.mapOptional("DWARF", Object.DWARF);
if (Object.DWARF)
Object.DWARF->IsLittleEndian =
Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
IO.setContext(nullptr);
}

Expand Down
65 changes: 63 additions & 2 deletions llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

## Generate and verify a big endian object file.

# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.o
# RUN: llvm-readobj --sections --section-data %t1.o | \
# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o
# RUN: llvm-readobj --sections --section-data %t.be.o | \
# RUN: FileCheck %s -DADDRALIGN=1 -DSIZE=96 --check-prefixes=DWARF-BE-HEADER,DWARF-BE-CONTENT

# DWARF-BE-HEADER: Index: 1
Expand Down Expand Up @@ -90,6 +90,67 @@ DWARF:
- Address: 0x0000000056780000
Length: 0x10

## Generate and verify a little endian object file.

# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t.le.o
# RUN: llvm-readobj --sections --section-data %t.le.o | \
# RUN: FileCheck %s --check-prefixes=DWARF-LE-DEFAULT

# DWARF-LE-DEFAULT: Section {
# DWARF-LE-DEFAULT: Index: 1
# DWARF-LE-DEFAULT-NEXT: Name: .debug_aranges (1)
# DWARF-LE-DEFAULT-NEXT: Type: SHT_PROGBITS (0x1)
# DWARF-LE-DEFAULT-NEXT: Flags [ (0x0)
# DWARF-LE-DEFAULT-NEXT: ]
# DWARF-LE-DEFAULT-NEXT: Address: 0x0
# DWARF-LE-DEFAULT-NEXT: Offset: 0x40
# DWARF-LE-DEFAULT-NEXT: Size: 96
# DWARF-LE-DEFAULT-NEXT: Link: 0
# DWARF-LE-DEFAULT-NEXT: Info: 0
# DWARF-LE-DEFAULT-NEXT: AddressAlignment: 1
# DWARF-LE-DEFAULT-NEXT: EntrySize: 0
# DWARF-LE-DEFAULT-NEXT: SectionData (
# DWARF-LE-DEFAULT-NEXT: 0000: 2C000000 02000000 00000400 00000000
## | | | | | |
## | | | | | +------- Padding zeros (4-byte)
## | | | | +- SegSize (1-byte) 0x00
## | | | +- AddrSize (1-byte) 0x04
## | | +-------- CuOffset (4-byte) 0x00
## | +--- Version (2-byte) 0x02
## +------- InitialLength (4-byte) 0x2c
##
# DWARF-LE-DEFAULT-NEXT: 0010: 34120000 20000000 00000000 00000000
## | | |
## | | +---------------- Terminating Entry
## | +------- Length (4-byte) 0x20
## +------- Address (4-byte) 0x1234
##
# DWARF-LE-DEFAULT-NEXT: 0020: 2C000000 02006500 00000800 00000000
## | | | | | |
## | | | | | +------- Padding zeros (4-byte)
## | | | | +- SegSize (1-byte) 0x00
## | | | +- AddrSize (1-byte) 0x08
## | | +-------- CuOffset (4-byte) 0x00
## | +--- Version (2-byte) 0x02
## +------- InitialLength (4-byte) 0x2c
##
# DWARF-LE-DEFAULT-NEXT: 0030: 78560000 00000000 20000000 00000000
## | |
## | +---------------- Length (8-byte) 0x20
## +---------------- Address (8-byte) 0x5678
##
# DWARF-LE-DEFAULT-NEXT: 0040: 00007856 00000000 10000000 00000000
## | |
## | +---------------- Length (8-byte) 0x10
## +---------------- Address (8-byte) 0x5678
##
# DWARF-LE-DEFAULT-NEXT: 0050: 00000000 00000000 00000000 00000000
## |
## +---------------------------------- Terminating entry
##
# DWARF-LE-DEFAULT-NEXT: )
# DWARF-LE-DEFAULT-NEXT: }

## b) Generate the .debug_aranges section from raw section content.

# RUN: yaml2obj --docnum=2 %s -o %t2.o
Expand Down

0 comments on commit b6020c3

Please sign in to comment.