summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML/ELFEmitter.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-08 09:49:05 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-08 09:49:05 +0000
commitd3963051c49037b1ce6edace90f59056d3bddffa (patch)
treed9ac3df45a3acaffb0611b8ce714efe2d7d7eaba /llvm/lib/ObjectYAML/ELFEmitter.cpp
parent6db975b7b89df9d4b27fa40411963f8f8891c349 (diff)
downloadbcm5719-llvm-d3963051c49037b1ce6edace90f59056d3bddffa.tar.gz
bcm5719-llvm-d3963051c49037b1ce6edace90f59056d3bddffa.zip
[yaml2obj/obj2yaml] - Add a basic support for extended section indexes.
In some cases a symbol might have section index == SHN_XINDEX. This is an escape value indicating that the actual section header index is too large to fit in the containing field. Then the SHT_SYMTAB_SHNDX section is used. It contains the 32bit values that stores section indexes. ELF gABI says that there can be multiple SHT_SYMTAB_SHNDX sections, i.e. for example one for .symtab and one for .dynsym (1) https://groups.google.com/forum/#!topic/generic-abi/-XJAV5d8PRg (2) DT_SYMTAB_SHNDX: http://www.sco.com/developers/gabi/latest/ch5.dynamic.html In this patch I am only supporting a single SHT_SYMTAB_SHNDX associated with a .symtab. This is a more or less common case which is used a few tests I saw in LLVM. I decided not to create the SHT_SYMTAB_SHNDX section as "implicit", but implement is like a kind of regular section for now. i.e. tools do not recreate this section or its content, like they do for symbol table sections, for example. That should allow to write all kind of possible broken test cases for our needs and keep the output closer to requested. Differential revision: https://reviews.llvm.org/D65446 llvm-svn: 368272
Diffstat (limited to 'llvm/lib/ObjectYAML/ELFEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/ELFEmitter.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 370d62088a4..d2ceb40e2c1 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -141,6 +141,9 @@ template <class ELFT> class ELFState {
bool writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
ContiguousBlobAccumulator &CBA);
bool writeSectionContent(Elf_Shdr &SHeader,
+ const ELFYAML::SymtabShndxSection &Shndx,
+ ContiguousBlobAccumulator &CBA);
+ bool writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::SymverSection &Section,
ContiguousBlobAccumulator &CBA);
bool writeSectionContent(Elf_Shdr &SHeader,
@@ -358,6 +361,9 @@ bool ELFState<ELFT>::initSectionHeaders(ELFState<ELFT> &State,
} else if (auto S = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
if (!writeSectionContent(SHeader, *S, CBA))
return false;
+ } else if (auto S = dyn_cast<ELFYAML::SymtabShndxSection>(Sec)) {
+ if (!writeSectionContent(SHeader, *S, CBA))
+ return false;
} else if (auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
if (!writeSectionContent(SHeader, *S, CBA))
return false;
@@ -741,6 +747,21 @@ bool ELFState<ELFT>::writeSectionContent(
}
template <class ELFT>
+bool ELFState<ELFT>::writeSectionContent(
+ Elf_Shdr &SHeader, const ELFYAML::SymtabShndxSection &Shndx,
+ ContiguousBlobAccumulator &CBA) {
+ raw_ostream &OS =
+ CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
+
+ for (uint32_t E : Shndx.Entries)
+ support::endian::write<uint32_t>(OS, E, ELFT::TargetEndianness);
+
+ SHeader.sh_entsize = Shndx.EntSize ? (uint64_t)*Shndx.EntSize : 4;
+ SHeader.sh_size = Shndx.Entries.size() * SHeader.sh_entsize;
+ return true;
+}
+
+template <class ELFT>
bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::Group &Section,
ContiguousBlobAccumulator &CBA) {
OpenPOWER on IntegriCloud