[llvm] 6128ff6 - [JITLink][MachO] Add convenience functions for default text/data sections.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 18:05:59 PDT 2024


Author: Lang Hames
Date: 2024-10-28T18:05:40-07:00
New Revision: 6128ff6630762310f6ae4eb61adda02cb4ad5260

URL: https://github.com/llvm/llvm-project/commit/6128ff6630762310f6ae4eb61adda02cb4ad5260
DIFF: https://github.com/llvm/llvm-project/commit/6128ff6630762310f6ae4eb61adda02cb4ad5260.diff

LOG: [JITLink][MachO] Add convenience functions for default text/data sections.

The getMachODefaultTextSection and getMachODefaultRWDataSection functions
return the "__TEXT,__text" and "__DATA,__data" sections respectively, creating
empty sections if the default sections are not already present in the graph.
These functions can be used by utilities that want to add code or data to these
standard sections (e.g. these functions can be used to supply the section
argument to the createAnonymousPointerJumpStub and
createPointerJumpStubBlock functions in the various targets).

Added: 
    llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.cpp
    llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h
    llvm/unittests/ExecutionEngine/JITLink/MachOLinkGraphTests.cpp

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/MachO.h
    llvm/include/llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h
    llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp
    llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
    llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
    llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp

Removed: 
    llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.cpp
    llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.h


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h b/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h
index b8432c4d26c68c..bb8da0ab9db27a 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/MachO.h
@@ -14,6 +14,7 @@
 #define LLVM_EXECUTIONENGINE_JITLINK_MACHO_H
 
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
+#include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h"
 
 namespace llvm {
 namespace jitlink {
@@ -33,6 +34,26 @@ createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer);
 void link_MachO(std::unique_ptr<LinkGraph> G,
                 std::unique_ptr<JITLinkContext> Ctx);
 
+/// Get a pointer to the standard MachO data section (creates an empty
+/// section with RW- permissions and standard lifetime if one does not
+/// already exist).
+inline Section &getMachODefaultRWDataSection(LinkGraph &G) {
+  if (auto *DataSec = G.findSectionByName(orc::MachODataDataSectionName))
+    return *DataSec;
+  return G.createSection(orc::MachODataDataSectionName,
+                         orc::MemProt::Read | orc::MemProt::Write);
+}
+
+/// Get a pointer to the standard MachO text section (creates an empty
+/// section with R-X permissions and standard lifetime if one does not
+/// already exist).
+inline Section &getMachODefaultTextSection(LinkGraph &G) {
+  if (auto *TextSec = G.findSectionByName(orc::MachOTextTextSectionName))
+    return *TextSec;
+  return G.createSection(orc::MachOTextTextSectionName,
+                         orc::MemProt::Read | orc::MemProt::Exec);
+}
+
 } // end namespace jitlink
 } // end namespace llvm
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h
index f886203f8e3fb5..b927dfbce992a0 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h
@@ -49,6 +49,7 @@ extern StringRef MachOSwift5TypesSectionName;
 extern StringRef MachOSwift5TypeRefSectionName;
 extern StringRef MachOSwift5FieldMetadataSectionName;
 extern StringRef MachOSwift5EntrySectionName;
+extern StringRef MachOTextTextSectionName;
 extern StringRef MachOThreadBSSSectionName;
 extern StringRef MachOThreadDataSectionName;
 extern StringRef MachOThreadVarsSectionName;

diff  --git a/llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp b/llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp
index 7f4c2934d026ad..11e8eb7bc3a19b 100644
--- a/llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Shared/MachOObjectFormat.cpp
@@ -42,6 +42,7 @@ StringRef MachOSwift5TypesSectionName = "__TEXT,__swift5_types";
 StringRef MachOSwift5TypeRefSectionName = "__TEXT,__swift5_typeref";
 StringRef MachOSwift5FieldMetadataSectionName = "__TEXT,__swift5_fieldmd";
 StringRef MachOSwift5EntrySectionName = "__TEXT,__swift5_entry";
