[llvm] cfa5fd4 - [ORC] Tidy up MachOPlatform's references to ORC runtime registration functions.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 13:33:17 PST 2023


Author: Lang Hames
Date: 2023-01-12T13:33:11-08:00
New Revision: cfa5fd4849e82d6ac83590abe87dfdbbdfd305be

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

LOG: [ORC] Tidy up MachOPlatform's references to ORC runtime registration functions.

Use an private struct, RuntimeFunction, to to keep the name and address of each
registration function together, and rename the member variables with their purpose
rather than the full name of the function in the runtime.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
    llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index 197905e980c66..6c67889b2cf7e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -209,15 +209,30 @@ class MachOPlatform : public Platform {
   SymbolStringPtr MachOHeaderStartSymbol;
   std::atomic<PlatformState> State{BootstrapPhase1};
 
-  ExecutorAddr orc_rt_macho_platform_bootstrap;
-  ExecutorAddr orc_rt_macho_platform_shutdown;
-  ExecutorAddr orc_rt_macho_register_ehframe_section;
-  ExecutorAddr orc_rt_macho_deregister_ehframe_section;
-  ExecutorAddr orc_rt_macho_register_jitdylib;
-  ExecutorAddr orc_rt_macho_deregister_jitdylib;
-  ExecutorAddr orc_rt_macho_register_object_platform_sections;
-  ExecutorAddr orc_rt_macho_deregister_object_platform_sections;
-  ExecutorAddr orc_rt_macho_create_pthread_key;
+  struct RuntimeFunction {
+    RuntimeFunction(SymbolStringPtr Name) : Name(std::move(Name)) {}
+    SymbolStringPtr Name;
+    ExecutorAddr Addr;
+  };
+
+  RuntimeFunction PlatformBootstrap{
+      ES.intern("___orc_rt_macho_platform_bootstrap")};
+  RuntimeFunction PlatformShutdown{
+      ES.intern("___orc_rt_macho_platform_shutdown")};
+  RuntimeFunction RegisterEHFrameSection{
+      ES.intern("___orc_rt_macho_register_ehframe_section")};
+  RuntimeFunction DeregisterEHFrameSection{
+      ES.intern("___orc_rt_macho_deregister_ehframe_section")};
+  RuntimeFunction RegisterJITDylib{
+      ES.intern("___orc_rt_macho_register_jitdylib")};
+  RuntimeFunction DeregisterJITDylib{
+      ES.intern("___orc_rt_macho_deregister_jitdylib")};
+  RuntimeFunction RegisterObjectPlatformSections{
+      ES.intern("___orc_rt_macho_register_object_platform_sections")};
+  RuntimeFunction DeregisterObjectPlatformSections{
+      ES.intern("___orc_rt_macho_deregister_object_platform_sections")};
+  RuntimeFunction CreatePThreadKey{
+      ES.intern("___orc_rt_macho_create_pthread_key")};
 
   DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 7ba03869d8304..d85e8944af2b8 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -349,10 +349,8 @@ MachOPlatform::MachOPlatform(
   // Force linking of eh-frame registration functions.
   if (auto Err2 = lookupAndRecordAddrs(
           ES, LookupKind::Static, makeJITDylibSearchOrder(&PlatformJD),
-          {{ES.intern("___orc_rt_macho_register_ehframe_section"),
-            &orc_rt_macho_register_ehframe_section},
-           {ES.intern("___orc_rt_macho_deregister_ehframe_section"),
-            &orc_rt_macho_deregister_ehframe_section}})) {
+          {{RegisterEHFrameSection.Name, &RegisterEHFrameSection.Addr},
+           {DeregisterEHFrameSection.Name, &DeregisterEHFrameSection.Addr}})) {
     Err = std::move(Err2);
     return;
   }
@@ -574,27 +572,22 @@ void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
 Error MachOPlatform::bootstrapMachORuntime(JITDylib &PlatformJD) {
   if (auto Err = lookupAndRecordAddrs(
           ES, LookupKind::Static, makeJITDylibSearchOrder(&PlatformJD),
-          {{ES.intern("___orc_rt_macho_platform_bootstrap"),
-            &orc_rt_macho_platform_bootstrap},
-           {ES.intern("___orc_rt_macho_platform_shutdown"),
-            &orc_rt_macho_platform_shutdown},
-           {ES.intern("___orc_rt_macho_register_jitdylib"),
-            &orc_rt_macho_register_jitdylib},
-           {ES.intern("___orc_rt_macho_deregister_jitdylib"),
-            &orc_rt_macho_deregister_jitdylib},
-           {ES.intern("___orc_rt_macho_register_object_platform_sections"),
-            &orc_rt_macho_register_object_platform_sections},
-           {ES.intern("___orc_rt_macho_deregister_object_platform_sections"),
-            &orc_rt_macho_deregister_object_platform_sections},
-           {ES.intern("___orc_rt_macho_create_pthread_key"),
-            &orc_rt_macho_create_pthread_key}}))
+          {{PlatformBootstrap.Name, &PlatformBootstrap.Addr},
+           {PlatformShutdown.Name, &PlatformShutdown.Addr},
+           {RegisterJITDylib.Name, &RegisterJITDylib.Addr},
+           {DeregisterJITDylib.Name, &DeregisterJITDylib.Addr},
+           {RegisterObjectPlatformSections.Name,
+            &RegisterObjectPlatformSections.Addr},
+           {DeregisterObjectPlatformSections.Name,
+            &DeregisterObjectPlatformSections.Addr},
+           {CreatePThreadKey.Name, &CreatePThreadKey.Addr}}))
     return Err;
 
