[llvm] ff9c1ae - [ObjectYAML][DWARF] Let the target address size be inferred from FileHeader.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 13 21:38:24 PDT 2020
Author: Xing GUO
Date: 2020-06-14T12:42:20+08:00
New Revision: ff9c1ae213a2ed6a760659a30f8399ffd56dc9b0
URL: https://github.com/llvm/llvm-project/commit/ff9c1ae213a2ed6a760659a30f8399ffd56dc9b0
DIFF: https://github.com/llvm/llvm-project/commit/ff9c1ae213a2ed6a760659a30f8399ffd56dc9b0.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/ObjectYAML/MachOYAML.cpp
llvm/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 08b02691ffc1..7b2f28db1f0e 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -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;
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 9ab6aa5aeafc..b373cfceff22 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -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;
}
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 8298047d8be9..bfb29181e3c6 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -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);
}
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 87f4eea126ae..84fbdb01365d 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -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);
}
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp
index a5341383e8a8..cd9ca76f5d2f 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -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);
diff --git a/llvm/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml b/llvm/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml
index be1a52a22efa..fe972a0fb40b 100644
--- a/llvm/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml
+++ b/llvm/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml
@@ -203,7 +203,6 @@ DWARF:
Form: DW_FORM_addr
debug_ranges:
- Offset: 0x00000000
- AddrSize: 0x08
Entries:
- LowOffset: 0x0000000000000000
HighOffset: 0x0000000000000020
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml
index db8eb89be7d8..adaceeeae8a7 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml
@@ -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
More information about the llvm-commits
mailing list