[llvm] [llvm][macho] Support the LC_TARGET_TRIPLE load command (PR #210276)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 17:50:42 PDT 2026


https://github.com/lhames commented:

ExecutionEngine parts look good to me, but it would be good to add a unit test. The following may need some cleaning up (I haven't tested it with your patch):
```c++
diff --git a/llvm/unittests/ExecutionEngine/Orc/MachOBuilderTest.cpp b/llvm/unittests/ExecutionEngine/Orc/MachOBuilderTest.cpp
index 55445cd1875d..257af77161ec 100644
--- a/llvm/unittests/ExecutionEngine/Orc/MachOBuilderTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/MachOBuilderTest.cpp
@@ -41,3 +41,31 @@ TEST(MachOBuilderTest, AddLCUUID) {
   ASSERT_EQ(ParsedUUID.size(), 16u);
   EXPECT_EQ(ArrayRef<uint8_t>(UUID), ParsedUUID);
 }
+
+TEST(MachOBuilderTest, AddTargetTriple) {
+  std::string TestTriple = "x86_64-apple-darwin";
+  MachOBuilder<MachO64LE> B(4096);
+  B.Header.filetype = MachO::MH_OBJECT;
+
+  B.addLoadCommand<MachO::LC_TARGET_TRIPLE>(TestTriple);
+
+  size_t Size = B.layout();
+  std::vector<char> Buffer(Size, 0);
+  B.write({Buffer.data(), Buffer.size()});
+
+  auto Obj = parseMachO(Buffer);
+  ASSERT_THAT_EXPECTED(Obj, Succeeded());
+
+  bool Found = false;
+  for (auto &LC : (*Obj)->load_commands()) {
+    if (LC.C.cmd == MachO::LC_TARGET_TRIPLE) {
+      Found = true;
+      std::string ReadTriple
+        = LC.Ptr + Obj->getTargetTripleLoadCommand(Load).triple;
+      EXPECT_EQ(ReadTriple, TestTriple);
+      break;
+    }
+  }
+
+  EXPECT_TRUE(Found);
+}
```

Test case 

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


More information about the llvm-commits mailing list