1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[ObjectYAML][DWARF] Let the target address size be inferred from FileHeader.

This patch adds a new field `bool Is64bit` in `DWARFYAML::Data` to indicate the address size of target. It's helpful for inferring the `AddrSize` in some DWARF sections.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D81709
This commit is contained in:
Xing GUO 2020-06-14 12:00:46 +08:00
parent 7106336a4c
commit 6a0fa3e985
7 changed files with 24 additions and 22 deletions

View File

@ -83,7 +83,7 @@ struct RangeEntry {
/// Class that describes a single range list inside the .debug_ranges section.
struct Ranges {
Optional<llvm::yaml::Hex64> Offset;
llvm::yaml::Hex8 AddrSize;
Optional<llvm::yaml::Hex8> AddrSize;
std::vector<RangeEntry> Entries;
};
@ -162,6 +162,7 @@ struct LineTable {
struct Data {
bool IsLittleEndian;
bool Is64bit;
std::vector<Abbrev> AbbrevDecls;
std::vector<StringRef> DebugStrings;
std::vector<ARange> ARanges;

View File

@ -148,13 +148,19 @@ Error DWARFYAML::emitDebugRanges(raw_ostream &OS, const DWARFYAML::Data &DI) {
Twine::utohexstr(CurrOffset) + ")");
if (DebugRanges.Offset)
ZeroFillBytes(OS, *DebugRanges.Offset - CurrOffset);
uint8_t AddrSize;
if (DebugRanges.AddrSize)
AddrSize = *DebugRanges.AddrSize;
else
AddrSize = DI.Is64bit ? 8 : 4;
for (auto Entry : DebugRanges.Entries) {
writeVariableSizedInteger(Entry.LowOffset, DebugRanges.AddrSize, OS,
writeVariableSizedInteger(Entry.LowOffset, AddrSize, OS,
DI.IsLittleEndian);
writeVariableSizedInteger(Entry.HighOffset, DebugRanges.AddrSize, OS,
writeVariableSizedInteger(Entry.HighOffset, AddrSize, OS,
DI.IsLittleEndian);
}
ZeroFillBytes(OS, DebugRanges.AddrSize * 2);
ZeroFillBytes(OS, AddrSize * 2);
++EntryIndex;
}

View File

@ -97,7 +97,7 @@ void MappingTraits<DWARFYAML::RangeEntry>::mapping(
void MappingTraits<DWARFYAML::Ranges>::mapping(IO &IO,
DWARFYAML::Ranges &DebugRanges) {
IO.mapOptional("Offset", DebugRanges.Offset);
IO.mapRequired("AddrSize", DebugRanges.AddrSize);
IO.mapOptional("AddrSize", DebugRanges.AddrSize);
IO.mapRequired("Entries", DebugRanges.Entries);
}

View File

@ -1655,9 +1655,12 @@ 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)
if (Object.DWARF) {
Object.DWARF->IsLittleEndian =
Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
Object.DWARF->Is64bit =
Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
}
IO.setContext(nullptr);
}

View File

@ -107,6 +107,8 @@ void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
Object.DWARF.IsLittleEndian = Object.IsLittleEndian;
IO.mapRequired("FileHeader", Object.Header);
Object.DWARF.Is64bit = Object.Header.magic == MachO::MH_MAGIC_64 ||
Object.Header.magic == MachO::MH_CIGAM_64;
IO.mapOptional("LoadCommands", Object.LoadCommands);
if(!Object.LinkEdit.isEmpty() || !IO.outputting())
IO.mapOptional("LinkEditData", Object.LinkEdit);

View File

@ -203,7 +203,6 @@ DWARF:
Form: DW_FORM_addr
debug_ranges:
- Offset: 0x00000000
AddrSize: 0x08
Entries:
- LowOffset: 0x0000000000000000
HighOffset: 0x0000000000000020

View File

@ -84,8 +84,7 @@ DWARF:
HighOffset: 0x00000010
- LowOffset: 0x00000000
HighOffset: 0x00000000
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x0000000000000010
HighOffset: 0x0000000000000020
- LowOffset: 0x0000000000000030
@ -207,8 +206,7 @@ Sections:
Size: 0x10
DWARF:
debug_ranges:
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x0000000000000001
HighOffset: 0x0000000000000002
@ -229,8 +227,7 @@ Sections:
Content: "00"
DWARF:
debug_ranges:
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x0000000000000001
HighOffset: 0x0000000000000002
@ -290,8 +287,7 @@ Sections:
Type: SHT_STRTAB
DWARF:
debug_ranges:
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x0000000000000001
HighOffset: 0x0000000000000002
@ -345,17 +341,14 @@ FileHeader:
Machine: EM_X86_64
DWARF:
debug_ranges:
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x01
HighOffset: 0x02
- Offset: 0x21 ## There are 0x20 bytes before this entry.
AddrSize: 0x08
Entries:
- LowOffset: 0x01
HighOffset: 0x02
- Offset: 0x41 ## There are 0x41 bytes before this entry.
AddrSize: 0x08
Entries:
- LowOffset: 0x01
HighOffset: 0x02
@ -375,12 +368,10 @@ FileHeader:
Machine: EM_X86_64
DWARF:
debug_ranges:
- AddrSize: 0x08
Entries:
- Entries:
- LowOffset: 0x01
HighOffset: 0x02
- Offset: 0x1F ## Must be greater than or equal to 0x20.
AddrSize: 0x08
Entries:
- LowOffset: 0x01
HighOffset: 0x02