Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lld/test/wasm/lto/relocation-model.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions lld/wasm/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Copy link
Member

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?

Copy link
Collaborator Author

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.

else
c.RelocModel = Reloc::Static;

Expand Down