[ORC] Honor linker private global prefix on symbol names.

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.
This commit is contained in:
Lang Hames 2020-06-13 19:03:21 -07:00
parent e54828ad47
commit 498dd745f5
2 changed files with 20 additions and 2 deletions

View 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;
}

View 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
}