[llvm] 428b2ff - [DWARFYAML] Make the debug_str section optional.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 19:04:26 PDT 2020
Author: Xing GUO
Date: 2020-09-01T10:02:09+08:00
New Revision: 428b2ffad4a346a967a4a105356fbc0fa518e2cc
URL: https://github.com/llvm/llvm-project/commit/428b2ffad4a346a967a4a105356fbc0fa518e2cc
DIFF: https://github.com/llvm/llvm-project/commit/428b2ffad4a346a967a4a105356fbc0fa518e2cc.diff
LOG: [DWARFYAML] Make the debug_str section optional.
This patch makes the debug_str section optional. When the debug_str
section exists but doesn't contain anything, yaml2obj will emit a
section header for it.
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D86860
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-str.yaml
llvm/tools/obj2yaml/dwarf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index d1bfb3e6c657..19b7f3500ee6 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -211,7 +211,7 @@ struct Data {
bool IsLittleEndian;
bool Is64BitAddrSize;
std::vector<AbbrevTable> DebugAbbrev;
- std::vector<StringRef> DebugStrings;
+ Optional<std::vector<StringRef>> DebugStrings;
Optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
Optional<std::vector<ARange>> DebugAranges;
std::vector<Ranges> DebugRanges;
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 8375efe66abc..a0a445ae0c9d 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -86,7 +86,7 @@ static void writeDWARFOffset(uint64_t Offset, dwarf::DwarfFormat Format,
}
Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
- for (auto Str : DI.DebugStrings) {
+ for (StringRef Str : *DI.DebugStrings) {
OS.write(Str.data(), Str.size());
OS.write('\0');
}
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 25ddf6b988b5..046dddbf9a39 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -24,7 +24,7 @@ bool DWARFYAML::Data::isEmpty() const {
SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
SetVector<StringRef> SecNames;
- if (!DebugStrings.empty())
+ if (DebugStrings)
SecNames.insert("debug_str");
if (DebugAranges)
SecNames.insert("debug_aranges");
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml
index 40890349f5c6..29247b334a1a 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml
@@ -1,4 +1,6 @@
-# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+## a) Test that obj2yaml is able to dump the __debug_str section.
+
+# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s
--- !mach-o
FileHeader:
@@ -252,3 +254,70 @@ DWARF:
#CHECK: - int
#CHECK: - char
+## b) Test dumping an empty __debug_str section.
+
+# RUN: yaml2obj --docnum=2 -DCONTENT='[]' %s | obj2yaml | FileCheck %s --check-prefix=EMPTY-CONTENT
+
+# EMPTY-CONTENT: Sections:
+# EMPTY-CONTENT-NEXT: - sectname: __debug_str
+# EMPTY-CONTENT-NEXT: segname: __DWARF
+# EMPTY-CONTENT-NEXT: addr: 0x0000000000000000
+# EMPTY-CONTENT-NEXT: size: 0
+# EMPTY-CONTENT-NEXT: offset: 0x00000210
+# EMPTY-CONTENT-NEXT: align: 0
+# EMPTY-CONTENT-NEXT: reloff: 0x00000000
+# EMPTY-CONTENT-NEXT: nreloc: 0
+# EMPTY-CONTENT-NEXT: flags: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved1: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved2: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved3: 0x00000000
+# EMPTY-CONTENT-NEXT: DWARF:
+# EMPTY-CONTENT-NEXT: debug_str: []
+
+--- !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_str
+ segname: __DWARF
+ addr: 0x00
+ size: [[SIZE=0]]
+ offset: 0x210
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+DWARF:
+ debug_str:
+ [[CONTENT]]
+
+## c) Test generating and dumping a __debug_str section who only has an empty string.
+
+# RUN: yaml2obj --docnum=2 -DCONTENT='[ "" ]' -DSIZE=1 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY-STRING
+
+# EMPTY-STRING: DWARF:
+# EMPTY-STRING-NEXT: debug_str:
+# EMPTY-STRING-NEXT: - ''
+# EMPTY-STRING-NEXT: ...
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-str.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-str.yaml
index c263563d3d9e..27d0aa640e02 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-str.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-str.yaml
@@ -13,10 +13,10 @@
## Check the default sh_type, sh_entsize, sh_info, sh_flags and sh_addralign of the
## .debug_str section header.
-# RUN: llvm-readelf -S %t1.o | FileCheck %s --check-prefix=SHDRS-DEFAULT
+# RUN: llvm-readelf -S %t1.o | FileCheck -DSIZE=000006 %s --check-prefix=SHDRS-DEFAULT
-# SHDRS-DEFAULT: Name Type Address Off Size ES Flg Lk Inf Al
-# SHDRS-DEFAULT: .debug_str PROGBITS 0000000000000000 000040 000006 01 MS 0 0 1
+# SHDRS-DEFAULT: Name Type Address Off Size ES Flg Lk Inf Al
+# SHDRS-DEFAULT: .debug_str PROGBITS 0000000000000000 000040 [[SIZE]] 01 MS 0 0 1
--- !ELF
FileHeader:
@@ -213,3 +213,17 @@ Sections:
DWARF:
debug_str:
- a
+
+## i) Test that the .debug_str section header is emitted if the "debug_str"
+## entry is empty.
+
+# RUN: yaml2obj --docnum=10 %s -o %t10.o
+# RUN: llvm-readelf -S %t10.o | FileCheck -DSIZE=000000 %s --check-prefix=SHDRS-DEFAULT
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+DWARF:
+ debug_str: []
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index 13e502dc73ad..513fa0fdef01 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -48,10 +48,11 @@ void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) {
void dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) {
StringRef RemainingTable = DCtx.getDWARFObj().getStrSection();
+ Y.DebugStrings.emplace();
while (RemainingTable.size() > 0) {
auto SymbolPair = RemainingTable.split('\0');
RemainingTable = SymbolPair.second;
- Y.DebugStrings.push_back(SymbolPair.first);
+ Y.DebugStrings->push_back(SymbolPair.first);
}
}
More information about the llvm-commits
mailing list