summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-04-26 12:15:32 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-04-26 12:15:32 +0000
commitda1b3abad6bba11fffe6a9e3bddaf70342f60199 (patch)
tree85c206b04a6c852ddf1ccca45b6907dee3cb54cb /llvm/tools
parentbb230c5e794623367fde6137237367a1f35481d2 (diff)
downloadbcm5719-llvm-da1b3abad6bba11fffe6a9e3bddaf70342f60199.tar.gz
bcm5719-llvm-da1b3abad6bba11fffe6a9e3bddaf70342f60199.zip
[yaml2elf] - Cleanup the initSectionHeaders(). NFCI.
This encapsulates the section specific code inside the corresponding writeSectionContent methods. Making the code a bit more consistent. llvm-svn: 359297
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp141
1 files changed, 74 insertions, 67 deletions
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 974acbd40c9..96761259c4e 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -147,7 +147,7 @@ class ELFState {
std::vector<Elf_Shdr> &SHeaders);
void addSymbols(ArrayRef<ELFYAML::Symbol> Symbols, std::vector<Elf_Sym> &Syms,
const StringTableBuilder &Strtab);
- void writeSectionContent(Elf_Shdr &SHeader,
+ bool writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RawContentSection &Section,
ContiguousBlobAccumulator &CBA);
bool writeSectionContent(Elf_Shdr &SHeader,
@@ -271,29 +271,13 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
SHeader.sh_link = Index;
}
- if (auto S = dyn_cast<ELFYAML::RawContentSection>(Sec.get()))
- writeSectionContent(SHeader, *S, CBA);
- else if (auto S = dyn_cast<ELFYAML::RelocationSection>(Sec.get())) {
- if (S->Link.empty())
- // For relocation section set link to .symtab by default.
- SHeader.sh_link = getDotSymTabSecNo();
-
- unsigned Index = 0;
- if (!S->RelocatableSec.empty() &&
- !convertSectionIndex(SN2I, S->Name, S->RelocatableSec, Index))
+ if (auto S = dyn_cast<ELFYAML::RawContentSection>(Sec.get())) {
+ if (!writeSectionContent(SHeader, *S, CBA))
return false;
- SHeader.sh_info = Index;
+ } else if (auto S = dyn_cast<ELFYAML::RelocationSection>(Sec.get())) {
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::Group>(Sec.get())) {
- unsigned SymIdx;
- if (SymN2I.lookup(S->Signature, SymIdx) &&
- !to_integer(S->Signature, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << S->Signature
- << "' at YAML section '" << S->Name << "'.\n";
- return false;
- }
- SHeader.sh_info = SymIdx;
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec.get())) {
@@ -309,11 +293,14 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::SymverSection>(Sec.get())) {
- writeSectionContent(SHeader, *S, CBA);
+ if (!writeSectionContent(SHeader, *S, CBA))
+ return false;
} else if (auto S = dyn_cast<ELFYAML::VerneedSection>(Sec.get())) {
- writeSectionContent(SHeader, *S, CBA);
+ if (!writeSectionContent(SHeader, *S, CBA))
+ return false;
} else if (auto S = dyn_cast<ELFYAML::VerdefSection>(Sec.get())) {
- writeSectionContent(SHeader, *S, CBA);
+ if (!writeSectionContent(SHeader, *S, CBA))
+ return false;
} else
llvm_unreachable("Unknown section type");
@@ -503,7 +490,7 @@ void ELFState<ELFT>::addSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
}
template <class ELFT>
-void ELFState<ELFT>::writeSectionContent(
+bool ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::RawContentSection &Section,
ContiguousBlobAccumulator &CBA) {
assert(Section.Size >= Section.Content.binary_size() &&
@@ -521,6 +508,7 @@ void ELFState<ELFT>::writeSectionContent(
SHeader.sh_entsize = 0;
SHeader.sh_size = Section.Size;
SHeader.sh_info = Section.Info;
+ return true;
}
static bool isMips64EL(const ELFYAML::Object &Doc) {
@@ -542,6 +530,16 @@ ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
SHeader.sh_size = SHeader.sh_entsize * Section.Relocations.size();
+ // For relocation section set link to .symtab by default.
+ if (Section.Link.empty())
+ SHeader.sh_link = getDotSymTabSecNo();
+
+ unsigned Index = 0;
+ if (!Section.RelocatableSec.empty() &&
+ !convertSectionIndex(SN2I, Section.Name, Section.RelocatableSec, Index))
+ return false;
+ SHeader.sh_info = Index;
+
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
for (const auto &Rel : Section.Relocations) {
@@ -583,6 +581,15 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
SHeader.sh_entsize = 4;
SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
+ unsigned SymIdx;
+ if (SymN2I.lookup(Section.Signature, SymIdx) &&
+ !to_integer(Section.Signature, SymIdx)) {
+ WithColor::error() << "Unknown symbol referenced: '" << Section.Signature
+ << "' at YAML section '" << Section.Name << "'.\n";
+ return false;
+ }
+ SHeader.sh_info = SymIdx;
+
raw_ostream &OS =
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
@@ -661,48 +668,48 @@ template <class ELFT>
bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::VerneedSection &Section,
ContiguousBlobAccumulator &CBA) {
- typedef typename ELFT::Verneed Elf_Verneed;
- typedef typename ELFT::Vernaux Elf_Vernaux;
-
- auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
-
- uint64_t AuxCnt = 0;
- for (size_t I = 0; I < Section.VerneedV.size(); ++I) {
- const ELFYAML::VerneedEntry &VE = Section.VerneedV[I];
-
- Elf_Verneed VerNeed;
- VerNeed.vn_version = VE.Version;
- VerNeed.vn_file = DotDynstr.getOffset(VE.File);
- if (I == Section.VerneedV.size() - 1)
- VerNeed.vn_next = 0;
- else
- VerNeed.vn_next =
- sizeof(Elf_Verneed) + VE.AuxV.size() * sizeof(Elf_Vernaux);
- VerNeed.vn_cnt = VE.AuxV.size();
- VerNeed.vn_aux = sizeof(Elf_Verneed);
- OS.write((const char *)&VerNeed, sizeof(Elf_Verneed));
-
- for (size_t J = 0; J < VE.AuxV.size(); ++J, ++AuxCnt) {
- const ELFYAML::VernauxEntry &VAuxE = VE.AuxV[J];
-
- Elf_Vernaux VernAux;
- VernAux.vna_hash = VAuxE.Hash;
- VernAux.vna_flags = VAuxE.Flags;
- VernAux.vna_other = VAuxE.Other;
- VernAux.vna_name = DotDynstr.getOffset(VAuxE.Name);
- if (J == VE.AuxV.size() - 1)
- VernAux.vna_next = 0;
- else
- VernAux.vna_next = sizeof(Elf_Vernaux);
- OS.write((const char *)&VernAux, sizeof(Elf_Vernaux));
- }
- }
-
- SHeader.sh_size = Section.VerneedV.size() * sizeof(Elf_Verneed) +
- AuxCnt * sizeof(Elf_Vernaux);
- SHeader.sh_info = Section.Info;
-
- return true;
+ typedef typename ELFT::Verneed Elf_Verneed;
+ typedef typename ELFT::Vernaux Elf_Vernaux;
+
+ auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
+
+ uint64_t AuxCnt = 0;
+ for (size_t I = 0; I < Section.VerneedV.size(); ++I) {
+ const ELFYAML::VerneedEntry &VE = Section.VerneedV[I];
+
+ Elf_Verneed VerNeed;
+ VerNeed.vn_version = VE.Version;
+ VerNeed.vn_file = DotDynstr.getOffset(VE.File);
+ if (I == Section.VerneedV.size() - 1)
+ VerNeed.vn_next = 0;
+ else
+ VerNeed.vn_next =
+ sizeof(Elf_Verneed) + VE.AuxV.size() * sizeof(Elf_Vernaux);
+ VerNeed.vn_cnt = VE.AuxV.size();
+ VerNeed.vn_aux = sizeof(Elf_Verneed);
+ OS.write((const char *)&VerNeed, sizeof(Elf_Verneed));
+
+ for (size_t J = 0; J < VE.AuxV.size(); ++J, ++AuxCnt) {
+ const ELFYAML::VernauxEntry &VAuxE = VE.AuxV[J];
+
+ Elf_Vernaux VernAux;
+ VernAux.vna_hash = VAuxE.Hash;
+ VernAux.vna_flags = VAuxE.Flags;
+ VernAux.vna_other = VAuxE.Other;
+ VernAux.vna_name = DotDynstr.getOffset(VAuxE.Name);
+ if (J == VE.AuxV.size() - 1)
+ VernAux.vna_next = 0;
+ else
+ VernAux.vna_next = sizeof(Elf_Vernaux);
+ OS.write((const char *)&VernAux, sizeof(Elf_Vernaux));
+ }
+ }
+
+ SHeader.sh_size = Section.VerneedV.size() * sizeof(Elf_Verneed) +
+ AuxCnt * sizeof(Elf_Vernaux);
+ SHeader.sh_info = Section.Info;
+
+ return true;
}
template <class ELFT>
@@ -883,7 +890,7 @@ int ELFState<ELFT>::writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
std::vector<Elf_Shdr> SHeaders;
- if(!State.initSectionHeaders(SHeaders, CBA))
+ if (!State.initSectionHeaders(SHeaders, CBA))
return 1;
// Populate SHeaders with implicit sections not present in the Doc
OpenPOWER on IntegriCloud