summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML/ELFEmitter.cpp
diff options
context:
space:
mode:
authorGeorgii Rymar <grimar@accesssoftek.com>2020-01-15 14:29:29 +0300
committerGeorgii Rymar <grimar@accesssoftek.com>2020-01-15 15:15:24 +0300
commit7570d387c21935b58afa67cb9ee17250e38721fa (patch)
treeb2fe64f4c8b521f34daf7188674286ceef0882ed /llvm/lib/ObjectYAML/ELFEmitter.cpp
parent13f22f5d5958a46db1212a083a426e339204c783 (diff)
downloadbcm5719-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/lib/ObjectYAML/ELFEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/ELFEmitter.cpp40
1 files changed, 33 insertions, 7 deletions
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");
OpenPOWER on IntegriCloud