File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change 88; RUN: wasm-ld %t.o -o %t_static.wasm -save-temps -r -mllvm -relocation-model=static
99; RUN: llvm-readobj -r %t_static.wasm.lto.o | FileCheck %s --check-prefix=STATIC
1010
11+ ;; Linking with --unresolved-symbols=import-dynamic should also generate PIC
12+ ;; code for external references.
13+ ; RUN: wasm-ld %t.o -o %t_import.wasm -save-temps --experimental-pic --unresolved-symbols=import-dynamic
14+ ; RUN: llvm-readobj -r %t_import.wasm.lto.o | FileCheck %s --check-prefix=PIC
15+
1116; PIC: R_WASM_GLOBAL_INDEX_LEB foo
1217; STATIC: R_WASM_MEMORY_ADDR_LEB foo
1318
Original file line number Diff line number Diff line change @@ -63,6 +63,12 @@ static lto::Config createConfig() {
6363 c.RelocModel = std::nullopt ;
6464 else if (ctx.isPic )
6565 c.RelocModel = Reloc::PIC_;
66+ else if (ctx.arg .unresolvedSymbols == UnresolvedPolicy::ImportDynamic)
67+ // With ImportDynamic we also need to use the PIC relocation model so that
68+ // external symbols are references via the GOT.
69+ // TODO(sbc): This should probably be Reloc::DynamicNoPIC, but the backend
70+ // doesn't currently support that.
71+ c.RelocModel = Reloc::PIC_;
6672 else
6773 c.RelocModel = Reloc::Static;
6874
You can’t perform that action at this time.
0 commit comments