Skip to content

Commit 059f044

Browse files
committed
[ORC] Propagate weak & hidden flags when creating lazy reexports, redirectables.
Updates JITLinkRedirectableSymbolManager to take alias flags into account when setting the scope and linkage of the created stubs (weak aliases get now get weak linkage, hidden stubs get hidden visibility). Updates lazyReexports to propagate alias flags (rather than trampoline flags) when building the initial destinations map for the redirectable symbols manager. Together these changes allow the LazyObjectLinkingLayer to link objects containing weak and hidden symbols.
1 parent 7620011 commit 059f044

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define weak void @bar() {
2+
entry:
3+
ret void
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define hidden void @baz() {
2+
entry:
3+
ret void
4+
}

compiler-rt/test/orc/TestCases/Generic/lazy-link.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
; RUN: rm -rf %t && mkdir -p %t
77
; RUN: %clang -c -o %t/foo.o %S/Inputs/foo-ret-42.ll
88
; RUN: %clang -c -o %t/x.o %S/Inputs/var-x-42.ll
9+
; RUN: %clang -c -o %t/bar.o %S/Inputs/bar-ret-void-weak.ll
10+
; RUN: %clang -c -o %t/baz.o %S/Inputs/baz-ret-void-hidden.ll
911
; RUN: %clang -c -o %t/main.o %s
1012
; RUN: %llvm_jitlink -noexec -show-linked-files %t/main.o -lazy %t/foo.o \
11-
; RUN: -lazy %t/x.o | FileCheck %s
13+
; RUN: -lazy %t/x.o -lazy %t/bar.o -lazy %t/baz.o | FileCheck %s
1214
;
1315
; UNSUPPORTED: system-windows
1416
; REQUIRES: target={{(arm|aarch|x86_)64.*}}
@@ -21,9 +23,15 @@
2123
declare i32 @foo()
2224
@x = external global i32
2325

26+
declare void @bar()
27+
declare hidden void @baz()
28+
29+
2430
define i32 @main(i32 %argc, ptr %argv) {
2531
entry:
2632
%foo_result = call i32 @foo()
33+
call void @bar()
34+
call void @baz()
2735
%x_val = load i32, ptr @x
2836
%result = add nsw i32 %foo_result, %x_val
2937
ret i32 %result

llvm/lib/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ void JITLinkRedirectableSymbolManager::emitRedirectableSymbols(
4747
Ptr.setScope(jitlink::Scope::Hidden);
4848
auto &Stub = PtrJumpStubCreator(*G, StubsSection, Ptr);
4949
Stub.setName(Name);
50-
Stub.setScope(jitlink::Scope::Default);
50+
Stub.setScope(Def.getFlags().isExported() ? jitlink::Scope::Default
51+
: jitlink::Scope::Hidden);
52+
Stub.setLinkage(!Def.getFlags().isWeak() ? jitlink::Linkage::Strong
53+
: jitlink::Linkage::Weak);
5154
NewSymbols[std::move(PtrName)] = JITSymbolFlags();
5255
}
5356

llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void LazyReexportsManager::emitRedirectableSymbols(
387387
SymbolMap Redirs;
388388
size_t I = 0;
389389
for (auto &[Name, AI] : Reexports)
390-
Redirs[Name] = (*ReentryPoints)[I++];
390+
Redirs[Name] = {(*ReentryPoints)[I++].getAddress(), AI.AliasFlags};
391391

392392
I = 0;
393393
if (!Reexports.empty()) {

0 commit comments

Comments
 (0)