From: George Rimar Date: Wed, 24 Apr 2019 15:03:53 +0000 (+0000) Subject: [obj2yamp] - Simplify and cleanup the code in ELFDumper::dumpGroup a bit. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=893591a76ebc8ea33b8b2400c0096bd9814c605b;p=llvm [obj2yamp] - Simplify and cleanup the code in ELFDumper::dumpGroup a bit. NFC. This makes the variables naming to match LLVM style, simplifies the code used to extract the group members, simplifies the loop and reorders the code around a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359101 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 17f23d5afd9..eee09369dc9 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -585,46 +585,44 @@ ELFDumper::dumpVerneedSection(const Elf_Shdr *Shdr) { template ErrorOr ELFDumper::dumpGroup(const Elf_Shdr *Shdr) { auto S = make_unique(); - if (std::error_code EC = dumpCommonSection(Shdr, *S)) return EC; - // Get sh_info which is the signature. + auto SymtabOrErr = Obj.getSection(Shdr->sh_link); if (!SymtabOrErr) return errorToErrorCode(SymtabOrErr.takeError()); + // Get symbol with index sh_info which name is the signature of the group. const Elf_Shdr *Symtab = *SymtabOrErr; auto SymOrErr = Obj.getSymbol(Symtab, Shdr->sh_info); if (!SymOrErr) return errorToErrorCode(SymOrErr.takeError()); - const Elf_Sym *symbol = *SymOrErr; auto StrTabOrErr = Obj.getStringTableForSymtab(*Symtab); if (!StrTabOrErr) return errorToErrorCode(StrTabOrErr.takeError()); - StringRef StrTab = *StrTabOrErr; - auto sectionContents = Obj.getSectionContents(Shdr); - if (!sectionContents) - return errorToErrorCode(sectionContents.takeError()); - Expected symbolName = getSymbolName(symbol, StrTab, Symtab); - if (!symbolName) - return errorToErrorCode(symbolName.takeError()); - S->Signature = *symbolName; - const Elf_Word *groupMembers = - reinterpret_cast(sectionContents->data()); - const long count = (Shdr->sh_size) / sizeof(Elf_Word); - ELFYAML::SectionOrType s; - for (int i = 0; i < count; i++) { - if (groupMembers[i] == llvm::ELF::GRP_COMDAT) { - s.sectionNameOrType = "GRP_COMDAT"; - } else { - auto sHdr = Obj.getSection(groupMembers[i]); - if (!sHdr) - return errorToErrorCode(sHdr.takeError()); - auto sectionName = getUniquedSectionName(*sHdr); - if (!sectionName) - return errorToErrorCode(sectionName.takeError()); - s.sectionNameOrType = *sectionName; + + Expected SymbolName = + getSymbolName(*SymOrErr, *StrTabOrErr, Symtab); + if (!SymbolName) + return errorToErrorCode(SymbolName.takeError()); + S->Signature = *SymbolName; + + auto MembersOrErr = Obj.template getSectionContentsAsArray(Shdr); + if (!MembersOrErr) + return errorToErrorCode(MembersOrErr.takeError()); + + for (Elf_Word Member : *MembersOrErr) { + if (Member == llvm::ELF::GRP_COMDAT) { + S->Members.push_back({"GRP_COMDAT"}); + continue; } - S->Members.push_back(s); + + auto SHdrOrErr = Obj.getSection(Member); + if (!SHdrOrErr) + return errorToErrorCode(SHdrOrErr.takeError()); + auto NameOrErr = getUniquedSectionName(*SHdrOrErr); + if (!NameOrErr) + return errorToErrorCode(NameOrErr.takeError()); + S->Members.push_back({*NameOrErr}); } return S.release(); }