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 @@ -171,6 +171,7 @@ std::vector DebugLines; bool isEmpty() const; + std::vector getNonEmptySectionNames() const; }; } // end namespace DWARFYAML diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h --- a/llvm/include/llvm/ObjectYAML/ELFYAML.h +++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -16,6 +16,7 @@ #define LLVM_OBJECTYAML_ELFYAML_H #include "llvm/ADT/StringRef.h" +#include "llvm/ObjectYAML/DWARFYAML.h" #include "llvm/ObjectYAML/YAML.h" #include "llvm/Support/YAMLTraits.h" #include @@ -521,6 +522,7 @@ // being a single SHT_SYMTAB section are upheld. Optional> Symbols; Optional> DynamicSymbols; + Optional DWARF; std::vector
getSections() { std::vector
Ret; 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 @@ -23,6 +23,32 @@ DebugLines.size(); } +std::vector DWARFYAML::Data::getNonEmptySectionNames() const { + std::vector SecNames; + if (DebugStrings.size() != 0) + SecNames.push_back("debug_str"); + if (AbbrevDecls.size() != 0) + SecNames.push_back("debug_abbrev"); + if (ARanges.size() != 0) + SecNames.push_back("debug_aranges"); + if (DebugRanges.size() != 0) + SecNames.push_back("debug_ranges"); + if (PubNames.Entries.size() != 0) + SecNames.push_back("debug_pubnames"); + if (PubTypes.Entries.size() != 0) + SecNames.push_back("debug_pubtypes"); + if (GNUPubNames.Entries.size() != 0) + SecNames.push_back("debug_gnu_pubnames"); + if (GNUPubTypes.Entries.size() != 0) + SecNames.push_back("debug_gnu_pubtypes"); + if (CompileUnits.size() != 0) + SecNames.push_back("debug_info"); + if (DebugLines.size() != 0) + SecNames.push_back("debug_line"); + + return SecNames; +} + namespace yaml { void MappingTraits::mapping(IO &IO, DWARFYAML::Data &DWARF) { 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 @@ -258,8 +258,10 @@ ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"}); if (Doc.Symbols) ImplicitSections.push_back(".symtab"); + if (Doc.DWARF) + for (auto DebugSecName : Doc.DWARF->getNonEmptySectionNames()) + ImplicitSections.push_back("." + DebugSecName); ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"}); - // Insert placeholders for implicit sections that are not // defined explicitly in YAML. for (StringRef SecName : ImplicitSections) { @@ -391,6 +393,8 @@ initSymtabSectionHeader(Header, SymtabType::Dynamic, CBA, YAMLSec); else if (SecName == ".dynstr") initStrtabSectionHeader(Header, SecName, DotDynstr, CBA, YAMLSec); + else if (SecName.startswith(".debug_") && !YAMLSec) + reportError(SecName + " section is not implemented"); else return false; diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1637,6 +1637,7 @@ IO.mapOptional("Sections", Object.Chunks); IO.mapOptional("Symbols", Object.Symbols); IO.mapOptional("DynamicSymbols", Object.DynamicSymbols); + IO.mapOptional("DWARF", Object.DWARF); IO.setContext(nullptr); } diff --git a/llvm/test/tools/yaml2obj/ELF/unimplemented-debug-sections.test b/llvm/test/tools/yaml2obj/ELF/unimplemented-debug-sections.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/yaml2obj/ELF/unimplemented-debug-sections.test @@ -0,0 +1,155 @@ +## This file contains tests for unimplemented debug sections. + +# RUN: not yaml2obj --docnum=1 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_abbrev" %s + +# CHECK: yaml2obj: error: [[SECTION]] section is not implemented + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_abbrev: + - Code: 0x00000001 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_producer + Form: DW_FORM_strp +... + +# RUN: not yaml2obj --docnum=2 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_aranges" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_aranges: + - Length: + TotalLength: 0x0 + Version: 0 + CuOffset: 0x0 + AddrSize: 0x0 + SegSize: 0x0 + Descriptors: + - Address: 0x0 + Length: 0x0 +... + +# RUN: not yaml2obj --docnum=3 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_ranges" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_ranges: + - Offset: 0x0 + AddrSize: 0x0 + Entries: + - LowOffset: 0x0 + HighOffset: 0x0 +... + +# RUN: not yaml2obj --docnum=4 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_pubnames" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_pubnames: + Length: + TotalLength: 0x0 + Version: 0 + UnitOffset: 0x0 + UnitSize: 0x0 + Entries: + - DieOffset: 0x0 + Name: '' +... + +# RUN: not yaml2obj --docnum=5 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_pubtypes" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_pubtypes: + Length: + TotalLength: 0x0 + Version: 0 + UnitOffset: 0x0 + UnitSize: 0x0 + Entries: + - DieOffset: 0x0 + Name: int +... + +# RUN: not yaml2obj --docnum=6 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_info" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_info: + - Length: + TotalLength: 0x0 + Version: 0 + AbbrOffset: 0x0 + AddrSize: 0x0 + Entries: +... + +# RUN: not yaml2obj --docnum=7 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_str" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_str: + - '' +... + +# RUN: not yaml2obj --docnum=8 %s -o %t.o 2>&1 | FileCheck -DSECTION=".debug_line" %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +DWARF: + debug_line: + - Length: + TotalLength: 0x0 + Version: 0 + PrologueLength: 0 + MinInstLength: 0 + DefaultIsStmt: 0 + LineBase: 0 + LineRange: 0 + OpcodeBase: 0 + StandardOpcodeLengths: [] + IncludeDirs: [] + Files: [] + Opcodes: [] +...