[PATCH] D134280: [NFC] refactor XCOFFObjectFile::getImportFileTable.

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 06:16:55 PDT 2022


DiggerLin created this revision.
DiggerLin added reviewers: jhenderson, daltenty, hubert.reinterpretcast, Esme.
Herald added a subscriber: hiraditya.
Herald added a project: All.
DiggerLin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

1.refactor  with XCOFFObjectFile::getImportFileTable with function getSectionFileOffsetToRawData instead of getLoaderSectionAddress

2. delete the function getLoaderSectionAddress.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134280

Files:
  llvm/include/llvm/Object/XCOFFObjectFile.h
  llvm/lib/Object/XCOFFObjectFile.cpp


Index: llvm/lib/Object/XCOFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/XCOFFObjectFile.cpp
+++ llvm/lib/Object/XCOFFObjectFile.cpp
@@ -402,43 +402,6 @@
   return toSection32(Sec)->FileOffsetToRawData;
 }
 
-Expected<uintptr_t> XCOFFObjectFile::getLoaderSectionAddress() const {
-  uint64_t OffsetToLoaderSection = 0;
-  uint64_t SizeOfLoaderSection = 0;
-
-  if (is64Bit()) {
-    for (const auto &Sec64 : sections64())
-      if (Sec64.getSectionType() == XCOFF::STYP_LOADER) {
-        OffsetToLoaderSection = Sec64.FileOffsetToRawData;
-        SizeOfLoaderSection = Sec64.SectionSize;
-        break;
-      }
-  } else {
-    for (const auto &Sec32 : sections32())
-      if (Sec32.getSectionType() == XCOFF::STYP_LOADER) {
-        OffsetToLoaderSection = Sec32.FileOffsetToRawData;
-        SizeOfLoaderSection = Sec32.SectionSize;
-        break;
-      }
-  }
-
-  // No loader section is not an error.
-  if (!SizeOfLoaderSection)
-    return 0;
-
-  uintptr_t LoderSectionStart =
-      reinterpret_cast<uintptr_t>(base() + OffsetToLoaderSection);
-  if (Error E =
-          Binary::checkOffset(Data, LoderSectionStart, SizeOfLoaderSection))
-    return createError(toString(std::move(E)) +
-                       ": loader section with offset 0x" +
-                       Twine::utohexstr(OffsetToLoaderSection) +
-                       " and size 0x" + Twine::utohexstr(SizeOfLoaderSection) +
-                       " goes past the end of the file");
-
-  return LoderSectionStart;
-}
-
 Expected<uintptr_t> XCOFFObjectFile::getSectionFileOffsetToRawData(
     XCOFF::SectionTypeFlags SectType) const {
   DataRefImpl DRI = getSectionByType(SectType);
@@ -1095,7 +1058,8 @@
 // This function returns the import file table. Each entry in the import file
 // table consists of: "path_name\0base_name\0archive_member_name\0".
 Expected<StringRef> XCOFFObjectFile::getImportFileTable() const {
-  Expected<uintptr_t> LoaderSectionAddrOrError = getLoaderSectionAddress();
+  Expected<uintptr_t> LoaderSectionAddrOrError =
+      getSectionFileOffsetToRawData(XCOFF::STYP_LOADER);
   if (!LoaderSectionAddrOrError)
     return LoaderSectionAddrOrError.takeError();
 
Index: llvm/include/llvm/Object/XCOFFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/XCOFFObjectFile.h
+++ llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -491,7 +491,6 @@
   const XCOFFSectionHeader64 *toSection64(DataRefImpl Ref) const;
   uintptr_t getSectionHeaderTableAddress() const;
   uintptr_t getEndOfSymbolTableAddress() const;
-  Expected<uintptr_t> getLoaderSectionAddress() const;
 
   DataRefImpl getSectionByType(XCOFF::SectionTypeFlags SectType) const;
   uint64_t getSectionFileOffsetToRawData(DataRefImpl Sec) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134280.461552.patch
Type: text/x-patch
Size: 2835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220920/750b0b6e/attachment.bin>


More information about the llvm-commits mailing list