]> granicus.if.org Git - llvm/commitdiff
[obj2yamp] - Simplify and cleanup the code in ELFDumper<ELFT>::dumpGroup a bit. NFC.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 24 Apr 2019 15:03:53 +0000 (15:03 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 24 Apr 2019 15:03:53 +0000 (15:03 +0000)
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

tools/obj2yaml/elf2yaml.cpp

index 17f23d5afd94c3dbb8018a0056e1f7d12ed86bbd..eee09369dc968f33d842dad569209ab4be5aa827 100644 (file)
@@ -585,46 +585,44 @@ ELFDumper<ELFT>::dumpVerneedSection(const Elf_Shdr *Shdr) {
 template <class ELFT>
 ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
   auto S = make_unique<ELFYAML::Group>();
-
   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<StringRef> symbolName = getSymbolName(symbol, StrTab, Symtab);
-  if (!symbolName)
-    return errorToErrorCode(symbolName.takeError());
-  S->Signature = *symbolName;
-  const Elf_Word *groupMembers =
-      reinterpret_cast<const Elf_Word *>(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<StringRef> SymbolName =
+      getSymbolName(*SymOrErr, *StrTabOrErr, Symtab);
+  if (!SymbolName)
+    return errorToErrorCode(SymbolName.takeError());
+  S->Signature = *SymbolName;
+
+  auto MembersOrErr = Obj.template getSectionContentsAsArray<Elf_Word>(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();
 }