summaryrefslogtreecommitdiffstats
path: root/llvm/tools/yaml2obj/yaml2elf.cpp
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2015-02-21 04:28:26 +0000
committerShankar Easwaran <shankare@codeaurora.org>2015-02-21 04:28:26 +0000
commit6fbbe201766818c9c682637b931e5e4d50c25a07 (patch)
tree1317d12fca6286233b2c559b2f8e6b1bb7ed59a7 /llvm/tools/yaml2obj/yaml2elf.cpp
parentcf4bdde33a0450f212e7577b71a7bcfe5213cb15 (diff)
downloadbcm5719-llvm-6fbbe201766818c9c682637b931e5e4d50c25a07.tar.gz
bcm5719-llvm-6fbbe201766818c9c682637b931e5e4d50c25a07.zip
[obj2yaml/yaml2obj] Add SHT_GROUP support.
This adds section group support to the tools obj2yaml and yaml2obj. llvm-svn: 230124
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2elf.cpp')
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index c8d4b887576..5d4c26379be 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -131,6 +131,8 @@ class ELFState {
bool writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RelocationSection &Section,
ContiguousBlobAccumulator &CBA);
+ bool writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
+ ContiguousBlobAccumulator &CBA);
// - SHT_NULL entry (placed first, i.e. 0'th entry)
// - symbol table (.symtab) (placed third to last)
@@ -223,6 +225,16 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
if (!writeSectionContent(SHeader, *S, CBA))
return false;
+ } else if (auto S = dyn_cast<ELFYAML::Group>(Sec.get())) {
+ unsigned SymIdx;
+ if (SymN2I.lookup(S->Info, SymIdx)) {
+ errs() << "error: Unknown symbol referenced: '" << S->Info
+ << "' at YAML section '" << S->Name << "'.\n";
+ return false;
+ }
+ SHeader.sh_info = SymIdx;
+ if (!writeSectionContent(SHeader, *S, CBA))
+ return false;
} else
llvm_unreachable("Unknown section type");
@@ -370,6 +382,38 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
return true;
}
+template <class ELFT>
+bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+ const ELFYAML::Group &Section,
+ ContiguousBlobAccumulator &CBA) {
+ typedef typename object::ELFFile<ELFT>::Elf_Word Elf_Word;
+ if (Section.Type != llvm::ELF::SHT_GROUP) {
+ errs() << "error: Invalid section type.\n";
+ return false;
+ }
+
+ SHeader.sh_entsize = sizeof(Elf_Word);
+ SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
+
+ auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
+
+ for (auto member : Section.Members) {
+ Elf_Word SIdx;
+ unsigned int sectionIndex = 0;
+ if (member.sectionNameOrType == "GRP_COMDAT")
+ sectionIndex = llvm::ELF::GRP_COMDAT;
+ else if (SN2I.lookup(member.sectionNameOrType, sectionIndex)) {
+ errs() << "error: Unknown section referenced: '"
+ << member.sectionNameOrType << "' at YAML section' "
+ << Section.Name << "\n";
+ return false;
+ }
+ SIdx = sectionIndex;
+ OS.write((const char *)&SIdx, sizeof(SIdx));
+ }
+ return true;
+}
+
template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
SN2I.addName(".symtab", getDotSymTabSecNo());
SN2I.addName(".strtab", getDotStrTabSecNo());
OpenPOWER on IntegriCloud