[llvm] Extend llvm objdump fatbin (PR #114834)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 09:27:40 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 70af40ba74cf62fdaa3ae1d7db972c138655049f 2f18112f00908a2d343359252449c2da8f65b060 --extensions h,cpp -- llvm/include/llvm/Object/OffloadBinary.h llvm/lib/Object/ObjectFile.cpp llvm/lib/Object/OffloadBinary.cpp llvm/tools/llvm-objdump/OffloadDump.cpp llvm/tools/llvm-objdump/OffloadDump.h llvm/tools/llvm-objdump/llvm-objdump.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index 984f40cc19..5723fe408b 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -17,12 +17,12 @@
 #ifndef LLVM_OBJECT_OFFLOADBINARY_H
 #define LLVM_OBJECT_OFFLOADBINARY_H
 
-#include "llvm/Support/Compression.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/Compression.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include <memory>
@@ -210,16 +210,22 @@ public:
   }
 };
 
-  struct BundleEntry {
-    uint64_t Offset = 0u;
-    uint64_t Size = 0u;
-    uint64_t IDLength = 0u;
-    StringRef ID;
-    BundleEntry(uint64_t O, uint64_t S, uint64_t I, StringRef T )
-                : Offset(O), Size(S), IDLength(I), ID(T) {}
-    void dumpInfo(raw_ostream &OS) { OS << "Offset = " << Offset << ", Size = " << Size << ", ID Length = " << IDLength << ", ID = " << ID;}
-    void dumpURI(raw_ostream &OS, StringRef filePath) {OS << ID.data() << "\tfile:\/\/" << filePath << "#offset=" << Offset << "&size=" << Size <<"\n";}
-  };
+struct BundleEntry {
+  uint64_t Offset = 0u;
+  uint64_t Size = 0u;
+  uint64_t IDLength = 0u;
+  StringRef ID;
+  BundleEntry(uint64_t O, uint64_t S, uint64_t I, StringRef T)
+      : Offset(O), Size(S), IDLength(I), ID(T) {}
+  void dumpInfo(raw_ostream &OS) {
+    OS << "Offset = " << Offset << ", Size = " << Size
+       << ", ID Length = " << IDLength << ", ID = " << ID;
+  }
+  void dumpURI(raw_ostream &OS, StringRef filePath) {
+    OS << ID.data() << "\tfile:\/\/" << filePath << "#offset=" << Offset
+       << "&size=" << Size << "\n";
+  }
+};
 
 class OffloadFatBinBundle {
 
@@ -230,15 +236,14 @@ private:
   SmallVector<BundleEntry> Entries;
 
 public:
-
-
-  SmallVector<BundleEntry> getEntries() { return Entries;}
+  SmallVector<BundleEntry> getEntries() { return Entries; }
 
   uint64_t getSize() const { return Size; }
-  StringRef getFileName() const {return FileName;}
-  int64_t getNumEntries() const { return NumberOfEntries;}
+  StringRef getFileName() const { return FileName; }
+  int64_t getNumEntries() const { return NumberOfEntries; }
 
-  static Expected<std::unique_ptr<OffloadFatBinBundle>> create(MemoryBufferRef, uint64_t SectionOffset, StringRef fileName);
+  static Expected<std::unique_ptr<OffloadFatBinBundle>>
+  create(MemoryBufferRef, uint64_t SectionOffset, StringRef fileName);
   Error extractBundle(const ObjectFile &Source);
 
   Error DumpEntryToCodeObject();
@@ -255,7 +260,7 @@ public:
   void PrintEntriesAsURI() {
     SmallVectorImpl<BundleEntry>::iterator it = Entries.begin();
     for (int64_t I = 0; I < NumberOfEntries; I++) {
-      it->dumpURI(outs(),FileName);
+      it->dumpURI(outs(), FileName);
       ++it;
     }
   }
@@ -273,14 +278,13 @@ public:
     return found;
   }
 
