[llvm] a29e8ef - [WebAssembly] Add path to PIC mode for wasm tables (#67545)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 23:00:26 PDT 2023
Author: Paulo Matos
Date: 2023-10-03T08:00:21+02:00
New Revision: a29e8ef1c36001ff19392713c8be4bd277e9b5d7
URL: https://github.com/llvm/llvm-project/commit/a29e8ef1c36001ff19392713c8be4bd277e9b5d7
DIFF: https://github.com/llvm/llvm-project/commit/a29e8ef1c36001ff19392713c8be4bd277e9b5d7.diff
LOG: [WebAssembly] Add path to PIC mode for wasm tables (#67545)
Currently tables cannot be shared between compilation units, therefore
no special treatment is needed for tables.
Fixes #65191
Added:
Modified:
llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/test/MC/WebAssembly/reloc-pic.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index 4a329bef4681995..86fb99cc98a9055 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -71,8 +71,7 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
// that is a reference type.
wasm::ValType ValTy;
bool IsTable = false;
- if (GlobalVT->isArrayTy() && WebAssembly::isWebAssemblyReferenceType(
- GlobalVT->getArrayElementType())) {
+ if (WebAssembly::isWebAssemblyTableType(GlobalVT)) {
IsTable = true;
const Type *ElTy = GlobalVT->getArrayElementType();
if (WebAssembly::isWebAssemblyExternrefType(ElTy))
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index d59fcb3c1b59670..a8860477a2472cf 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -28,14 +28,16 @@ namespace WebAssembly {
/// Return true if this is a WebAssembly Externref Type.
inline bool isWebAssemblyExternrefType(const Type *Ty) {
- return Ty->getPointerAddressSpace() ==
- WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
+ return Ty->isPointerTy() &&
+ Ty->getPointerAddressSpace() ==
+ WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
}
/// Return true if this is a WebAssembly Funcref Type.
inline bool isWebAssemblyFuncrefType(const Type *Ty) {
- return Ty->getPointerAddressSpace() ==
- WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
+ return Ty->isPointerTy() &&
+ Ty->getPointerAddressSpace() ==
+ WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
}
/// Return true if this is a WebAssembly Reference Type.
@@ -43,6 +45,12 @@ inline bool isWebAssemblyReferenceType(const Type *Ty) {
return isWebAssemblyExternrefType(Ty) || isWebAssemblyFuncrefType(Ty);
}
+/// Return true if the table represents a WebAssembly table type.
+inline bool isWebAssemblyTableType(const Type *Ty) {
+ return Ty->isArrayTy() &&
+ isWebAssemblyReferenceType(Ty->getArrayElementType());
+}
+
// Convert StringRef to ValType / HealType / BlockType
MVT parseMVT(StringRef Type);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index fd154a90edef1d9..61cfcdc914cdb93 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1724,8 +1724,11 @@ SDValue WebAssemblyTargetLowering::LowerGlobalAddress(SDValue Op,
fail(DL, DAG, "Invalid address space for WebAssembly target");
unsigned OperandFlags = 0;
- if (isPositionIndependent()) {
- const GlobalValue *GV = GA->getGlobal();
+ const GlobalValue *GV = GA->getGlobal();
+ // Since WebAssembly tables cannot yet be shared accross modules, we don't
+ // need special treatment for tables in PIC mode.
+ if (isPositionIndependent() &&
+ !WebAssembly::isWebAssemblyTableType(GV->getValueType())) {
if (getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV)) {
MachineFunction &MF = DAG.getMachineFunction();
MVT PtrVT = getPointerTy(MF.getDataLayout());
diff --git a/llvm/test/MC/WebAssembly/reloc-pic.s b/llvm/test/MC/WebAssembly/reloc-pic.s
index dd5d315cc2ce03f..974d6cb8969890d 100644
--- a/llvm/test/MC/WebAssembly/reloc-pic.s
+++ b/llvm/test/MC/WebAssembly/reloc-pic.s
@@ -1,5 +1,5 @@
-# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj < %s | obj2yaml | FileCheck %s
-# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj < %s | obj2yaml | FileCheck --check-prefix=REF %s
+# RUN: sed -e '/^REF-/d' %s | llvm-mc -triple=wasm32-unknown-unknown -filetype=obj | obj2yaml | FileCheck %s
+# RUN: sed -e 's/^REF-//g' %s | llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj | obj2yaml | FileCheck --check-prefix=REF %s
# Verify that @GOT relocation entryes result in R_WASM_GLOBAL_INDEX_LEB against
# against the corrsponding function or data symbol and that the corresponding
@@ -50,6 +50,9 @@ hidden_func:
#.hidden hidden_data
.size default_data, 4
+REF-mytable:
+REF-.tabletype mytable, externref
+
# CHECK: --- !WASM
# CHECK-NEXT: FileHeader:
# CHECK-NEXT: Version: 0x1
@@ -209,6 +212,11 @@ hidden_func:
# CHECK-NEXT: Function: 5
# REF: - Index: 10
# REF-NEXT: Kind: TABLE
+# REF-NEXT: Name: mytable
+# REF-NEXT: Flags: [ BINDING_LOCAL ]
+# REF-NEXT: Table: 1
+# REF-NEXT: - Index: 11
+# REF-NEXT: Kind: TABLE
# REF-NEXT: Name: __indirect_function_table
# REF-NEXT: Flags: [ UNDEFINED, NO_STRIP ]
# REF-NEXT: Table: 0
More information about the llvm-commits
mailing list