diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h --- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h +++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h @@ -26,26 +26,6 @@ namespace llvm { namespace DWARFYAML { -struct InitialLength { - uint32_t TotalLength; - uint64_t TotalLength64; - - bool isDWARF64() const { return TotalLength == UINT32_MAX; } - - uint64_t getLength() const { - return isDWARF64() ? TotalLength64 : TotalLength; - } - - void setLength(uint64_t Len) { - if (Len >= (uint64_t)UINT32_MAX) { - TotalLength64 = Len; - TotalLength = UINT32_MAX; - } else { - TotalLength = Len; - } - } -}; - struct AttributeAbbrev { llvm::dwarf::Attribute Attribute; llvm::dwarf::Form Form; @@ -95,7 +75,8 @@ }; struct PubSection { - InitialLength Length; + dwarf::DwarfFormat Format; + yaml::Hex64 Length; uint16_t Version; uint32_t UnitOffset; uint32_t UnitSize; @@ -375,10 +356,6 @@ static void mapping(IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable); }; -template <> struct MappingTraits { - static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF); -}; - template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, dwarf::DwarfFormat &Format) { IO.enumCase(Format, "DWARF32", dwarf::DWARF32); diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -68,13 +68,6 @@ OS.write(reinterpret_cast(FillData.data()), Size); } -static void writeInitialLength(const DWARFYAML::InitialLength &Length, - raw_ostream &OS, bool IsLittleEndian) { - writeInteger((uint32_t)Length.TotalLength, OS, IsLittleEndian); - if (Length.isDWARF64()) - writeInteger((uint64_t)Length.TotalLength64, OS, IsLittleEndian); -} - static void writeInitialLength(const dwarf::DwarfFormat Format, const uint64_t Length, raw_ostream &OS, bool IsLittleEndian) { @@ -213,12 +206,12 @@ static Error emitPubSection(raw_ostream &OS, const DWARFYAML::PubSection &Sect, bool IsLittleEndian, bool IsGNUPubSec = false) { - writeInitialLength(Sect.Length, OS, IsLittleEndian); + writeInitialLength(Sect.Format, Sect.Length, OS, IsLittleEndian); writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian); - writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian); - writeInteger((uint32_t)Sect.UnitSize, OS, IsLittleEndian); + writeDWARFOffset(Sect.UnitOffset, Sect.Format, OS, IsLittleEndian); + writeDWARFOffset(Sect.UnitSize, Sect.Format, OS, IsLittleEndian); for (auto Entry : Sect.Entries) { - writeInteger((uint32_t)Entry.DieOffset, OS, IsLittleEndian); + writeDWARFOffset(Entry.DieOffset, Sect.Format, OS, IsLittleEndian); if (IsGNUPubSec) writeInteger((uint8_t)Entry.Descriptor, OS, IsLittleEndian); OS.write(Entry.Name.data(), Entry.Name.size()); diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp --- a/llvm/lib/ObjectYAML/DWARFYAML.cpp +++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp @@ -136,6 +136,7 @@ void MappingTraits::mapping( IO &IO, DWARFYAML::PubSection &Section) { + IO.mapOptional("Format", Section.Format, dwarf::DWARF32); IO.mapRequired("Length", Section.Length); IO.mapRequired("Version", Section.Version); IO.mapRequired("UnitOffset", Section.UnitOffset); @@ -286,13 +287,6 @@ IO.mapOptional("Lists", ListTable.Lists); } -void MappingTraits::mapping( - IO &IO, DWARFYAML::InitialLength &InitialLength) { - IO.mapRequired("TotalLength", InitialLength.TotalLength); - if (InitialLength.isDWARF64()) - IO.mapRequired("TotalLength64", InitialLength.TotalLength64); -} - } // end namespace yaml } // end namespace llvm diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml @@ -403,8 +403,7 @@ - Address: 0x0000000100000F50 Length: 52 debug_pubnames: - Length: - TotalLength: 23 + Length: 23 Version: 2 UnitOffset: 0 UnitSize: 121 @@ -412,8 +411,7 @@ - DieOffset: 0x0000002A Name: main debug_pubtypes: - Length: - TotalLength: 31 + Length: 31 Version: 2 UnitOffset: 0 UnitSize: 121 diff --git a/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml b/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml --- a/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml +++ b/llvm/test/ObjectYAML/MachO/DWARF-pubsections.yaml @@ -308,8 +308,7 @@ - int - char debug_pubnames: - Length: - TotalLength: 23 + Length: 23 Version: 2 UnitOffset: 0 UnitSize: 121 @@ -317,8 +316,7 @@ - DieOffset: 0x0000002A Name: main debug_pubtypes: - Length: - TotalLength: 31 + Length: 31 Version: 2 UnitOffset: 0 UnitSize: 121 @@ -331,8 +329,7 @@ #CHECK: DWARF: #CHECK: debug_pubnames: -#CHECK: Length: -#CHECK: TotalLength: 23 +#CHECK: Length: 0x0000000000000017 #CHECK: Version: 2 #CHECK: UnitOffset: 0 #CHECK: UnitSize: 121 @@ -340,8 +337,7 @@ #CHECK: - DieOffset: 0x0000002A #CHECK: Name: main #CHECK: debug_pubtypes: -#CHECK: Length: -#CHECK: TotalLength: 31 +#CHECK: Length: 0x000000000000001F #CHECK: Version: 2 #CHECK: UnitOffset: 0 #CHECK: UnitSize: 121 diff --git a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml --- a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml +++ b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml @@ -387,8 +387,7 @@ - Address: 0x000000000000BFF0 Length: 16 debug_pubnames: - Length: - TotalLength: 23 + Length: 23 Version: 2 UnitOffset: 0 UnitSize: 119 @@ -396,8 +395,7 @@ - DieOffset: 0x00000026 Name: main debug_pubtypes: - Length: - TotalLength: 31 + Length: 31 Version: 2 UnitOffset: 0 UnitSize: 119 @@ -865,8 +863,7 @@ - Address: 0x0000000100007F9C Length: 28 debug_pubnames: - Length: - TotalLength: 23 + Length: 23 Version: 2 UnitOffset: 0 UnitSize: 126 @@ -874,8 +871,7 @@ - DieOffset: 0x0000002A Name: main debug_pubtypes: - Length: - TotalLength: 31 + Length: 31 Version: 2 UnitOffset: 0 UnitSize: 126 diff --git a/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml --- a/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml +++ b/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml @@ -550,8 +550,7 @@ - Address: 0x0000000100000F90 Length: 37 debug_pubnames: - Length: - TotalLength: 43 + Length: 43 Version: 2 UnitOffset: 0 UnitSize: 224 @@ -563,8 +562,7 @@ - DieOffset: 0x00000069 Name: main debug_pubtypes: - Length: - TotalLength: 31 + Length: 31 Version: 2 UnitOffset: 0 UnitSize: 224 diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubnames.yaml @@ -44,8 +44,8 @@ Machine: EM_X86_64 DWARF: debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Format: [[FORMAT=DWARF32]] + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -79,6 +79,58 @@ ## ^------- name "def\0" # DWARF32-BE-NEXT: ) +## Generate and verify a DWARF64 little endian .debug_gnu_pubnames section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.le.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.le.o | \ +# RUN: FileCheck -DSIZE=56 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE + +# DWARF64-LE-NEXT: SectionData ( +# DWARF64-LE-NEXT: 0000: FFFFFFFF 34120000 00000000 02003412 |....4.........4.| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-LE-NEXT: 0010: 00000000 00002143 00000000 00007856 |......!C......xV| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-LE-NEXT: 0020: 34120000 00003061 62630021 43658700 |4.....0abc.!Ce..| +## ------------- +## ^- descriptor (1-byte) +## ^-------- name "abc\0" +## ^---------- offset (8-byte) +# DWARF64-LE-NEXT: 0030: 00000030 64656600 |...0def.| +## ------ +## ^- descriptor (1-byte) +## ^------- name "def\0" +# DWARF64-LE-NEXT: ) + +## Generate and verify a DWARF64 big endian .debug_gnu_pubnames section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.be.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.be.o | \ +# RUN: FileCheck -DSIZE=56 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE + +# DWARF64-BE-NEXT: SectionData ( +# DWARF64-BE-NEXT: 0000: FFFFFFFF 00000000 00001234 00020000 |...........4....| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-BE-NEXT: 0010: 00000000 12340000 00000000 43210000 |.....4......C!..| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-BE-NEXT: 0020: 00001234 56783061 62630000 00000087 |...4Vx0abc......| +## ------------- +## ^- descriptor (1-byte) +## ^-------- name "abc\0" +## ^---------- offset (8-byte) +# DWARF64-BE-NEXT: 0030: 65432130 64656600 |eC!0def.| +## ------ +## ^- descriptor (1-byte) +## ^------- name "def\0" +# DWARF64-BE-NEXT: ) + ## b) Generate the .debug_gnu_pubnames section from raw section content. # RUN: yaml2obj --docnum=2 %s -o %t2.o @@ -140,8 +192,7 @@ Size: 0x10 DWARF: debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -164,8 +215,7 @@ Content: "00" DWARF: debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -227,8 +277,7 @@ Type: SHT_STRTAB DWARF: debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -238,7 +287,7 @@ # RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck %s --check-prefix=MISSING-KEY --ignore-case -# MISSING-KEY: YAML:260:9: error: missing required key 'Descriptor' +# MISSING-KEY: YAML:{{.*}}:9: error: missing required key 'Descriptor' # MISSING-KEY-NEXT: - DieOffset: 0x12345678 # MISSING-KEY-NEXT: ^ # MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: Invalid argument @@ -251,8 +300,7 @@ Machine: EM_X86_64 DWARF: debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubtypes.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubtypes.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubtypes.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-gnu-pubtypes.yaml @@ -44,8 +44,8 @@ Machine: EM_X86_64 DWARF: debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Format: [[FORMAT=DWARF32]] + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -79,6 +79,58 @@ ## ^------- name "def\0" # DWARF32-BE-NEXT: ) +## Generate and verify a DWARF64 little endian .debug_gnu_pubtypes section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.le.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.le.o | \ +# RUN: FileCheck -DSIZE=56 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE + +# DWARF64-LE-NEXT: SectionData ( +# DWARF64-LE-NEXT: 0000: FFFFFFFF 34120000 00000000 02003412 |....4.........4.| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-LE-NEXT: 0010: 00000000 00002143 00000000 00007856 |......!C......xV| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-LE-NEXT: 0020: 34120000 00001261 62630021 43658700 |4......abc.!Ce..| +## ------------- +## ^- descriptor (1-byte) +## ^-------- name "abc\0" +## ^---------- offset (8-byte) +# DWARF64-LE-NEXT: 0030: 00000034 64656600 |...4def.| +## ------ +## ^- descriptor (1-byte) +## ^------- name "def\0" +# DWARF64-LE-NEXT: ) + +## Generate and verify a DWARF64 big endian .debug_gnu_pubtypes section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.be.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.be.o | \ +# RUN: FileCheck -DSIZE=56 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE + +# DWARF64-BE-NEXT: SectionData ( +# DWARF64-BE-NEXT: 0000: FFFFFFFF 00000000 00001234 00020000 |...........4....| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-BE-NEXT: 0010: 00000000 12340000 00000000 43210000 |.....4......C!..| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-BE-NEXT: 0020: 00001234 56781261 62630000 00000087 |...4Vx.abc......| +## ------------- +## ^- descriptor (1-byte) +## ^-------- name "abc\0" +## ^---------- offset (8-byte) +# DWARF64-BE-NEXT: 0030: 65432134 64656600 |eC!4def.| +## ------ +## ^- descriptor (1-byte) +## ^------- name "def\0" +# DWARF64-BE-NEXT: ) + ## b) Generate the .debug_gnu_pubtypes section from raw section content. # RUN: yaml2obj --docnum=2 %s -o %t2.o @@ -140,8 +192,7 @@ Size: 0x10 DWARF: debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -164,8 +215,7 @@ Content: "00" DWARF: debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -227,8 +277,7 @@ Type: SHT_STRTAB DWARF: debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -238,7 +287,7 @@ # RUN: not yaml2obj --docnum=8 %s -o %t8.o 2>&1 | FileCheck %s --check-prefix=MISSING-KEY --ignore-case -# MISSING-KEY: YAML:260:9: error: missing required key 'Descriptor' +# MISSING-KEY: YAML:{{.*}}:9: error: missing required key 'Descriptor' # MISSING-KEY-NEXT: - DieOffset: 0x12345678 # MISSING-KEY-NEXT: ^ # MISSING-KEY-NEXT: yaml2obj: error: failed to parse YAML input: Invalid argument @@ -251,8 +300,7 @@ Machine: EM_X86_64 DWARF: debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubnames.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubnames.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubnames.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubnames.yaml @@ -2,10 +2,10 @@ ## a) Generate the '.debug_pubnames' section from the 'DWARF' entry. -## Generate and verify a 32-bit little endian .debug_pubnames section. +## Generate and verify a DWARF32 little endian .debug_pubnames section. -# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.le.o -# RUN: llvm-readobj --sections --section-data %t1.le.o | \ +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.dwarf32.le.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf32.le.o | \ # RUN: FileCheck -DSIZE=30 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE # SHDR: Index: 1 @@ -43,8 +43,8 @@ Machine: EM_X86_64 DWARF: debug_pubnames: - Length: - TotalLength: 0x1234 + Format: [[FORMAT=DWARF32]] + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -54,10 +54,10 @@ - DieOffset: 0x87654321 Name: def -## Generate and verify a 32-bit big endian .debug_pubnames section. +## Generate and verify a DWARF32 big endian .debug_pubnames section. -# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.be.o -# RUN: llvm-readobj --sections --section-data %t1.be.o | \ +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.dwarf32.be.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf32.be.o | \ # RUN: FileCheck -DSIZE=30 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE # DWARF32-BE-NEXT: SectionData ( @@ -75,6 +75,54 @@ ## ^-------- name "def\0" # DWARF32-BE-NEXT: ) +## Generate and verify a DWARF64 little endian .debug_pubnames section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.le.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.le.o | \ +# RUN: FileCheck -DSIZE=54 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE + +# DWARF64-LE-NEXT: SectionData ( +# DWARF64-LE-NEXT: 0000: FFFFFFFF 34120000 00000000 02003412 |....4.........4.| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-LE-NEXT: 0010: 00000000 00002143 00000000 00007856 |......!C......xV| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-LE-NEXT: 0020: 34120000 00006162 63002143 65870000 |4.....abc.!Ce...| +## ------------- +## ^-------- name "abc\0" +## ^------------ offset (8-byte) +# DWARF64-LE-NEXT: 0030: 00006465 6600 |..def.| +## ---- +## ^-------- name "def\0" +# DWARF64-LE-NEXT: ) + +## Generate and verify a DWARF64 big endian .debug_pubnames section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.be.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.be.o | \ +# RUN: FileCheck -DSIZE=54 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE + +# DWARF64-BE-NEXT: SectionData ( +# DWARF64-BE-NEXT: 0000: FFFFFFFF 00000000 00001234 00020000 |...........4....| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-BE-NEXT: 0010: 00000000 12340000 00000000 43210000 |.....4......C!..| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-BE-NEXT: 0020: 00001234 56786162 63000000 00008765 |...4Vxabc......e| +## ------------- +## ^-------- name "abc\0" +## ^------------ offset (8-byte) +# DWARF64-BE-NEXT: 0030: 43216465 6600 |C!def.| +## ---- +## ^-------- name "def\0" +# DWARF64-BE-NEXT: ) + ## b) Generate the .debug_pubnames section from raw section content. # RUN: yaml2obj --docnum=2 %s -o %t2.o @@ -136,8 +184,7 @@ Size: 0x10 DWARF: debug_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -160,8 +207,7 @@ Content: "00" DWARF: debug_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -223,8 +269,7 @@ Type: SHT_STRTAB DWARF: debug_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubtypes.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubtypes.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubtypes.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-pubtypes.yaml @@ -43,8 +43,8 @@ Machine: EM_X86_64 DWARF: debug_pubtypes: - Length: - TotalLength: 0x1234 + Format: [[FORMAT=DWARF32]] + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -75,6 +75,54 @@ ## ^-------- name "def\0" # DWARF32-BE-NEXT: ) +## Generate and verify a DWARF64 little endian .debug_pubtypes section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.le.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.le.o | \ +# RUN: FileCheck -DSIZE=54 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE + +# DWARF64-LE-NEXT: SectionData ( +# DWARF64-LE-NEXT: 0000: FFFFFFFF 34120000 00000000 02003412 |....4.........4.| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-LE-NEXT: 0010: 00000000 00002143 00000000 00007856 |......!C......xV| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-LE-NEXT: 0020: 34120000 00006162 63002143 65870000 |4.....abc.!Ce...| +## ------------- +## ^-------- name "abc\0" +## ^------------ offset (8-byte) +# DWARF64-LE-NEXT: 0030: 00006465 6600 |..def.| +## ---- +## ^-------- name "def\0" +# DWARF64-LE-NEXT: ) + +## Generate and verify a DWARF64 big endian .debug_pubtypes section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF64 %s -o %t1.dwarf64.be.o +# RUN: llvm-readobj --sections --section-data %t1.dwarf64.be.o | \ +# RUN: FileCheck -DSIZE=54 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE + +# DWARF64-BE-NEXT: SectionData ( +# DWARF64-BE-NEXT: 0000: FFFFFFFF 00000000 00001234 00020000 |...........4....| +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_info_offset (8-byte) +# DWARF64-BE-NEXT: 0010: 00000000 12340000 00000000 43210000 |.....4......C!..| +## ------------- +## ^----------------- debug_info_length (8-byte) +## ^--- offset (8-byte) +# DWARF64-BE-NEXT: 0020: 00001234 56786162 63000000 00008765 |...4Vxabc......e| +## ------------- +## ^-------- name "abc\0" +## ^------------ offset (8-byte) +# DWARF64-BE-NEXT: 0030: 43216465 6600 |C!def.| +## ---- +## ^-------- name "def\0" +# DWARF64-BE-NEXT: ) + ## b) Generate the .debug_pubtypes section from raw section content. # RUN: yaml2obj --docnum=2 %s -o %t2.o @@ -136,8 +184,7 @@ Size: 0x10 DWARF: debug_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -160,8 +207,7 @@ Content: "00" DWARF: debug_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 @@ -223,8 +269,7 @@ Type: SHT_STRTAB DWARF: debug_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x1234 UnitSize: 0x4321 diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp --- a/llvm/tools/obj2yaml/dwarf2yaml.cpp +++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp @@ -19,13 +19,6 @@ using namespace llvm; -void dumpInitialLength(DataExtractor &Data, uint64_t &Offset, - DWARFYAML::InitialLength &InitialLength) { - InitialLength.TotalLength = Data.getU32(&Offset); - if (InitialLength.isDWARF64()) - InitialLength.TotalLength64 = Data.getU64(&Offset); -} - void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) { auto AbbrevSetPtr = DCtx.getDebugAbbrev(); if (AbbrevSetPtr) { @@ -132,11 +125,18 @@ DCtx.isLittleEndian(), 0); DWARFYAML::PubSection Y; uint64_t Offset = 0; - dumpInitialLength(PubSectionData, Offset, Y.Length); + uint64_t Length = PubSectionData.getU32(&Offset); + if (Length == dwarf::DW_LENGTH_DWARF64) { + Y.Format = dwarf::DWARF64; + Y.Length = PubSectionData.getU64(&Offset); + } else { + Y.Format = dwarf::DWARF32; + Y.Length = Length; + } Y.Version = PubSectionData.getU16(&Offset); Y.UnitOffset = PubSectionData.getU32(&Offset); Y.UnitSize = PubSectionData.getU32(&Offset); - while (Offset < Y.Length.getLength()) { + while (Offset < Y.Length) { DWARFYAML::PubEntry NewEntry; NewEntry.DieOffset = PubSectionData.getU32(&Offset); if (IsGNUStyle) diff --git a/llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp b/llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp --- a/llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp +++ b/llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp @@ -68,8 +68,7 @@ TEST(DebugPubSection, TestDebugPubSection) { StringRef Yaml = R"( debug_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00 @@ -79,8 +78,7 @@ - DieOffset: 0x4321 Name: def debug_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00 @@ -115,8 +113,7 @@ TEST(DebugPubSection, TestUnexpectedDescriptor) { StringRef Yaml = R"( debug_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00 @@ -133,8 +130,7 @@ TEST(DebugGNUPubSection, TestDebugGNUPubSections) { StringRef Yaml = R"( debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00 @@ -146,8 +142,7 @@ Descriptor: 0x34 Name: def debug_gnu_pubtypes: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00 @@ -188,8 +183,7 @@ TEST(DebugGNUPubSection, TestMissingDescriptor) { StringRef Yaml = R"( debug_gnu_pubnames: - Length: - TotalLength: 0x1234 + Length: 0x1234 Version: 2 UnitOffset: 0x4321 UnitSize: 0x00