+StringRef MachOTextTextSectionName = "__TEXT,__text";
 StringRef MachOThreadBSSSectionName = "__DATA,__thread_bss";
 StringRef MachOThreadDataSectionName = "__DATA,__thread_data";
 StringRef MachOThreadVarsSectionName = "__DATA,__thread_vars";

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
index 82d277309307cb..d1c7b799880a3b 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/JITLink/CMakeLists.txt
@@ -11,8 +11,9 @@ add_llvm_unittest(JITLinkTests
     AArch32Tests.cpp
     AArch32ErrorTests.cpp
     EHFrameSupportTests.cpp
-    JITLinkMocks.cpp
+    JITLinkTestUtils.cpp
     LinkGraphTests.cpp
+    MachOLinkGraphTests.cpp
     MemoryManagerErrorTests.cpp
     StubsTests.cpp
   )

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.cpp b/llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.cpp
deleted file mode 100644
index c40ce7adb0b5ea..00000000000000
--- a/llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-//===--------- JITLinkMocks.cpp - Mock APIs for JITLink unit tests --------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "JITLinkMocks.h"
-#include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h"
-
-#include "llvm/Testing/Support/Error.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace llvm::orc;
-using namespace llvm::jitlink;
-
-void lookupResolveEverythingToNull(
-    const llvm::jitlink::JITLinkContext::LookupMap &Symbols,
-    std::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation> LC) {
-  llvm::orc::ExecutorAddr Null;
-  llvm::jitlink::AsyncLookupResult Result;
-  for (auto &KV : Symbols)
-    Result[KV.first] = {Null, llvm::JITSymbolFlags::Exported};
-  LC->run(std::move(Result));
-}
-
-void lookupErrorOut(
-    const llvm::jitlink::JITLinkContext::LookupMap &Symbols,
-    std::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation> LC) {
-  LC->run(llvm::make_error<llvm::StringError>("Lookup failed",
-                                              llvm::inconvertibleErrorCode()));
-}
-
-std::unique_ptr<MockJITLinkContext> makeMockContext(
-    llvm::unique_function<void(llvm::Error)> HandleFailed,
-    llvm::unique_function<void(MockJITLinkMemoryManager &)> SetupMemMgr,
-    llvm::unique_function<void(MockJITLinkContext &)> SetupContext) {
-  auto MemMgr = std::make_unique<MockJITLinkMemoryManager>();
-  SetupMemMgr(*MemMgr);
-  auto Ctx = std::make_unique<MockJITLinkContext>(std::move(MemMgr),
-                                                  std::move(HandleFailed));
-  SetupContext(*Ctx);
-  return Ctx;
-}
-
-void defaultMemMgrSetup(MockJITLinkMemoryManager &) {}
-void defaultCtxSetup(MockJITLinkContext &) {}
-
-TEST(JITLinkMocks, SmokeTest) {
-  // Check that the testing infrastructure defaults can "link" a graph
-  // successfully.
-  auto G = std::make_unique<LinkGraph>("foo", Triple("x86_64-apple-darwin"), 8,
-                                       llvm::endianness::little,
-                                       getGenericEdgeKindName);
-
-  ArrayRef<char> Content = "hello, world!";
-  auto &Sec =
-      G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
-  orc::ExecutorAddr B1Addr(0x1000);
-  auto &B = G->createContentBlock(Sec, Content, B1Addr, 8, 0);
-  G->addDefinedSymbol(B, 4, "S", 4, Linkage::Strong, Scope::Default, false,
-                      false);
-
-  Error Err = Error::success();
-  auto Ctx =
-      makeMockContext(JoinErrorsInto(Err), defaultMemMgrSetup, defaultCtxSetup);
-
-  link_MachO_x86_64(std::move(G), std::move(Ctx));
-
-  EXPECT_THAT_ERROR(std::move(Err), Succeeded());
-}

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.cpp b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.cpp
new file mode 100644
index 00000000000000..9a7878edab5045
--- /dev/null
+++ b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.cpp
@@ -0,0 +1,114 @@
+//===------- JITLinkTestUtils.cpp - Utilities for JITLink unit tests ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "JITLinkTestUtils.h"
+#include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h"
+
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::orc;
+using namespace llvm::jitlink;
+
+static const char BlockContentBytes[] = {
+    0x54, 0x68, 0x65, 0x72, 0x65, 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x6f,
+    0x76, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x61, 0x74, 0x20, 0x74, 0x68,
+    0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x66,
+    0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x64, 0x20,
+    0x68, 0x61, 0x64, 0x20, 0x70, 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x61,
+    0x72, 0x6f, 0x75, 0x6e, 0x64, 0x0a, 0x54, 0x68, 0x61, 0x74, 0x20, 0x74,
+    0x68, 0x65, 0x20, 0x63, 0x6f, 0x6c, 0x74, 0x20, 0x66, 0x72, 0x6f, 0x6d,
+    0x20, 0x4f, 0x6c, 0x64, 0x20, 0x52, 0x65, 0x67, 0x72, 0x65, 0x74, 0x20,
+    0x68, 0x61, 0x64, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x61, 0x77, 0x61, 0x79,
+    0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20, 0x68, 0x61, 0x64, 0x20, 0x6a, 0x6f,
+    0x69, 0x6e, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x69, 0x6c,
+    0x64, 0x20, 0x62, 0x75, 0x73, 0x68, 0x20, 0x68, 0x6f, 0x72, 0x73, 0x65,
+    0x73, 0x20, 0x2d, 0x2d, 0x20, 0x68, 0x65, 0x20, 0x77, 0x61, 0x73, 0x20,
+    0x77, 0x6f, 0x72, 0x74, 0x68, 0x20, 0x61, 0x20, 0x74, 0x68, 0x6f, 0x75,
+    0x73, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x6f, 0x75, 0x6e, 0x64, 0x2c, 0x0a,
+    0x53, 0x6f, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+    0x72, 0x61, 0x63, 0x6b, 0x73, 0x20, 0x68, 0x61, 0x64, 0x20, 0x67, 0x61,
+    0x74, 0x68, 0x65, 0x72, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68,
+    0x65, 0x20, 0x66, 0x72, 0x61, 0x79, 0x2e, 0x0a, 0x41, 0x6c, 0x6c, 0x20,
+    0x74, 0x68, 0x65, 0x20, 0x74, 0x72, 0x69, 0x65, 0x64, 0x20, 0x61, 0x6e,
+    0x64, 0x20, 0x6e, 0x6f, 0x74, 0x65, 0x64, 0x20, 0x72, 0x69, 0x64, 0x65,
+    0x72, 0x73, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20,
+    0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6e, 0x65, 0x61,
+    0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x61, 0x72, 0x0a, 0x48, 0x61,
+    0x64, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x61,
+    0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x73, 0x74,
+    0x65, 0x61, 0x64, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68,
+    0x74, 0x2c, 0x0a, 0x46, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62,
+    0x75, 0x73, 0x68, 0x6d, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x20,
+    0x68, 0x61, 0x72, 0x64, 0x20, 0x72, 0x69, 0x64, 0x69, 0x6e, 0x67, 0x20,
+    0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x69,
+    0x6c, 0x64, 0x20, 0x62, 0x75, 0x73, 0x68, 0x20, 0x68, 0x6f, 0x72, 0x73,
+    0x65, 0x73, 0x20, 0x61, 0x72, 0x65, 0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20,
+    0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x2d, 0x68, 0x6f,
+    0x72, 0x73, 0x65, 0x20, 0x73, 0x6e, 0x75, 0x66, 0x66, 0x73, 0x20, 0x74,
+    0x68, 0x65, 0x20, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x20, 0x77, 0x69,
+    0x74, 0x68, 0x20, 0x64, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x00};
+
+ArrayRef<char> BlockContent(BlockContentBytes);
+
+void lookupResolveEverythingToNull(
+    const llvm::jitlink::JITLinkContext::LookupMap &Symbols,
+    std::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation> LC) {
+  llvm::orc::ExecutorAddr Null;
+  llvm::jitlink::AsyncLookupResult Result;
+  for (auto &KV : Symbols)
+    Result[KV.first] = {Null, llvm::JITSymbolFlags::Exported};
+  LC->run(std::move(Result));
+}
+
+void lookupErrorOut(
+    const llvm::jitlink::JITLinkContext::LookupMap &Symbols,
+    std::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation> LC) {
+  LC->run(llvm::make_error<llvm::StringError>("Lookup failed",
+                                              llvm::inconvertibleErrorCode()));
+}
+
+std::unique_ptr<MockJITLinkContext> makeMockContext(
+    llvm::unique_function<void(llvm::Error)> HandleFailed,
+    llvm::unique_function<void(MockJITLinkMemoryManager &)> SetupMemMgr,
+    llvm::unique_function<void(MockJITLinkContext &)> SetupContext) {
+  auto MemMgr = std::make_unique<MockJITLinkMemoryManager>();
+  SetupMemMgr(*MemMgr);
+  auto Ctx = std::make_unique<MockJITLinkContext>(std::move(MemMgr),
+                                                  std::move(HandleFailed));
+  SetupContext(*Ctx);
+  return Ctx;
+}
+
+void defaultMemMgrSetup(MockJITLinkMemoryManager &) {}
+void defaultCtxSetup(MockJITLinkContext &) {}
+
+TEST(JITLinkMocks, SmokeTest) {
+  // Check that the testing infrastructure defaults can "link" a graph
+  // successfully.
+  auto G = std::make_unique<LinkGraph>("foo", Triple("x86_64-apple-darwin"), 8,
+                                       llvm::endianness::little,
+                                       getGenericEdgeKindName);
+
+  ArrayRef<char> Content = "hello, world!";
+  auto &Sec =
+      G->createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
+  orc::ExecutorAddr B1Addr(0x1000);
+  auto &B = G->createContentBlock(Sec, Content, B1Addr, 8, 0);
+  G->addDefinedSymbol(B, 4, "S", 4, Linkage::Strong, Scope::Default, false,
+                      false);
+
+  Error Err = Error::success();
+  auto Ctx =
+      makeMockContext(JoinErrorsInto(Err), defaultMemMgrSetup, defaultCtxSetup);
+
+  link_MachO_x86_64(std::move(G), std::move(Ctx));
+
+  EXPECT_THAT_ERROR(std::move(Err), Succeeded());
+}

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.h b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h
similarity index 95%
rename from llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.h
rename to llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h
index 8c1e3ff2c77db5..dc077f900d1958 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/JITLinkMocks.h
+++ b/llvm/unittests/ExecutionEngine/JITLink/JITLinkTestUtils.h
@@ -1,4 +1,4 @@
-//===----- JITLinkMocks.h - Mock APIs for JITLink unit tests ----*- C++ -*-===//
+//===--- JITLinkTestUtils.h - Utilities for JITLink unit tests --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Mock APIs for JITLink unit tests.
+// Utilities for JITLink unit tests.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKMOCKS_H
-#define LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKMOCKS_H
+#ifndef LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKTESTUTILS_H
+#define LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKTESTUTILS_H
 
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
 
