From: Dan Gohman Date: Wed, 5 Jun 2019 20:01:01 +0000 (+0000) Subject: [WebAssembly] Limit PIC support to the Emscripten target X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c16eb49bdc8b898bc19408487397bcc7e53411e;p=llvm [WebAssembly] Limit PIC support to the Emscripten target The current PIC support currently only works with Emscripten, so disable it for other targets. This is the PIC portion of https://reviews.llvm.org/D62542. Reviewed By: dschuff, sbc100 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362638 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 8b73e827856..937d272d213 100644 --- a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -83,13 +83,22 @@ extern "C" void LLVMInitializeWebAssemblyTarget() { // WebAssembly Lowering public interface. //===----------------------------------------------------------------------===// -static Reloc::Model getEffectiveRelocModel(Optional RM) { +static Reloc::Model getEffectiveRelocModel(Optional RM, + const Triple &TT) { if (!RM.hasValue()) { // Default to static relocation model. This should always be more optimial // than PIC since the static linker can determine all global addresses and // assume direct function calls. return Reloc::Static; } + + if (!TT.isOSEmscripten()) { + // Relocation modes other than static are currently implemented in a way + // that only works for Emscripten, so disable them if we aren't targeting + // Emscripten. + return Reloc::Static; + } + return *RM; } @@ -102,7 +111,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( : LLVMTargetMachine(T, TT.isArch64Bit() ? "e-m:e-p:64:64-i64:64-n32:64-S128" : "e-m:e-p:32:32-i64:64-n32:64-S128", - TT, CPU, FS, Options, getEffectiveRelocModel(RM), + TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT), getEffectiveCodeModel(CM, CodeModel::Large), OL), TLOF(new WebAssemblyTargetObjectFile()) { // WebAssembly type-checks instructions, but a noreturn function with a return diff --git a/test/CodeGen/WebAssembly/address-offsets.ll b/test/CodeGen/WebAssembly/address-offsets.ll index 4f522335907..7fe40a1dbec 100644 --- a/test/CodeGen/WebAssembly/address-offsets.ll +++ b/test/CodeGen/WebAssembly/address-offsets.ll @@ -6,7 +6,7 @@ ; a variety of circumstances. target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" @g = external global [0 x i32], align 4 diff --git a/test/CodeGen/WebAssembly/call-pic.ll b/test/CodeGen/WebAssembly/call-pic.ll index 53a397ac769..631fedbfb24 100644 --- a/test/CodeGen/WebAssembly/call-pic.ll +++ b/test/CodeGen/WebAssembly/call-pic.ll @@ -1,7 +1,7 @@ ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -relocation-model=pic -fast-isel=1 | FileCheck %s ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -relocation-model=pic -fast-isel=0 | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" declare i32 @foo() declare i32 @bar() diff --git a/test/CodeGen/WebAssembly/load-store-pic.ll b/test/CodeGen/WebAssembly/load-store-pic.ll index 2f7f34ddf6f..9090c3520b5 100644 --- a/test/CodeGen/WebAssembly/load-store-pic.ll +++ b/test/CodeGen/WebAssembly/load-store-pic.ll @@ -6,7 +6,7 @@ ; We test here both with and without fast-isel. target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" -target triple = "wasm32-unknown-unknown" +target triple = "wasm32-unknown-emscripten" @hidden_global = external hidden global i32 @hidden_global_array = external hidden global [10 x i32]