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 @@ -120,7 +120,7 @@ InitialLength Length; uint16_t Version; llvm::dwarf::UnitType Type; // Added in DWARF 5 - uint32_t AbbrOffset; + yaml::Hex64 AbbrOffset; uint8_t AddrSize; std::vector Entries; }; 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 @@ -212,9 +212,13 @@ if (CU.Version >= 5) { writeInteger((uint8_t)CU.Type, OS, DebugInfo.IsLittleEndian); writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian); - writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian); + cantFail(writeVariableSizedInteger(CU.AbbrOffset, + CU.Length.isDWARF64() ? 8 : 4, OS, + DebugInfo.IsLittleEndian)); } else { - writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian); + cantFail(writeVariableSizedInteger(CU.AbbrOffset, + CU.Length.isDWARF64() ? 8 : 4, OS, + DebugInfo.IsLittleEndian)); writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian); } } diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml --- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml @@ -669,3 +669,68 @@ - AbbrCode: 1 Values: - Value: 0x1234 + +## j) Test that yaml2obj emits the correct DWARF64 unit headers. + +## DWARFv5 unit header. + +# RUN: yaml2obj --docnum=11 %s -o %t11.o +# RUN: llvm-readelf --hex-dump=.debug_info %t11.o | \ +# RUN: FileCheck %s --check-prefix=DWARFV5-HEADER + +# DWARFV5-HEADER: Hex dump of section '.debug_info': +# DWARFV5-HEADER-NEXT: 0x00000000 ffffffff 0c000000 00000000 05000208 ................ +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^- unit_type (1-byte) +## ^- address_size (1-byte) +# DWARFV5-HEADER-NEXT: 0x00000010 34120000 00000000 4....... +## ^---------------- debug_abbrev_offset (8-byte) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_info: + - Length: + TotalLength: 0xffffffff + TotalLength64: 0x0c + Version: 5 + UnitType: DW_UT_type + AbbrOffset: 0x1234 + AddrSize: 8 + Entries: [] + +## DWARFv4 unit header. + +# RUN: yaml2obj --docnum=12 %s -o %t12.o +# RUN: llvm-readelf --hex-dump=.debug_info %t12.o | \ +# RUN: FileCheck %s --check-prefix=DWARFV4-HEADER + +# DWARFV4-HEADER: Hex dump of section '.debug_info': +# DWARFV4-HEADER-NEXT: 0x00000000 ffffffff 0c000000 00000000 04003412 ..............4. +## ^------------------------- unit_length (12-byte) +## ^--- version (2-byte) +## ^--- debug_abbrev_offset (8-byte) +# DWARFV4-HEADER-NEXT: 0x00000010 00000000 000008 ....... +## ------------- +## ^- address_size (1-byte) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_info: + - Length: + TotalLength: 0xffffffff + TotalLength64: 0x0c + Version: 4 + AbbrOffset: 0x1234 + AddrSize: 8 + Entries: []