summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorXing GUO <higuoxing@gmail.com>2018-12-04 14:27:51 +0000
committerXing GUO <higuoxing@gmail.com>2018-12-04 14:27:51 +0000
commit98228351821bb2a8348fa349ecb2dabcd65d5b38 (patch)
tree7838d2e46e5faaa357ac8fff438d45bdc8f0f198 /llvm/tools
parenta2eebb828e02be7ca8e0c1c53e1ad6548aa1049f (diff)
downloadbcm5719-llvm-98228351821bb2a8348fa349ecb2dabcd65d5b38.tar.gz
bcm5719-llvm-98228351821bb2a8348fa349ecb2dabcd65d5b38.zip
[yaml2obj] Move redundant statements into a separate static function
Reviewers: jhenderson, grimar Reviewed By: jhenderson Subscribers: jakehehrlich, llvm-commits Differential Revision: https://reviews.llvm.org/D55220 llvm-svn: 348264
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index 28ffa885080..bd4c1c3e998 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -226,6 +226,16 @@ void ELFState<ELFT>::initProgramHeaders(std::vector<Elf_Phdr> &PHeaders) {
}
}
+static bool convertSectionIndex(NameToIdxMap &SN2I, StringRef SecName,
+ StringRef IndexSrc, unsigned &IndexDest) {
+ if (SN2I.lookup(IndexSrc, IndexDest) && !to_integer(IndexSrc, IndexDest)) {
+ WithColor::error() << "Unknown section referenced: '" << IndexSrc
+ << "' at YAML section '" << SecName << "'.\n";
+ return false;
+ }
+ return true;
+}
+
template <class ELFT>
bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
ContiguousBlobAccumulator &CBA) {
@@ -245,11 +255,8 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
if (!Sec->Link.empty()) {
unsigned Index;
- if (SN2I.lookup(Sec->Link, Index) && !to_integer(Sec->Link, Index)) {
- WithColor::error() << "Unknown section referenced: '" << Sec->Link
- << "' at YAML section '" << Sec->Name << "'.\n";
+ if (!convertSectionIndex(SN2I, Sec->Name, Sec->Link, Index))
return false;
- }
SHeader.sh_link = Index;
}
@@ -261,13 +268,9 @@ bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
SHeader.sh_link = getDotSymTabSecNo();
unsigned Index;
- if (SN2I.lookup(S->Info, Index) && !to_integer(S->Info, Index)) {
- WithColor::error() << "Unknown section referenced: '" << S->Info
- << "' at YAML section '" << S->Name << "'.\n";
+ if (!convertSectionIndex(SN2I, S->Name, S->Info, Index))
return false;
- }
SHeader.sh_info = Index;
-
if (!writeSectionContent(SHeader, *S, CBA))
return false;
} else if (auto S = dyn_cast<ELFYAML::Group>(Sec.get())) {
@@ -535,13 +538,9 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
unsigned int sectionIndex = 0;
if (member.sectionNameOrType == "GRP_COMDAT")
sectionIndex = llvm::ELF::GRP_COMDAT;
- else if (SN2I.lookup(member.sectionNameOrType, sectionIndex) &&
- !to_integer(member.sectionNameOrType, sectionIndex)) {
- WithColor::error() << "Unknown section referenced: '"
- << member.sectionNameOrType << "' at YAML section' "
- << Section.Name << "\n";
+ else if (!convertSectionIndex(SN2I, Section.Name, member.sectionNameOrType,
+ sectionIndex))
return false;
- }
SIdx = sectionIndex;
OS.write((const char *)&SIdx, sizeof(SIdx));
}
OpenPOWER on IntegriCloud