[llvm] [llvm][object] handle GOFF in createObjectFile (PR #206636)
David Tenty via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 20:05:14 PDT 2026
https://github.com/daltenty created https://github.com/llvm/llvm-project/pull/206636
`ObjectFile::createObjectFile` doesn't handle GOFF and returns an error, even though the requisite GOFF support is present (i.e. `createGOFFObjectFile`). This change correct this, and adds a simple test for `createObjectFile` on a GOFF type object.
>From a22fb331d60b1fa78a3b3824b06a79f83467b3fd Mon Sep 17 00:00:00 2001
From: David Tenty <daltenty at ibm.com>
Date: Mon, 29 Jun 2026 22:40:33 -0400
Subject: [PATCH] [llvm][object] handle GOFF in createObjectFile
---
llvm/lib/Object/ObjectFile.cpp | 3 ++-
llvm/unittests/Object/GOFFObjectFileTest.cpp | 27 ++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
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;
More information about the llvm-commits
mailing list