diff options
Diffstat (limited to 'llvm/tools/obj2yaml/elf2yaml.cpp')
-rw-r--r-- | llvm/tools/obj2yaml/elf2yaml.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index 13469804b98..15c38c630b9 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -60,6 +60,8 @@ class ELFDumper { ELFYAML::Relocation &R); Expected<ELFYAML::AddrsigSection *> dumpAddrsigSection(const Elf_Shdr *Shdr); + Expected<ELFYAML::LinkerOptionsSection *> + dumpLinkerOptionsSection(const Elf_Shdr *Shdr); Expected<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RawContentSection *> @@ -315,6 +317,14 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() { Y->Chunks.emplace_back(*SecOrErr); break; } + case ELF::SHT_LLVM_LINKER_OPTIONS: { + Expected<ELFYAML::LinkerOptionsSection *> SecOrErr = + dumpLinkerOptionsSection(&Sec); + if (!SecOrErr) + return SecOrErr.takeError(); + Y->Chunks.emplace_back(*SecOrErr); + break; + } case ELF::SHT_NULL: { // We only dump the SHT_NULL section at index 0 when it // has at least one non-null field, because yaml2obj @@ -589,6 +599,37 @@ ELFDumper<ELFT>::dumpAddrsigSection(const Elf_Shdr *Shdr) { } template <class ELFT> +Expected<ELFYAML::LinkerOptionsSection *> +ELFDumper<ELFT>::dumpLinkerOptionsSection(const Elf_Shdr *Shdr) { + auto S = std::make_unique<ELFYAML::LinkerOptionsSection>(); + if (Error E = dumpCommonSection(Shdr, *S)) + return std::move(E); + + auto ContentOrErr = Obj.getSectionContents(Shdr); + if (!ContentOrErr) + return ContentOrErr.takeError(); + + ArrayRef<uint8_t> Content = *ContentOrErr; + if (Content.empty() || Content.back() != 0) { + S->Content = Content; + return S.release(); + } + + SmallVector<StringRef, 16> Strings; + toStringRef(Content.drop_back()).split(Strings, '\0'); + if (Strings.size() % 2 != 0) { + S->Content = Content; + return S.release(); + } + + S->Options.emplace(); + for (size_t I = 0, E = Strings.size(); I != E; I += 2) + S->Options->push_back({Strings[I], Strings[I + 1]}); + + return S.release(); +} + +template <class ELFT> Expected<ELFYAML::DynamicSection *> ELFDumper<ELFT>::dumpDynamicSection(const Elf_Shdr *Shdr) { auto S = std::make_unique<ELFYAML::DynamicSection>(); |