-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld][WebAssembly] LTO: Use PIC reloc model with dynamic imports #165342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-lld-wasm @llvm/pr-subscribers-lld Author: Sam Clegg (sbc100) ChangesFull diff: https://github.com/llvm/llvm-project/pull/165342.diff 2 Files Affected:
diff --git a/lld/test/wasm/lto/relocation-model.ll b/lld/test/wasm/lto/relocation-model.ll
index 8fe198d0c64e6..a042615b8fe1c 100644
--- a/lld/test/wasm/lto/relocation-model.ll
+++ b/lld/test/wasm/lto/relocation-model.ll
@@ -8,6 +8,11 @@
; RUN: wasm-ld %t.o -o %t_static.wasm -save-temps -r -mllvm -relocation-model=static
; RUN: llvm-readobj -r %t_static.wasm.lto.o | FileCheck %s --check-prefix=STATIC
+;; Linking with --unresolved-symbols=import-dynamic should also generate PIC
+;; code for external references.
+; RUN: wasm-ld %t.o -o %t_import.wasm -save-temps --experimental-pic --unresolved-symbols=import-dynamic
+; RUN: llvm-readobj -r %t_import.wasm.lto.o | FileCheck %s --check-prefix=PIC
+
; PIC: R_WASM_GLOBAL_INDEX_LEB foo
; STATIC: R_WASM_MEMORY_ADDR_LEB foo
diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp
index ae85f4693214b..668cdf21ea3ed 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -63,6 +63,12 @@ static lto::Config createConfig() {
c.RelocModel = std::nullopt;
else if (ctx.isPic)
c.RelocModel = Reloc::PIC_;
+ else if (ctx.arg.unresolvedSymbols == UnresolvedPolicy::ImportDynamic)
+ // With ImportDynamic we also need to use the PIC relocation model so that
+ // external symbols are references via the GOT.
+ // TODO(sbc): This should probably be Reloc::DynamicNoPIC, but the backend
+ // doesn't currently support that.
+ c.RelocModel = Reloc::PIC_;
else
c.RelocModel = Reloc::Static;
|
4e4528b to
fcdee61
Compare
| // external symbols are references via the GOT. | ||
| // TODO(sbc): This should probably be Reloc::DynamicNoPIC, but the backend | ||
| // doesn't currently support that. | ||
| c.RelocModel = Reloc::PIC_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the docs for import-dynamic need to be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentatio already talks about how the input file need to be PIC.. so this is really just a bugfix I think. The code better matches the docs now.
No description provided.