summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ObjectYAML/ELFYAML.h12
-rw-r--r--llvm/lib/ObjectYAML/ELFEmitter.cpp40
-rw-r--r--llvm/lib/ObjectYAML/ELFYAML.cpp17
-rw-r--r--llvm/tools/obj2yaml/elf2yaml.cpp33
4 files changed, 95 insertions, 7 deletions
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index c9f14589906..f87135e6a1b 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -138,6 +138,7 @@ struct Chunk {
Group,
RawContent,
Relocation,
+ Relr,
NoBits,
Note,
Hash,
@@ -440,6 +441,17 @@ struct RelocationSection : Section {
}
};
+struct RelrSection : Section {
+ Optional<std::vector<llvm::yaml::Hex64>> Entries;
+ Optional<yaml::BinaryRef> Content;
+
+ RelrSection() : Section(ChunkKind::Relr) {}
+
+ static bool classof(const Chunk *S) {
+ return S->Kind == ChunkKind::Relr;
+ }
+};
+
struct SymtabShndxSection : Section {
std::vector<uint32_t> Entries;
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 69f5510fc7f..ee7d5f616a7 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -110,6 +110,7 @@ template <class ELFT> class ELFState {
typedef typename ELFT::Rela Elf_Rela;
typedef typename ELFT::Relr Elf_Relr;
typedef typename ELFT::Dyn Elf_Dyn;
+ typedef typename ELFT::uint uintX_t;
enum class SymtabType { Static, Dynamic };
@@ -165,6 +166,9 @@ template <class ELFT> class ELFState {
void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RelocationSection &Section,
ContiguousBlobAccumulator &CBA);
+ void writeSectionContent(Elf_Shdr &SHeader,
+ const ELFYAML::RelrSection &Section,
+ ContiguousBlobAccumulator &CBA);
void writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
ContiguousBlobAccumulator &CBA);
void writeSectionContent(Elf_Shdr &SHeader,
@@ -454,6 +458,8 @@ void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
writeSectionContent(SHeader, *S, CBA);
+ } else if (auto S = dyn_cast<ELFYAML::RelrSection>(Sec)) {
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::Group>(Sec)) {
writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec)) {
@@ -770,10 +776,6 @@ void ELFState<ELFT>::writeSectionContent(
if (Section.EntSize)
SHeader.sh_entsize = *Section.EntSize;
- else if (Section.Type == llvm::ELF::SHT_RELR)
- SHeader.sh_entsize = sizeof(Elf_Relr);
- else
- SHeader.sh_entsize = 0;
if (Section.Info)
SHeader.sh_info = *Section.Info;
@@ -828,6 +830,33 @@ void ELFState<ELFT>::writeSectionContent(
}
template <class ELFT>
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+ const ELFYAML::RelrSection &Section,
+ ContiguousBlobAccumulator &CBA) {
+ raw_ostream &OS =
+ CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
+ SHeader.sh_entsize =
+ Section.EntSize ? uint64_t(*Section.EntSize) : sizeof(Elf_Relr);
+
+ if (Section.Content) {
+ SHeader.sh_size = writeContent(OS, Section.Content, None);
+ return;
+ }
+
+ if (!Section.Entries)
+ return;
+
+ for (llvm::yaml::Hex64 E : *Section.Entries) {
+ if (!ELFT::Is64Bits && E > UINT32_MAX)
+ reportError(Section.Name + ": the value is too large for 32-bits: 0x" +
+ Twine::utohexstr(E));
+ support::endian::write<uintX_t>(OS, E, ELFT::TargetEndianness);
+ }
+
+ SHeader.sh_size = sizeof(uintX_t) * Section.Entries->size();
+}
+
+template <class ELFT>
void ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::SymtabShndxSection &Shndx,
ContiguousBlobAccumulator &CBA) {
@@ -889,7 +918,6 @@ template <class ELFT>
void ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::StackSizesSection &Section,
ContiguousBlobAccumulator &CBA) {
- using uintX_t = typename ELFT::uint;
raw_ostream &OS =
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
@@ -1115,8 +1143,6 @@ template <class ELFT>
void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::DynamicSection &Section,
ContiguousBlobAccumulator &CBA) {
- typedef typename ELFT::uint uintX_t;
-
assert(Section.Type == llvm::ELF::SHT_DYNAMIC &&
"Section type is not SHT_DYNAMIC");
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 21ae85022c2..efa7ecb4728 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1101,6 +1101,12 @@ static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
IO.mapOptional("Relocations", Section.Relocations);
}
+static void sectionMapping(IO &IO, ELFYAML::RelrSection &Section) {
+ commonSectionMapping(IO, Section);
+ IO.mapOptional("Entries", Section.Entries);
+ IO.mapOptional("Content", Section.Content);
+}
+
static void groupSectionMapping(IO &IO, ELFYAML::Group &Group) {
commonSectionMapping(IO, Group);
IO.mapOptional("Info", Group.Signature);
@@ -1200,6 +1206,11 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
Section.reset(new ELFYAML::RelocationSection());
sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
break;
+ case ELF::SHT_RELR:
+ if (!IO.outputting())
+ Section.reset(new ELFYAML::RelrSection());
+ sectionMapping(IO, *cast<ELFYAML::RelrSection>(Section.get()));
+ break;
case ELF::SHT_GROUP:
if (!IO.outputting())
Section.reset(new ELFYAML::Group());
@@ -1441,6 +1452,12 @@ StringRef MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::validate(
return {};
}
+ if (const auto *RS = dyn_cast<ELFYAML::RelrSection>(C.get())) {
+ if (RS->Entries && RS->Content)
+ return "\"Entries\" and \"Content\" can't be used together";
+ return {};
+ }
+
return {};
}
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>();
OpenPOWER on IntegriCloud