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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 20:06:01 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

Author: David Tenty (daltenty)

<details>
<summary>Changes</summary>

`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.

---
Full diff: https://github.com/llvm/llvm-project/pull/206636.diff


2 Files Affected:

- (modified) llvm/lib/Object/ObjectFile.cpp (+2-1) 
- (modified) llvm/unittests/Object/GOFFObjectFileTest.cpp (+27) 


``````````diff
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..5d0b9e73c8dd5 100644
--- a/llvm/unittests/Object/GOFFObjectFileTest.cpp
+++ b/llvm/unittests/Object/GOFFObjectFileTest.cpp
@@ -42,6 +42,33 @@ 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;

``````````

</details>


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


More information about the llvm-commits mailing list