-  OffloadFatBinBundle(MemoryBufferRef Source, StringRef file) :
-                      FileName(file) {
+  OffloadFatBinBundle(MemoryBufferRef Source, StringRef file) : FileName(file) {
     NumberOfEntries = 0;
     Entries = SmallVector<BundleEntry>();
   }
 };
 
-enum uri_type_t {FILE_URI, MEMORY_URI};
+enum uri_type_t { FILE_URI, MEMORY_URI };
 
 struct OffloadBundleURI {
   int64_t Offset = 0;
@@ -291,39 +295,43 @@ struct OffloadBundleURI {
 
   // Constructors
   // TODO: add a Copy ctor ?
-  OffloadBundleURI(StringRef file, int64_t off, int64_t size) : Offset(off), Size(size), ProcessID(0), FileName(file), URIType(FILE_URI) {}
+  OffloadBundleURI(StringRef file, int64_t off, int64_t size)
+      : Offset(off), Size(size), ProcessID(0), FileName(file),
+        URIType(FILE_URI) {}
 
   OffloadBundleURI(StringRef str, uri_type_t type) {
     URIType = type;
     switch (URIType) {
-      case FILE_URI:
-    	parseFileName(str);
-        break;
-      case MEMORY_URI:
-        parseMemoryURI(str);
-        break;
-      default:
-    	report_fatal_error("Unrecognized URI type.");
-     }
+    case FILE_URI:
+      parseFileName(str);
+      break;
+    case MEMORY_URI:
+      parseMemoryURI(str);
+      break;
+    default:
+      report_fatal_error("Unrecognized URI type.");
+    }
   }
 
   void parseFileName(StringRef str) {
-    ProcessID=0;
-    URIType=FILE_URI;
+    ProcessID = 0;
+    URIType = FILE_URI;
     if (str.consume_front("file://")) {
-      StringRef FilePathname = str.take_until([](char c) {return (c == '#') || (c == '?');});
+      StringRef FilePathname =
+          str.take_until([](char c) { return (c == '#') || (c == '?'); });
       FileName = FilePathname;
       str = str.drop_front(FilePathname.size());
 
       if (str.consume_front("#offset=")) {
-        StringRef OffsetStr = str.take_until([](char c) { return c == '&';});
-        OffsetStr.getAsInteger(10,Offset);
+        StringRef OffsetStr = str.take_until([](char c) { return c == '&'; });
+        OffsetStr.getAsInteger(10, Offset);
         str = str.drop_front(OffsetStr.size());
 
         if (str.consume_front("&size=")) {
-           Size; str.getAsInteger(10,Size);
+          Size;
+          str.getAsInteger(10, Size);
         } else
-        	report_fatal_error("Reading 'size' in URI.");
+          report_fatal_error("Reading 'size' in URI.");
       } else
         report_fatal_error("Reading 'offset' in URI.");
     } else
@@ -334,15 +342,17 @@ struct OffloadBundleURI {
     // TODO: add parseMemoryURI type
   }
 
-  StringRef getFileName() const { return FileName;}
+  StringRef getFileName() const { return FileName; }
 };
 
 /// Extracts embedded device offloading code from a memory \p Buffer to a list
 /// of \p Binaries.
 Error extractOffloadBinaries(MemoryBufferRef Buffer,
                              SmallVectorImpl<OffloadFile> &Binaries);
-Error extractFatBinaryFromObject(const ObjectFile &Obj, SmallVectorImpl<OffloadFatBinBundle> &Bundles);
-Error extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size, StringRef OutputFileName);
+Error extractFatBinaryFromObject(const ObjectFile &Obj,
+                                 SmallVectorImpl<OffloadFatBinBundle> &Bundles);
+Error extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size,
+                        StringRef OutputFileName);
 Error extractURI(StringRef URIstr);
 
 /// Convert a string \p Name to an image kind.
diff --git a/llvm/lib/Object/OffloadBinary.cpp b/llvm/lib/Object/OffloadBinary.cpp
index b2288e8a47..a6ff079567 100644
--- a/llvm/lib/Object/OffloadBinary.cpp
+++ b/llvm/lib/Object/OffloadBinary.cpp
@@ -9,6 +9,7 @@
 #include "llvm/Object/OffloadBinary.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/COFF.h"
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Module.h"
@@ -17,17 +18,16 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
-#include "llvm/BinaryFormat/COFF.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Alignment.h"
+#include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/Timer.h"
-#include "llvm/Support/BinaryStreamReader.h"
 
 using namespace llvm;
 using namespace llvm::object;
@@ -106,8 +106,11 @@ Error extractFromObject(const ObjectFile &Obj,
   return Error::success();
 }
 
-// Extract an Offload bundle (usually a Clang Offload Bundle) from a fat_bin section
-Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset, StringRef fileName, SmallVectorImpl<OffloadFatBinBundle> &Bundles ) {
+// Extract an Offload bundle (usually a Clang Offload Bundle) from a fat_bin
+// section
+Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset,
+                           StringRef fileName,
+                           SmallVectorImpl<OffloadFatBinBundle> &Bundles) {
 
   uint64_t Offset = 0;
   int64_t nextbundleStart = 0;
@@ -119,18 +122,21 @@ Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset, Str
         MemoryBuffer::getMemBuffer(Contents.getBuffer().drop_front(Offset), "",
                                    /*RequiresNullTerminator*/ false);
 
-    // Create the FatBinBindle object. This will also create the Bundle Entry list info.
-    auto FatBundleOrErr = OffloadFatBinBundle::create(*Buffer, SectionOffset + Offset, fileName);
+    // Create the FatBinBindle object. This will also create the Bundle Entry
+    // list info.
+    auto FatBundleOrErr =
+        OffloadFatBinBundle::create(*Buffer, SectionOffset + Offset, fileName);
     if (!FatBundleOrErr)
       return FatBundleOrErr.takeError();
     OffloadFatBinBundle &Bundle = **FatBundleOrErr;
 
     // add current Bundle to list.
-   Bundles.emplace_back(std::move(**FatBundleOrErr));
+    Bundles.emplace_back(std::move(**FatBundleOrErr));
 
     // find the next bundle by searching for the magic string
     StringRef str = Buffer->getBuffer();
-    nextbundleStart = (int64_t)str.find(StringRef("__CLANG_OFFLOAD_BUNDLE__"), 24);
+    nextbundleStart =
+        (int64_t)str.find(StringRef("__CLANG_OFFLOAD_BUNDLE__"), 24);
 
     if (nextbundleStart >= 0)
       Offset += nextbundleStart;
@@ -213,61 +219,65 @@ Error extractFromArchive(const Archive &Library,
 
 } // namespace
 
-
-Error OffloadFatBinBundle::ReadEntries(StringRef Buffer, uint64_t SectionOffset) {
+Error OffloadFatBinBundle::ReadEntries(StringRef Buffer,
+                                       uint64_t SectionOffset) {
   uint64_t BundleNumber = 0;
   uint64_t NumOfEntries = 0;
 
   // get Reader
-  BinaryStreamReader Reader( Buffer, llvm::endianness::little);
+  BinaryStreamReader Reader(Buffer, llvm::endianness::little);
 
   // Read the Magic String first.
   StringRef Magic;
   if (auto EC = Reader.readFixedString(Magic, 24)) {
-      return errorCodeToError(object_error::parse_failed);
-   }
+    return errorCodeToError(object_error::parse_failed);
+  }
 
-   // read the number of Code Objects (Entries) in the current Bundle.
+  // read the number of Code Objects (Entries) in the current Bundle.
   if (auto EC = Reader.readInteger(NumOfEntries)) {
-    printf("OffloadFatBinBundle::ReadEntries .... failed to read number of Entries\n");
+    printf("OffloadFatBinBundle::ReadEntries .... failed to read number of "
+           "Entries\n");
     return errorCodeToError(object_error::parse_failed);
   }
   NumberOfEntries = NumOfEntries;
 
-    // For each Bundle Entry (code object)
-    for (uint64_t I = 0; I < NumOfEntries; I++) {
-      uint64_t EntrySize;
-      uint64_t EntryOffset;
-      uint64_t EntryIDSize;
-      StringRef EntryID;
-      uint64_t absOffset;
+  // For each Bundle Entry (code object)
+  for (uint64_t I = 0; I < NumOfEntries; I++) {
+    uint64_t EntrySize;
+    uint64_t EntryOffset;
+    uint64_t EntryIDSize;
+    StringRef EntryID;
+    uint64_t absOffset;
 
-      if (auto EC = Reader.readInteger(EntryOffset)) {
-        return errorCodeToError(object_error::parse_failed);
-      }
+    if (auto EC = Reader.readInteger(EntryOffset)) {
+      return errorCodeToError(object_error::parse_failed);
+    }
 
-      if (auto EC = Reader.readInteger(EntrySize)) {
-        return errorCodeToError(object_error::parse_failed);
-      }
+    if (auto EC = Reader.readInteger(EntrySize)) {
+      return errorCodeToError(object_error::parse_failed);
+    }
 
-      if (auto EC = Reader.readInteger(EntryIDSize)) {
-        return errorCodeToError(object_error::parse_failed);
-      }
+    if (auto EC = Reader.readInteger(EntryIDSize)) {
+      return errorCodeToError(object_error::parse_failed);
+    }
 
-      if (auto EC = Reader.readFixedString(EntryID, EntryIDSize)) {
-        return errorCodeToError(object_error::parse_failed);
-      }
+    if (auto EC = Reader.readFixedString(EntryID, EntryIDSize)) {
+      return errorCodeToError(object_error::parse_failed);
+    }
 
-      // create a Bundle Entry object:
-      auto entry = new BundleEntry(EntryOffset+SectionOffset, EntrySize, EntryIDSize, EntryID);
+    // create a Bundle Entry object:
+    auto entry = new BundleEntry(EntryOffset + SectionOffset, EntrySize,
+                                 EntryIDSize, EntryID);
 
-      Entries.push_back(*entry);
-    } // end of for loop
+    Entries.push_back(*entry);
+  } // end of for loop
 
-    return Error::success();
+  return Error::success();
 }
 
-Expected<std::unique_ptr<OffloadFatBinBundle>> OffloadFatBinBundle::create(MemoryBufferRef Buf, uint64_t SectionOffset, StringRef fileName) {
+Expected<std::unique_ptr<OffloadFatBinBundle>>
+OffloadFatBinBundle::create(MemoryBufferRef Buf, uint64_t SectionOffset,
+                            StringRef fileName) {
   if (Buf.getBufferSize() < 24)
     return errorCodeToError(object_error::parse_failed);
 
@@ -275,7 +285,7 @@ Expected<std::unique_ptr<OffloadFatBinBundle>> OffloadFatBinBundle::create(Memor
   if (identify_magic(Buf.getBuffer()) != file_magic::offload_bundle)
     return errorCodeToError(object_error::parse_failed);
 
-  OffloadFatBinBundle* TheBundle = new OffloadFatBinBundle(Buf, fileName);
+  OffloadFatBinBundle *TheBundle = new OffloadFatBinBundle(Buf, fileName);
 
   // Read the Bundle Entries
   Error Err = TheBundle->ReadEntries(Buf.getBuffer(), SectionOffset);
@@ -290,11 +300,14 @@ Error OffloadFatBinBundle::extractBundle(const ObjectFile &Source) {
   SmallVectorImpl<BundleEntry>::iterator it = Entries.begin();
   for (int64_t I = 0; I < getNumEntries(); I++) {
 
-    if (it->Size >0) {
-      // create output file name. Which should be <fileName>-offset<Offset>-size<Size>.co"
-     std::string str = getFileName().str() + "-offset" + itostr(it->Offset) + "-size" + itostr(it->Size) + ".co";
-     if (Error Err = object::extractCodeObject(Source, it->Offset, it->Size, StringRef(str)))
-       return Err;
+    if (it->Size > 0) {
+      // create output file name. Which should be
+      // <fileName>-offset<Offset>-size<Size>.co"
+      std::string str = getFileName().str() + "-offset" + itostr(it->Offset) +
+                        "-size" + itostr(it->Size) + ".co";
+      if (Error Err = object::extractCodeObject(Source, it->Offset, it->Size,
+                                                StringRef(str)))
+        return Err;
     }
     ++it;
   }
@@ -431,7 +444,8 @@ Error object::extractOffloadBinaries(MemoryBufferRef Buffer,
   }
 }
 
-Error object::extractFatBinaryFromObject(const ObjectFile &Obj, SmallVectorImpl<OffloadFatBinBundle> &Bundles) {
+Error object::extractFatBinaryFromObject(
+    const ObjectFile &Obj, SmallVectorImpl<OffloadFatBinBundle> &Bundles) {
   assert((Obj.isELF() || Obj.isCOFF()) && "Invalid file type");
 
   // iterate through Sections until we find an offload_bundle section.
@@ -442,35 +456,39 @@ Error object::extractFatBinaryFromObject(const ObjectFile &Obj, SmallVectorImpl<
 
     // If it does not start with the reserved suffix, just skip this section.
     if ((llvm::identify_magic(*Buffer) == llvm::file_magic::offload_bundle) ||
-    	(llvm::identify_magic(*Buffer) == llvm::file_magic::offload_bundle_compressed)){
+        (llvm::identify_magic(*Buffer) ==
+         llvm::file_magic::offload_bundle_compressed)) {
 
       uint64_t SectionOffset = 0;
       if (Obj.isELF()) {
-    	  SectionOffset = ELFSectionRef(Sec).getOffset();
+        SectionOffset = ELFSectionRef(Sec).getOffset();
       } else if (Obj.isCOFF()) {
-    	  if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj)) {
-    	    const coff_section *CoffSection = COFFObj->getCOFFSection(Sec);
-    	  }
+        if (const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(&Obj)) {
+          const coff_section *CoffSection = COFFObj->getCOFFSection(Sec);
+        }
       }
 
       MemoryBufferRef Contents(*Buffer, Obj.getFileName());
 
-      if (llvm::identify_magic(*Buffer) == llvm::file_magic::offload_bundle_compressed){
+      if (llvm::identify_magic(*Buffer) ==
+          llvm::file_magic::offload_bundle_compressed) {
         // Decompress the input if necessary.
         Expected<std::unique_ptr<MemoryBuffer>> DecompressedBufferOrErr =
             CompressedOffloadBundle::decompress(Contents, false);
 
         if (!DecompressedBufferOrErr)
-            return createStringError(
-                inconvertibleErrorCode(),
-                "Failed to decompress input: " +
-                    llvm::toString(DecompressedBufferOrErr.takeError()));
-
-          MemoryBuffer &DecompressedInput = **DecompressedBufferOrErr;
-          if (Error Err = extractOffloadBundle(DecompressedInput, SectionOffset, Obj.getFileName() ,Bundles))
-                    return Err;
+          return createStringError(
+              inconvertibleErrorCode(),
+              "Failed to decompress input: " +
+                  llvm::toString(DecompressedBufferOrErr.takeError()));
+
+        MemoryBuffer &DecompressedInput = **DecompressedBufferOrErr;
+        if (Error Err = extractOffloadBundle(DecompressedInput, SectionOffset,
+                                             Obj.getFileName(), Bundles))
+          return Err;
       } else {
-        if (Error Err = extractOffloadBundle(Contents, SectionOffset, Obj.getFileName() ,Bundles))
+        if (Error Err = extractOffloadBundle(Contents, SectionOffset,
+                                             Obj.getFileName(), Bundles))
           return Err;
       }
     }
@@ -478,9 +496,10 @@ Error object::extractFatBinaryFromObject(const ObjectFile &Obj, SmallVectorImpl<
   return Error::success();
 }
 
-Error object::extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size, StringRef OutputFileName) {
+Error object::extractCodeObject(const ObjectFile &Source, int64_t Offset,
+                                int64_t Size, StringRef OutputFileName) {
   Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
-     FileOutputBuffer::create(OutputFileName, Size);
+      FileOutputBuffer::create(OutputFileName, Size);
 
   if (!BufferOrErr)
     return BufferOrErr.takeError();
@@ -490,7 +509,9 @@ Error object::extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_
     return Err;
 
   std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
-  std::copy(InputBuffOrErr->getBufferStart() + Offset, InputBuffOrErr->getBufferStart() + Offset + Size, Buf->getBufferStart());
+  std::copy(InputBuffOrErr->getBufferStart() + Offset,
+            InputBuffOrErr->getBufferStart() + Offset + Size,
+            Buf->getBufferStart());
   if (Error E = Buf->commit())
     return E;
 
@@ -501,18 +522,21 @@ Error object::extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_
 // into file <SourceFile>-offset<Offset>-size<Size>.co
 Error object::extractURI(StringRef URIstr) {
   // create a URI object
-  object::OffloadBundleURI* uri = new object::OffloadBundleURI(URIstr, FILE_URI);
+  object::OffloadBundleURI *uri =
+      new object::OffloadBundleURI(URIstr, FILE_URI);
 
   std::string OutputFile = uri->FileName.str();
-  OutputFile +="-offset" + itostr(uri->Offset) + "-size" + itostr(uri->Size) + ".co";
+  OutputFile +=
+      "-offset" + itostr(uri->Offset) + "-size" + itostr(uri->Size) + ".co";
 
   // Create an ObjectFile object from uri.file_uri
   auto ObjOrErr = ObjectFile::createObjectFile(uri->FileName);
-  if(!ObjOrErr)
+  if (!ObjOrErr)
     return ObjOrErr.takeError();
 
   auto Obj = ObjOrErr->getBinary();
-  if (Error Err = object::extractCodeObject(*Obj, uri->Offset, uri->Size, OutputFile))
+  if (Error Err =
+          object::extractCodeObject(*Obj, uri->Offset, uri->Size, OutputFile))
     return Err;
 
   return Error::success();
@@ -602,7 +626,6 @@ bool object::areTargetsCompatible(const OffloadFile::TargetID &LHS,
   return true;
 }
 
-
 // Utility function to format numbers with commas
 static std::string formatWithCommas(unsigned long long Value) {
   std::string Num = std::to_string(Value);
diff --git a/llvm/tools/llvm-objdump/OffloadDump.cpp b/llvm/tools/llvm-objdump/OffloadDump.cpp
index 120cc26f4f..516f5d0278 100644
--- a/llvm/tools/llvm-objdump/OffloadDump.cpp
+++ b/llvm/tools/llvm-objdump/OffloadDump.cpp
@@ -14,14 +14,14 @@
 #include "OffloadDump.h"
 #include "llvm-objdump.h"
 #include "llvm/Object/ELFObjectFile.h"
-#include "llvm/Support/Alignment.h"
 #include "llvm/Object/OffloadBinary.h"
+#include "llvm/Support/Alignment.h"
 
 using namespace llvm;
 using namespace llvm::object;
 using namespace llvm::objdump;
 
-void disassembleObject(llvm::object::ObjectFile*, bool InlineRelocs);
+void disassembleObject(llvm::object::ObjectFile *, bool InlineRelocs);
 
 /// Get the printable name of the image kind.
 static StringRef getImageName(const OffloadBinary &OB) {
@@ -73,31 +73,41 @@ void llvm::dumpOffloadBinary(const ObjectFile &O) {
 // and dump them into Code Object files
 // if -d is specified, disassemble the Code Object Files
 // if -arch=-name is specified, only dump the Entries that match the target arch
-void llvm::dumpOffloadFatBinary(const ObjectFile &O, std::string ArchName, bool Disassemble) {
+void llvm::dumpOffloadFatBinary(const ObjectFile &O, std::string ArchName,
+                                bool Disassemble) {
   assert((O.isELF() || O.isCOFF()) && "Invalid file type");
   // Collect all Bundles and their Entries ....
   SmallVector<llvm::object::OffloadFatBinBundle> FoundBundles;
   SmallVector<BundleEntry> FoundEntries;
 
   if (Error Err = llvm::object::extractFatBinaryFromObject(O, FoundBundles))
-    reportError(O.getFileName(), "while extracting offload FatBin bundles: " + toString(std::move(Err)));
+    reportError(O.getFileName(), "while extracting offload FatBin bundles: " +
+                                     toString(std::move(Err)));
 
   // Now filter based on if arch-name is specified
-  SmallVectorImpl<llvm::object::OffloadFatBinBundle>::iterator BundleIter = FoundBundles.begin();
-  for (uint64_t bundle_num = 0; bundle_num < FoundBundles.size(); bundle_num++) {
+  SmallVectorImpl<llvm::object::OffloadFatBinBundle>::iterator BundleIter =
+      FoundBundles.begin();
+  for (uint64_t bundle_num = 0; bundle_num < FoundBundles.size();
+       bundle_num++) {
     if (!ArchName.empty())
       FoundEntries = BundleIter->EntryIDContains(StringRef(ArchName));
     else
       FoundEntries = BundleIter->getEntries();
 
     // now we have a list of Found Entries .... dump them
-    SmallVectorImpl</*OffloadFatBinBundle::*/BundleEntry>::iterator FoundIter = FoundEntries.begin();
+    SmallVectorImpl</*OffloadFatBinBundle::*/ BundleEntry>::iterator FoundIter =
+        FoundEntries.begin();
     for (int64_t entry_num = 0; entry_num < FoundEntries.size(); entry_num++) {
-      // create file name for this object file:  <source-filename>:<Bundle Number>.<EntryID>
-      std::string str = BundleIter->getFileName().str() + ":" + itostr(bundle_num) + "." + FoundIter->ID.str();
+      // create file name for this object file:  <source-filename>:<Bundle
+      // Number>.<EntryID>
+      std::string str = BundleIter->getFileName().str() + ":" +
+                        itostr(bundle_num) + "." + FoundIter->ID.str();
       StringRef OutputFilename = StringRef(str);
-      if (Error Err = object::extractCodeObject(O, FoundIter->Offset, FoundIter->Size, OutputFilename))
-        reportError(O.getFileName(), "while extracting offload Bundle Entries: " + toString(std::move(Err)));
+      if (Error Err = object::extractCodeObject(
+              O, FoundIter->Offset, FoundIter->Size, OutputFilename))
+        reportError(O.getFileName(),
+                    "while extracting offload Bundle Entries: " +
+                        toString(std::move(Err)));
 
       // TODO: If -d was specified, disasseble the Code Object too
 
diff --git a/llvm/tools/llvm-objdump/OffloadDump.h b/llvm/tools/llvm-objdump/OffloadDump.h
index 0f044b85ec..9ba0818355 100644
--- a/llvm/tools/llvm-objdump/OffloadDump.h
+++ b/llvm/tools/llvm-objdump/OffloadDump.h
@@ -16,7 +16,8 @@ namespace llvm {
 
 void dumpOffloadSections(const object::OffloadBinary &OB);
 void dumpOffloadBinary(const object::ObjectFile &O);
-void dumpOffloadFatBinary(const object::ObjectFile &O, std::string ArchName, bool Disassemble);
+void dumpOffloadFatBinary(const object::ObjectFile &O, std::string ArchName,
+                          bool Disassemble);
 } // namespace llvm
 
 #endif
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 49d863cb52..2d9894ef5a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3735,7 +3735,8 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
   if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
       !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
       !Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
-      !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading && !OffloadFatBin &&
+      !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading &&
+      !OffloadFatBin &&
       !(MachOOpt &&
         (Bind || DataInCode || ChainedFixups || DyldInfo || DylibId ||
          DylibsUsed || ExportsTrie || FirstPrivateHeader ||
@@ -3754,5 +3755,3 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   return EXIT_SUCCESS;
 }
-
-

``````````

</details>


https://github.com/llvm/llvm-project/pull/114834


More information about the llvm-commits mailing list