aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2024-08-12 11:08:38 +0200
committerGitHub <noreply@github.com>2024-08-12 11:08:38 +0200
commit8a1846dbdcc62675b51d245caabfe3c6ec6fd209 (patch)
tree5a079bc5f24ac4a4bf9845c8e2ee573fdcbb91fd /llvm/lib/ObjectYAML
parentd12250ca7bea22ed12caf44fe80b203d83db75bb (diff)
downloadllvm-8a1846dbdcc62675b51d245caabfe3c6ec6fd209.zip
llvm-8a1846dbdcc62675b51d245caabfe3c6ec6fd209.tar.gz
llvm-8a1846dbdcc62675b51d245caabfe3c6ec6fd209.tar.bz2
[dwarf2yaml] Correctly emit type and split unit headers (#102471)
(DWARFv5) split units have an extra `dwo_id` field in the header. Type units have `type_signature` and `type_offset`.
Diffstat (limited to 'llvm/lib/ObjectYAML')
-rw-r--r--llvm/lib/ObjectYAML/DWARFEmitter.cpp37
-rw-r--r--llvm/lib/ObjectYAML/DWARFYAML.cpp20
2 files changed, 52 insertions, 5 deletions
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 39195bf..15100f3 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -405,8 +405,8 @@ static Expected<uint64_t> writeDIE(const DWARFYAML::Data &DI, uint64_t CUIndex,
}
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
- for (uint64_t I = 0; I < DI.CompileUnits.size(); ++I) {
- const DWARFYAML::Unit &Unit = DI.CompileUnits[I];
+ for (uint64_t I = 0; I < DI.Units.size(); ++I) {
+ const DWARFYAML::Unit &Unit = DI.Units[I];
uint8_t AddrSize;
if (Unit.AddrSize)
AddrSize = *Unit.AddrSize;
@@ -414,8 +414,24 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
AddrSize = DI.Is64BitAddrSize ? 8 : 4;
dwarf::FormParams Params = {Unit.Version, AddrSize, Unit.Format};
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
- Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type)
Length += Params.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
+ if (Unit.Version >= 5) {
+ ++Length; // sizeof(unit_type)
+ switch (Unit.Type) {
+ case dwarf::DW_UT_compile:
+ case dwarf::DW_UT_partial:
+ default:
+ break;
+ case dwarf::DW_UT_type:
+ case dwarf::DW_UT_split_type:
+ // sizeof(type_signature) + sizeof(type_offset)
+ Length += 8 + Params.getDwarfOffsetByteSize();
+ break;
+ case dwarf::DW_UT_skeleton:
+ case dwarf::DW_UT_split_compile:
+ Length += 8; // sizeof(dwo_id)
+ }
+ }
// Since the length of the current compilation unit is undetermined yet, we
// firstly write the content of the compilation unit to a buffer to
@@ -461,6 +477,21 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian);
writeDWARFOffset(AbbrevTableOffset, Unit.Format, OS, DI.IsLittleEndian);
+ switch (Unit.Type) {
+ case dwarf::DW_UT_compile:
+ case dwarf::DW_UT_partial:
+ default:
+ break;
+ case dwarf::DW_UT_type:
+ case dwarf::DW_UT_split_type:
+ writeInteger(Unit.TypeSignatureOrDwoID, OS, DI.IsLittleEndian);
+ writeDWARFOffset(Unit.TypeOffset, Unit.Format, OS, DI.IsLittleEndian);
+ break;
+ case dwarf::DW_UT_skeleton:
+ case dwarf::DW_UT_split_compile:
+ writeInteger(Unit.TypeSignatureOrDwoID, OS, DI.IsLittleEndian);
+ break;
+ }
} else {
writeDWARFOffset(AbbrevTableOffset, Unit.Format, OS, DI.IsLittleEndian);
writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian);
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 5207671..c65a494 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -36,7 +36,7 @@ SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
SecNames.insert("debug_addr");
if (!DebugAbbrev.empty())
SecNames.insert("debug_abbrev");
- if (!CompileUnits.empty())
+ if (!Units.empty())
SecNames.insert("debug_info");
if (PubNames)
SecNames.insert("debug_pubnames");
@@ -101,7 +101,7 @@ void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
DWARFCtx.IsGNUPubSec = true;
IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
- IO.mapOptional("debug_info", DWARF.CompileUnits);
+ IO.mapOptional("debug_info", DWARF.Units);
IO.mapOptional("debug_line", DWARF.DebugLines);
IO.mapOptional("debug_addr", DWARF.DebugAddr);
IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets);
@@ -216,6 +216,22 @@ void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
IO.mapOptional("AbbrevTableID", Unit.AbbrevTableID);
IO.mapOptional("AbbrOffset", Unit.AbbrOffset);
IO.mapOptional("AddrSize", Unit.AddrSize);
+ if (Unit.Version >= 5) {
+ switch (Unit.Type) {
+ case dwarf::DW_UT_compile:
+ case dwarf::DW_UT_partial:
+ default:
+ break;
+ case dwarf::DW_UT_type:
+ case dwarf::DW_UT_split_type:
+ IO.mapRequired("TypeSignature", Unit.TypeSignatureOrDwoID);
+ IO.mapRequired("TypeOffset", Unit.TypeOffset);
+ break;
+ case dwarf::DW_UT_skeleton:
+ case dwarf::DW_UT_split_compile:
+ IO.mapRequired("DwoID", Unit.TypeSignatureOrDwoID);
+ }
+ }
IO.mapOptional("Entries", Unit.Entries);
}