[ORC] Honor linker private global prefix on symbol names.
authorLang Hames <lhames@gmail.com>
Sun, 14 Jun 2020 02:03:21 +0000 (19:03 -0700)
committerLang Hames <lhames@gmail.com>
Mon, 15 Jun 2020 17:28:36 +0000 (10:28 -0700)
If a symbol name begins with the linker private global prefix (as
described by the DataLayout) then it should be treated as non-exported,
regardless of its LLVM IR visibility value.

llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp
llvm/test/ExecutionEngine/OrcLazy/private_linkage.ll

index b445d3d..0f6f9ef 100644 (file)
@@ -20,6 +20,8 @@
 using namespace llvm;
 
 JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) {
+  assert(GV.hasName() && "Can't get flags for anonymous symbol");
+
   JITSymbolFlags Flags = JITSymbolFlags::None;
   if (GV.hasWeakLinkage() || GV.hasLinkOnceLinkage())
     Flags |= JITSymbolFlags::Weak;
@@ -34,6 +36,16 @@ JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) {
            isa<Function>(cast<GlobalAlias>(GV).getAliasee()))
     Flags |= JITSymbolFlags::Callable;
 
+  // Check for a linker-private-global-prefix on the symbol name, in which
+  // case it must be marked as non-exported.
+  if (auto *M = GV.getParent()) {
+    const auto &DL = M->getDataLayout();
+    StringRef LPGP = DL.getLinkerPrivateGlobalPrefix();
+    if (!LPGP.empty() && GV.getName().front() == '\01' &&
+        GV.getName().substr(1).startswith(LPGP))
+      Flags &= ~JITSymbolFlags::Exported;
+  }
+
   return Flags;
 }
 
index 11813dd..c8f1531 100644 (file)
@@ -1,12 +1,18 @@
 ; RUN: lli -jit-kind=orc-lazy %s
 
-define private void @_ZL3foov() {
+define private void @foo() {
+entry:
+  ret void
+}
+
+define void @"\01l_bar"() {
 entry:
   ret void
 }
 
 define i32 @main(i32 %argc, i8** nocapture readnone %argv) {
 entry:
-  tail call void @_ZL3foov()
+  call void @foo()
+  call void @"\01l_bar"()
   ret i32 0
 }