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 @@ -27,6 +27,8 @@ SecNames.insert("debug_str"); if (!ARanges.empty()) SecNames.insert("debug_aranges"); + if (!DebugRanges.empty()) + SecNames.insert("debug_ranges"); return SecNames; } diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -852,6 +852,8 @@ DWARFYAML::EmitDebugStr(OS, DWARF); else if (Name == ".debug_aranges") DWARFYAML::EmitDebugAranges(OS, DWARF); + else if (Name == ".debug_ranges") + DWARFYAML::EmitDebugRanges(OS, DWARF); else llvm_unreachable("unexpected emitDWARF() call"); diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml @@ -0,0 +1,265 @@ +## Test that yaml2obj emits .debug_ranges section. + +## a) Generate the .debug_ranges section from the "DWARF" entry. + +## Generate and verify a little endian .debug_ranges section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t.le.o +# RUN: llvm-readobj --sections --section-data %t.le.o | \ +# RUN: FileCheck %s -DSIZE=72 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-LE-CONTENT + +# DWARF-HEADER: Index: 1 +# DWARF-HEADER-NEXT: Name: .debug_ranges (1) +# DWARF-HEADER-NEXT: Type: SHT_PROGBITS (0x1) +# DWARF-HEADER-NEXT: Flags [ (0x0) +# DWARF-HEADER-NEXT: ] +# DWARF-HEADER-NEXT: Address: 0x0 +# DWARF-HEADER-NEXT: Offset: 0x40 +# DWARF-HEADER-NEXT: Size: [[SIZE]] +# DWARF-HEADER-NEXT: Link: 0 +# DWARF-HEADER-NEXT: Info: 0 +# DWARF-HEADER-NEXT: AddressAlignment: [[ADDRALIGN]] +# DWARF-HEADER-NEXT: EntrySize: 0 +# DWARF-LE-CONTENT: SectionData ( +# DWARF-LE-CONTENT-NEXT: 0000: 00000000 10000000 00000000 20000000 +## | | | | +## | | | +------- HighOffset (4-byte) 0x20 +## | | +------- LowOffset (4-byte) 0x00 +## | +------- HighOffset (4-byte) 0x10 +## +------- LowOffset (4-byte) 0x00 +## +# DWARF-LE-CONTENT-NEXT: 0010: 00000000 00000000 00000000 00000000 +## | | +## | +---------------- LowOffset (8-byte) 0x00 +## +---------------- Terminating Entry (8-byte) +# DWARF-LE-CONTENT-NEXT: 0020: 30000000 00000000 00000000 00000000 +## | | +## | +---------------- LowOffset (8-byte) 0x00 +## +---------------- HighOffset (8-byte) 0x30 +# DWARF-LE-CONTENT-NEXT: 0030: 40000000 00000000 00000000 00000000 +## | | +## | +---------------- Terminating Entry (Lower bits, 8-byte) +## +---------------- HighOffset (8-byte) 0x40 +# DWARF-LE-CONTENT-NEXT: 0040: 00000000 00000000 +## | +## +---------------- Terminating Entry (Higher bits, 8-byte) +# DWARF-LE-CONTENT-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: [[ENDIAN]] + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_ranges: + - Offset: 0 + AddrSize: 0x04 + Entries: + - LowOffset: 0x00000000 + HighOffset: 0x00000010 + - LowOffset: 0x00000000 + HighOffset: 0x00000020 + - Offset: 24 + AddrSize: 0x08 + Entries: + - LowOffset: 0x0000000000000000 + HighOffset: 0x0000000000000030 + - LowOffset: 0x0000000000000000 + HighOffset: 0x0000000000000040 + +## Generate and verify a big endian .debug_ranges section. + +# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o +# RUN: llvm-readobj --sections --section-data %t.be.o | \ +# RUN: FileCheck %s -DSIZE=72 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-BE-CONTENT + +# DWARF-BE-CONTENT: SectionData ( +# DWARF-BE-CONTENT-NEXT: 0000: 00000000 00000010 00000000 00000020 +## | | | | +## | | | +------- HighOffset (4-byte) 0x20 +## | | +------- LowOffset (4-byte) 0x00 +## | +------- HighOffset (4-byte) 0x10 +## +------- LowOffset (4-byte) 0x00 +## +# DWARF-BE-CONTENT-NEXT: 0010: 00000000 00000000 00000000 00000000 +## | | +## | +---------------- LowOffset (8-byte) 0x00 +## +---------------- Terminating Entry (8-byte) +# DWARF-BE-CONTENT-NEXT: 0020: 00000000 00000030 00000000 00000000 +## | | +## | +---------------- LowOffset (8-byte) 0x00 +## +---------------- HighOffset (8-byte) 0x30 +# DWARF-BE-CONTENT-NEXT: 0030: 00000000 00000040 00000000 00000000 +## | | +## | +---------------- Terminating Entry (Lower bits, 8-byte) +## +---------------- HighOffset (8-byte) 0x40 +# DWARF-BE-CONTENT-NEXT: 0040: 00000000 00000000 +## | +## +---------------- Terminating Entry (Higher bits, 8-byte) +# DWARF-BE-CONTENT-NEXT: ) + +## b) Generate the .debug_ranges section from raw section content. + +# RUN: yaml2obj --docnum=2 %s -o %t2.o +# RUN: llvm-readobj --sections --section-data %t2.o | \ +# RUN: FileCheck %s -DSIZE=3 -DADDRALIGN=0 --check-prefixes=DWARF-HEADER,ARBITRARY-CONTENT + +# ARBITRARY-CONTENT: SectionData ( +# ARBITRARY-CONTENT-NEXT: 0000: 112233 +# ARBITRARY-CONTENT-NEXT: ) + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_PROGBITS + Content: "112233" + +## c) Generate the .debug_ranges section when the "Size" is specified. + +# RUN: yaml2obj --docnum=3 %s -o %t3.o +# RUN: llvm-readobj --hex-dump=.debug_ranges %t3.o | FileCheck %s --check-prefix=SIZE + +# SIZE: Hex dump of section '.debug_ranges': +# SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................ +# SIZE-EMPTY: + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_PROGBITS + Size: 0x10 + +## d) Test that yaml2obj emits an error message when both the "Size" and the +## "debug_ranges" entry are specified at the same time. + +# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR + +# ERROR: yaml2obj: error: cannot specify section '.debug_ranges' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_PROGBITS + Size: 0x10 +DWARF: + debug_ranges: + - Offset: 0 + AddrSize: 0x04 + Entries: + - LowOffset: 0x00000000 + HighOffset: 0x00000000 + +## e) Test that yaml2obj emits an error message when both the "Content" and the +## "debug_ranges" entry are specified at the same time. + +# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_PROGBITS + Content: "00" +DWARF: + debug_ranges: + - Offset: 0 + AddrSize: 0x04 + Entries: + - LowOffset: 0x00000000 + HighOffset: 0x00000000 + +## f) Test that all the properties can be overridden by the section header when +## the "debug_ranges" entry doesn't exist. + +# RUN: yaml2obj --docnum=6 %s -o %t6.o +# RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN + +# OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# OVERRIDDEN: [ 1] .debug_ranges STRTAB 0000000000002020 000050 000010 01 A 2 1 2 +# OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000060 000000 00 0 0 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_STRTAB # SHT_PROGBITS by default. + Flags: [SHF_ALLOC] # 0 by default. + Link: .sec # 0 by default. + EntSize: 1 # 0 by default. + Info: 1 # 0 by default. + AddressAlign: 2 # 0 by default. + Address: 0x0000000000002020 # 0x00 by default. + Offset: 0x00000050 # 0x40 for the first section. + Size: 0x10 # Set the "Size" so that we can reuse the check tag "OVERRIDDEN". + - Name: .sec # Linked by .debug_ranges. + Type: SHT_STRTAB + +## g) Test that all the properties can be overridden by the section header when +## the "debug_ranges" entry exists. + +# RUN: yaml2obj --docnum=7 %s -o %t7.o +# RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .debug_ranges + Type: SHT_STRTAB # SHT_PROGBITS by default. + Flags: [SHF_ALLOC] # 0 by default. + Link: .sec # 0 by default. + EntSize: 1 # 0 by default. + Info: 1 # 0 by default. + AddressAlign: 2 # 1 by default. + Address: 0x0000000000002020 # 0x00 by default. + Offset: 0x00000050 # 0x40 for the first section. + - Name: .sec # Linked by .debug_ranges. + Type: SHT_STRTAB +DWARF: + debug_ranges: + - Offset: 0 + AddrSize: 0x04 + Entries: + - LowOffset: 0x00000000 + HighOffset: 0x00000000 + +## h) Test that yaml2obj will not generate the .debug_ranges section when the "DWARF" entry +## exists but the "debug_ranges" entry doesn't exist in the "DWARF" entry or the "Sections" entry. + +# RUN: yaml2obj --docnum=8 %s -o %t8.o +# RUN: llvm-readelf --sections %t8.o | FileCheck /dev/null --implicit-check-not=.debug_ranges + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: