[llvm] 7635761 - [llvm][object] handle GOFF in createObjectFile (#206636)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 15:46:16 PDT 2026


Author: David Tenty
Date: 2026-07-03T18:46:11-04:00
New Revision: 76357610925cbc76f3a084dea730f97db8fe7464

URL: https://github.com/llvm/llvm-project/commit/76357610925cbc76f3a084dea730f97db8fe7464
DIFF: https://github.com/llvm/llvm-project/commit/76357610925cbc76f3a084dea730f97db8fe7464.diff

LOG: [llvm][object] handle GOFF in createObjectFile (#206636)

`ObjectFile::createObjectFile` doesn't handle GOFF and returns an error,
even though the requisite GOFF support is present (i.e.
`createGOFFObjectFile`). This change corrects this, and adds a simple
test for `createObjectFile` on a GOFF type object.

Added: 
    

Modified: 
    llvm/lib/Object/ObjectFile.cpp
    llvm/unittests/Object/GOFFObjectFileTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp
index b0e4ea0a51ba1..c4b4cdff6de93 100644
--- a/llvm/lib/Object/ObjectFile.cpp
+++ b/llvm/lib/Object/ObjectFile.cpp
@@ -163,7 +163,6 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
   case file_magic::windows_resource:
   case file_magic::pdb:
   case file_magic::minidump:
-  case file_magic::goff_object:
   case file_magic::cuda_fatbinary:
   case file_magic::offload_binary:
   case file_magic::offload_bundle:
@@ -203,6 +202,8 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
     return createWasmObjectFile(Object);
   case file_magic::dxcontainer_object:
     return createDXContainerObjectFile(Object);
+  case file_magic::goff_object:
+    return createGOFFObjectFile(Object);
   }
   llvm_unreachable("Unexpected Object File Type");
 }

diff  --git a/llvm/unittests/Object/GOFFObjectFileTest.cpp b/llvm/unittests/Object/GOFFObjectFileTest.cpp
index e2fbf81ef23f5..8dc45337dc93b 100644
--- a/llvm/unittests/Object/GOFFObjectFileTest.cpp
+++ b/llvm/unittests/Object/GOFFObjectFileTest.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Object/GOFFObjectFile.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
@@ -42,6 +43,31 @@ void constructInvalidGOFF(size_t Size) {
 }
 } // namespace
 
+TEST(GOFFObjectFileTest, createObjectFile) {
+  const uint8_t GOFFData[] = {
+      0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00,
+  };
+  ArrayRef<uint8_t> GOFFRef(GOFFData, sizeof(GOFFData));
+  Expected<std::unique_ptr<ObjectFile>> XCOFFObjOrErr =
+      object::ObjectFile::createObjectFile(
+          MemoryBufferRef(toStringRef(GOFFRef), "dummyGOFF"),
+          file_magic::goff_object);
+  ASSERT_THAT_EXPECTED(XCOFFObjOrErr, Succeeded());
+}
+
 TEST(GOFFObjectFileTest, ConstructGOFFObjectValidSize) {
   GOFFData[0] = (char)0x03;
   GOFFData[1] = (char)0xF0;


        


More information about the llvm-commits mailing list