@@ -225,4 +225,6 @@ class JoinErrorsInto {
   llvm::Error &Err;
 };
 
-#endif // LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKMOCKS_H
+extern llvm::ArrayRef<char> BlockContent;
+
+#endif // LLVM_UNITTESTS_EXECUTIONENGINE_JITLINK_JITLINKTESTUTILS_H

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index 5eea2118461952..32d917d75d5ca4 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "JITLinkTestUtils.h"
+
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
 #include "llvm/ExecutionEngine/Orc/ObjectFileInterface.h"
@@ -17,47 +19,6 @@
 using namespace llvm;
 using namespace llvm::jitlink;
 
-static const char BlockContentBytes[] = {
-    0x54, 0x68, 0x65, 0x72, 0x65, 0x20, 0x77, 0x61, 0x73, 0x20, 0x6d, 0x6f,
-    0x76, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x61, 0x74, 0x20, 0x74, 0x68,
-    0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x66,
-    0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x6f, 0x72, 0x64, 0x20,
-    0x68, 0x61, 0x64, 0x20, 0x70, 0x61, 0x73, 0x73, 0x65, 0x64, 0x20, 0x61,
-    0x72, 0x6f, 0x75, 0x6e, 0x64, 0x0a, 0x54, 0x68, 0x61, 0x74, 0x20, 0x74,
-    0x68, 0x65, 0x20, 0x63, 0x6f, 0x6c, 0x74, 0x20, 0x66, 0x72, 0x6f, 0x6d,
-    0x20, 0x4f, 0x6c, 0x64, 0x20, 0x52, 0x65, 0x67, 0x72, 0x65, 0x74, 0x20,
-    0x68, 0x61, 0x64, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x61, 0x77, 0x61, 0x79,
-    0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20, 0x68, 0x61, 0x64, 0x20, 0x6a, 0x6f,
-    0x69, 0x6e, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x69, 0x6c,
-    0x64, 0x20, 0x62, 0x75, 0x73, 0x68, 0x20, 0x68, 0x6f, 0x72, 0x73, 0x65,
-    0x73, 0x20, 0x2d, 0x2d, 0x20, 0x68, 0x65, 0x20, 0x77, 0x61, 0x73, 0x20,
-    0x77, 0x6f, 0x72, 0x74, 0x68, 0x20, 0x61, 0x20, 0x74, 0x68, 0x6f, 0x75,
-    0x73, 0x61, 0x6e, 0x64, 0x20, 0x70, 0x6f, 0x75, 0x6e, 0x64, 0x2c, 0x0a,
-    0x53, 0x6f, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
-    0x72, 0x61, 0x63, 0x6b, 0x73, 0x20, 0x68, 0x61, 0x64, 0x20, 0x67, 0x61,
-    0x74, 0x68, 0x65, 0x72, 0x65, 0x64, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68,
-    0x65, 0x20, 0x66, 0x72, 0x61, 0x79, 0x2e, 0x0a, 0x41, 0x6c, 0x6c, 0x20,
-    0x74, 0x68, 0x65, 0x20, 0x74, 0x72, 0x69, 0x65, 0x64, 0x20, 0x61, 0x6e,
-    0x64, 0x20, 0x6e, 0x6f, 0x74, 0x65, 0x64, 0x20, 0x72, 0x69, 0x64, 0x65,
-    0x72, 0x73, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20,
-    0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6e, 0x65, 0x61,
-    0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x61, 0x72, 0x0a, 0x48, 0x61,
-    0x64, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x65, 0x72, 0x65, 0x64, 0x20, 0x61,
-    0x74, 0x20, 0x74, 0x68, 0x65, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x73, 0x74,
-    0x65, 0x61, 0x64, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x6e, 0x69, 0x67, 0x68,
-    0x74, 0x2c, 0x0a, 0x46, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62,
-    0x75, 0x73, 0x68, 0x6d, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x20,
-    0x68, 0x61, 0x72, 0x64, 0x20, 0x72, 0x69, 0x64, 0x69, 0x6e, 0x67, 0x20,
-    0x77, 0x68, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x69,
-    0x6c, 0x64, 0x20, 0x62, 0x75, 0x73, 0x68, 0x20, 0x68, 0x6f, 0x72, 0x73,
-    0x65, 0x73, 0x20, 0x61, 0x72, 0x65, 0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20,
-    0x74, 0x68, 0x65, 0x20, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x2d, 0x68, 0x6f,
-    0x72, 0x73, 0x65, 0x20, 0x73, 0x6e, 0x75, 0x66, 0x66, 0x73, 0x20, 0x74,
-    0x68, 0x65, 0x20, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x20, 0x77, 0x69,
-    0x74, 0x68, 0x20, 0x64, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x00};
-
-static ArrayRef<char> BlockContent(BlockContentBytes);
-
 TEST(LinkGraphTest, Construction) {
   // Check that LinkGraph construction works as expected.
   LinkGraph G("foo", Triple("x86_64-apple-darwin"), 8, llvm::endianness::little,

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/MachOLinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/MachOLinkGraphTests.cpp
new file mode 100644
index 00000000000000..be922275be26f4
--- /dev/null
+++ b/llvm/unittests/ExecutionEngine/JITLink/MachOLinkGraphTests.cpp
@@ -0,0 +1,35 @@
+//===------ LinkGraphTests.cpp - Unit tests for core JITLink classes ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "JITLinkTestUtils.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ExecutionEngine/JITLink/JITLink.h"
+#include "llvm/ExecutionEngine/JITLink/MachO.h"
+
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::jitlink;
+
+TEST(MachOLinkGraphTest, GetStandardSections) {
+  // Check that LinkGraph construction works as expected.
+  LinkGraph G("foo", Triple("arm64-apple-darwin"), 8, llvm::endianness::little,
+              getGenericEdgeKindName);
+
+  auto &Data = getMachODefaultRWDataSection(G);
+  EXPECT_TRUE(Data.empty());
+  EXPECT_EQ(Data.getName(), orc::MachODataDataSectionName);
+  EXPECT_EQ(Data.getMemProt(), orc::MemProt::Read | orc::MemProt::Write);
+
+  auto &Text = getMachODefaultTextSection(G);
+  EXPECT_TRUE(Text.empty());
+  EXPECT_EQ(Text.getName(), orc::MachOTextTextSectionName);
+  EXPECT_EQ(Text.getMemProt(), orc::MemProt::Read | orc::MemProt::Exec);
+}

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp
index f0f3dd117c6f88..2b303f7a8c1a29 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/MemoryManagerErrorTests.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "JITLinkMocks.h"
+#include "JITLinkTestUtils.h"
 #include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h"
 
 #include "llvm/Testing/Support/Error.h"


        


More information about the llvm-commits mailing list