diff options
author | Georgii Rymar <grimar@accesssoftek.com> | 2020-01-15 14:29:29 +0300 |
---|---|---|
committer | Georgii Rymar <grimar@accesssoftek.com> | 2020-01-15 15:15:24 +0300 |
commit | 7570d387c21935b58afa67cb9ee17250e38721fa (patch) | |
tree | b2fe64f4c8b521f34daf7188674286ceef0882ed /llvm/tools | |
parent | 13f22f5d5958a46db1212a083a426e339204c783 (diff) | |
download | bcm5719-llvm-7570d387c21935b58afa67cb9ee17250e38721fa.tar.gz bcm5719-llvm-7570d387c21935b58afa67cb9ee17250e38721fa.zip |
[yaml2obj/obj2yaml] - Add support for SHT_RELR sections.
Note: this is a reland with a trivial 2 lines fix in ELFState<ELFT>::writeSectionContent.
It adds a check similar to ones we already have for other sections to fix the case revealed
by bots, like http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/60744.
The encoded sequence of Elf*_Relr entries in a SHT_RELR section looks
like [ AAAAAAAA BBBBBBB1 BBBBBBB1 ... AAAAAAAA BBBBBB1 ... ]
i.e. start with an address, followed by any number of bitmaps. The address
entry encodes 1 relocation. The subsequent bitmap entries encode up to 63(31)
relocations each, at subsequent offsets following the last address entry.
More information is here:
https://github.com/llvm-mirror/llvm/blob/master/lib/Object/ELF.cpp#L272
This patch adds a support for these sections.
Differential revision: https://reviews.llvm.org/D71872
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/obj2yaml/elf2yaml.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index 75d2e427b4f..904d1ad9d0a 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -27,6 +27,7 @@ class ELFDumper { typedef typename ELFT::Word Elf_Word; typedef typename ELFT::Rel Elf_Rel; typedef typename ELFT::Rela Elf_Rela; + using Elf_Relr = typename ELFT::Relr; using Elf_Nhdr = typename ELFT::Nhdr; using Elf_Note = typename ELFT::Note; @@ -66,6 +67,7 @@ class ELFDumper { dumpDependentLibrariesSection(const Elf_Shdr *Shdr); Expected<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr); + Expected<ELFYAML::RelrSection *> dumpRelrSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RawContentSection *> dumpContentSection(const Elf_Shdr *Shdr); Expected<ELFYAML::SymtabShndxSection *> @@ -251,6 +253,13 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() { Y->Chunks.emplace_back(*SecOrErr); break; } + case ELF::SHT_RELR: { + Expected<ELFYAML::RelrSection *> SecOrErr = dumpRelrSection(&Sec); + if (!SecOrErr) + return SecOrErr.takeError(); + Y->Chunks.emplace_back(*SecOrErr); + break; + } case ELF::SHT_GROUP: { Expected<ELFYAML::Group *> GroupOrErr = dumpGroup(&Sec); if (!GroupOrErr) @@ -724,6 +733,30 @@ ELFDumper<ELFT>::dumpRelocSection(const Elf_Shdr *Shdr) { } template <class ELFT> +Expected<ELFYAML::RelrSection *> +ELFDumper<ELFT>::dumpRelrSection(const Elf_Shdr *Shdr) { + auto S = std::make_unique<ELFYAML::RelrSection>(); + if (auto E = dumpCommonSection(Shdr, *S)) + return std::move(E); + + if (Expected<ArrayRef<Elf_Relr>> Relrs = Obj.relrs(Shdr)) { + S->Entries.emplace(); + for (Elf_Relr Rel : *Relrs) + S->Entries->emplace_back(Rel); + return S.release(); + } else { + // Ignore. We are going to dump the data as raw content below. + consumeError(Relrs.takeError()); + } + + Expected<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr); + if (!ContentOrErr) + return ContentOrErr.takeError(); + S->Content = *ContentOrErr; + return S.release(); +} + +template <class ELFT> Expected<ELFYAML::RawContentSection *> ELFDumper<ELFT>::dumpContentSection(const Elf_Shdr *Shdr) { auto S = std::make_unique<ELFYAML::RawContentSection>(); |