-  return ES.callSPSWrapper<void()>(orc_rt_macho_platform_bootstrap);
+  return ES.callSPSWrapper<void()>(PlatformBootstrap.Addr);
 }
 
 Expected<uint64_t> MachOPlatform::createPThreadKey() {
-  if (!orc_rt_macho_create_pthread_key)
+  if (!CreatePThreadKey.Addr)
     return make_error<StringError>(
         "Attempting to create pthread key in target, but runtime support has "
         "not been loaded yet",
@@ -602,7 +595,7 @@ Expected<uint64_t> MachOPlatform::createPThreadKey() {
 
   Expected<uint64_t> Result(0);
   if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
-          orc_rt_macho_create_pthread_key, Result))
+          CreatePThreadKey.Addr, Result))
     return std::move(Err);
   return Result;
 }
@@ -688,9 +681,9 @@ Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
   G.allocActions().push_back(
       {cantFail(
            WrapperFunctionCall::Create<SPSArgList<SPSString, SPSExecutorAddr>>(
-               MP.orc_rt_macho_register_jitdylib, JD.getName(), HeaderAddr)),
+               MP.RegisterJITDylib.Addr, JD.getName(), HeaderAddr)),
        cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
-           MP.orc_rt_macho_deregister_jitdylib, HeaderAddr))});
+           MP.DeregisterJITDylib.Addr, HeaderAddr))});
   return Error::success();
 }
 
@@ -875,10 +868,10 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
       G.allocActions().push_back(
           {cantFail(
                WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
-                   MP.orc_rt_macho_register_ehframe_section, R.getRange())),
+                   MP.RegisterEHFrameSection.Addr, R.getRange())),
            cantFail(
                WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
-                   MP.orc_rt_macho_deregister_ehframe_section, R.getRange()))});
+                   MP.DeregisterEHFrameSection.Addr, R.getRange()))});
   }
 
   // Get a pointer to the thread data section if there is one. It will be used
@@ -978,12 +971,12 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
     G.allocActions().push_back(
         {cantFail(
              WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
-                 MP.orc_rt_macho_register_object_platform_sections, *HeaderAddr,
+                 MP.RegisterObjectPlatformSections.Addr, *HeaderAddr,
                  MachOPlatformSecs)),
          cantFail(
              WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
-                 MP.orc_rt_macho_deregister_object_platform_sections,
-                 *HeaderAddr, MachOPlatformSecs))});
+                 MP.DeregisterObjectPlatformSections.Addr, *HeaderAddr,
+                 MachOPlatformSecs))});
   }
 
   return Error::success();


        


More information about the llvm-commits mailing list