llvm.org GIT mirror llvm / 53a9c2e
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348264 91177308-0d34-0410-b5e6-96231b3b80d8 Xing GUO 9 months ago
1 changed file(s) with 14 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
225225 }
226226 }
227227
228 static bool convertSectionIndex(NameToIdxMap &SN2I, StringRef SecName,
229 StringRef IndexSrc, unsigned &IndexDest) {
230 if (SN2I.lookup(IndexSrc, IndexDest) && !to_integer(IndexSrc, IndexDest)) {
231 WithColor::error() << "Unknown section referenced: '" << IndexSrc
232 << "' at YAML section '" << SecName << "'.\n";
233 return false;
234 }
235 return true;
236 }
237
228238 template
229239 bool ELFState::initSectionHeaders(std::vector &SHeaders,
230240 ContiguousBlobAccumulator &CBA) {
244254
245255 if (!Sec->Link.empty()) {
246256 unsigned Index;
247 if (SN2I.lookup(Sec->Link, Index) && !to_integer(Sec->Link, Index)) {
248 WithColor::error() << "Unknown section referenced: '" << Sec->Link
249 << "' at YAML section '" << Sec->Name << "'.\n";
257 if (!convertSectionIndex(SN2I, Sec->Name, Sec->Link, Index))
250258 return false;
251 }
252259 SHeader.sh_link = Index;
253260 }
254261
260267 SHeader.sh_link = getDotSymTabSecNo();
261268
262269 unsigned Index;
263 if (SN2I.lookup(S->Info, Index) && !to_integer(S->Info, Index)) {
264 WithColor::error() << "Unknown section referenced: '" << S->Info
265 << "' at YAML section '" << S->Name << "'.\n";
270 if (!convertSectionIndex(SN2I, S->Name, S->Info, Index))
266271 return false;
267 }
268272 SHeader.sh_info = Index;
269
270273 if (!writeSectionContent(SHeader, *S, CBA))
271274 return false;
272275 } else if (auto S = dyn_cast(Sec.get())) {
534537 unsigned int sectionIndex = 0;
535538 if (member.sectionNameOrType == "GRP_COMDAT")
536539 sectionIndex = llvm::ELF::GRP_COMDAT;
537 else if (SN2I.lookup(member.sectionNameOrType, sectionIndex) &&
538 !to_integer(member.sectionNameOrType, sectionIndex)) {
539 WithColor::error() << "Unknown section referenced: '"
540 << member.sectionNameOrType << "' at YAML section' "
541 << Section.Name << "\n";
540 else if (!convertSectionIndex(SN2I, Section.Name, member.sectionNameOrType,
541 sectionIndex))
542542 return false;
543 }
544543 SIdx = sectionIndex;
545544 OS.write((const char *)&SIdx, sizeof(SIdx));
546545 }