[llvm] 74b02d7 - [DWARFYAML] Make the debug_aranges entry optional.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 05:21:15 PDT 2020
Author: Xing GUO
Date: 2020-07-31T20:18:53+08:00
New Revision: 74b02d73e34278e081dcb4946d66b9562f0986fe
URL: https://github.com/llvm/llvm-project/commit/74b02d73e34278e081dcb4946d66b9562f0986fe
DIFF: https://github.com/llvm/llvm-project/commit/74b02d73e34278e081dcb4946d66b9562f0986fe.diff
LOG: [DWARFYAML] Make the debug_aranges entry optional.
This patch makes the 'debug_aranges' entry optional. If the entry is
empty, yaml2obj will only emit the header for it.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D84921
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/lib/ObjectYAML/MachOEmitter.cpp
llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
llvm/tools/obj2yaml/dwarf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 32382da6de50..5737ceccc0a4 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -211,7 +211,7 @@ struct Data {
std::vector<Abbrev> AbbrevDecls;
std::vector<StringRef> DebugStrings;
Optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
- std::vector<ARange> ARanges;
+ Optional<std::vector<ARange>> DebugAranges;
std::vector<Ranges> DebugRanges;
std::vector<AddrTableEntry> DebugAddr;
Optional<PubSection> PubNames;
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index dbf417780cfc..ab3cd05a6495 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -126,7 +126,8 @@ Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
}
Error DWARFYAML::emitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
- for (auto Range : DI.ARanges) {
+ assert(DI.DebugAranges && "unexpected emitDebugAranges() call");
+ for (auto Range : *DI.DebugAranges) {
uint8_t AddrSize;
if (Range.AddrSize)
AddrSize = *Range.AddrSize;
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 7dd289ff6973..04dd185ad954 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -17,7 +17,7 @@
namespace llvm {
bool DWARFYAML::Data::isEmpty() const {
- return DebugStrings.empty() && AbbrevDecls.empty() && ARanges.empty() &&
+ return DebugStrings.empty() && AbbrevDecls.empty() && DebugAranges &&
DebugRanges.empty() && !PubNames && !PubTypes && !GNUPubNames &&
!GNUPubTypes && CompileUnits.empty() && DebugLines.empty();
}
@@ -26,7 +26,7 @@ SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
SetVector<StringRef> SecNames;
if (!DebugStrings.empty())
SecNames.insert("debug_str");
- if (!ARanges.empty())
+ if (DebugAranges)
SecNames.insert("debug_aranges");
if (!DebugRanges.empty())
SecNames.insert("debug_ranges");
@@ -61,8 +61,7 @@ void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
IO.setContext(&DWARFCtx);
IO.mapOptional("debug_str", DWARF.DebugStrings);
IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
- if (!DWARF.ARanges.empty() || !IO.outputting())
- IO.mapOptional("debug_aranges", DWARF.ARanges);
+ IO.mapOptional("debug_aranges", DWARF.DebugAranges);
if (!DWARF.DebugRanges.empty() || !IO.outputting())
IO.mapOptional("debug_ranges", DWARF.DebugRanges);
IO.mapOptional("debug_pubnames", DWARF.PubNames);
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 619572a7532c..9b454c528a7e 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -293,9 +293,10 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
Err = DWARFYAML::emitDebugStr(OS, Obj.DWARF);
else if (0 == strncmp(&Sec.sectname[0], "__debug_abbrev", 16))
Err = DWARFYAML::emitDebugAbbrev(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16))
- Err = DWARFYAML::emitDebugAranges(OS, Obj.DWARF);
- else if (0 == strncmp(&Sec.sectname[0], "__debug_ranges", 16))
+ else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16)) {
+ if (Obj.DWARF.DebugAranges)
+ Err = DWARFYAML::emitDebugAranges(OS, Obj.DWARF);
+ } else if (0 == strncmp(&Sec.sectname[0], "__debug_ranges", 16))
Err = DWARFYAML::emitDebugRanges(OS, Obj.DWARF);
else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) {
if (Obj.DWARF.PubNames)
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
index ecdd88a68dd0..1e9b880c3cd3 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
@@ -1,4 +1,7 @@
-# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+## a) Test that yaml2macho is able to emit the .debug_aranges section and obj2yaml
+## is able to convert it back.
+
+# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s
--- !mach-o
FileHeader:
@@ -331,3 +334,65 @@ DWARF:
# CHECK-NEXT: Descriptors:
# CHECK-NEXT: - Address: 0x0000000100000F50
# CHECK-NEXT: Length: 52
+
+## b) Test that if the "debug_aranges" entry is empty, yaml2macho will only emit the
+## section header.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2.o
+# RUN: llvm-readobj --sections --section-data %t2.o | FileCheck %s --check-prefix=EMPTY-SECTION
+
+# EMPTY-SECTION: Index: 0
+# EMPTY-SECTION-NEXT: Name: __debug_aranges (5F 5F 64 65 62 75 67 5F 61 72 61 6E 67 65 73 00)
+# EMPTY-SECTION-NEXT: Segment: __DWARF (5F 5F 44 57 41 52 46 00 00 00 00 00 00 00 00 00)
+# EMPTY-SECTION-NEXT: Address: 0x0
+# EMPTY-SECTION-NEXT: Size: 0xC
+# EMPTY-SECTION-NEXT: Offset: 528
+# EMPTY-SECTION-NEXT: Alignment: 0
+# EMPTY-SECTION-NEXT: RelocationOffset: 0x0
+# EMPTY-SECTION-NEXT: RelocationCount: 0
+# EMPTY-SECTION-NEXT: Type: Regular (0x0)
+# EMPTY-SECTION-NEXT: Attributes [ (0x0)
+# EMPTY-SECTION-NEXT: ]
+# EMPTY-SECTION-NEXT: Reserved1: 0x0
+# EMPTY-SECTION-NEXT: Reserved2: 0x0
+# EMPTY-SECTION-NEXT: Reserved3: 0x0
+# EMPTY-SECTION-NEXT: SectionData (
+# EMPTY-SECTION-NEXT: )
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x0000000A
+ ncmds: 1
+ sizeofcmds: 232
+ flags: 0x00000000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __DWARF
+ vmaddr: 0x00
+ vmsize: 0x00
+ fileoff: 0x00
+ filesize: 0x00
+ maxprot: 0
+ initprot: 0
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __debug_aranges
+ segname: __DWARF
+ addr: 0x00
+ size: 12
+ offset: 528
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+DWARF:
+ debug_aranges: []
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
index 9fa86449053d..4fa924c33ad1 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
@@ -595,3 +595,22 @@ DWARF:
Descriptors:
- Address: 0x1234
Length: 0x4321
+
+## l) Test that the .debug_aranges section header is emitted if the "debug_aranges"
+## entry is empty.
+
+# RUN: yaml2obj --docnum=12 %s -o %t12.o
+# RUN: llvm-readobj --sections --section-data %t12.o | \
+# RUN: FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=DWARF-HEADER,EMPTY-CONTENT
+
+# EMPTY-CONTENT-NEXT: SectionData (
+# EMPTY-CONTENT-NEXT: )
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+DWARF:
+ debug_aranges: []
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 66264a46068a..4c1742cf922b 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -64,7 +64,7 @@ Error dumpDebugARanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
DCtx.isLittleEndian(), 0);
uint64_t Offset = 0;
DWARFDebugArangeSet Set;
-
+ std::vector<DWARFYAML::ARange> DebugAranges;
while (ArangesData.isValidOffset(Offset)) {
if (Error E = Set.extract(ArangesData, &Offset))
return E;
@@ -81,8 +81,10 @@ Error dumpDebugARanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
Desc.Length = Descriptor.Length;
Range.Descriptors.push_back(Desc);
}
- Y.ARanges.push_back(Range);
+ DebugAranges.push_back(Range);
}
+
+ Y.DebugAranges = DebugAranges;
return ErrorSuccess();
}
More information about the llvm-commits
mailing list