[llvm] [WebAssembly] Add path to PIC mode for wasm tables (PR #67545)
Paulo Matos via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 04:52:17 PDT 2023
https://github.com/pmatos created https://github.com/llvm/llvm-project/pull/67545
Currently tables cannot be shared between compilation units, therefore
no special treatment is needed for tables.
Fixes #65191
>From 6dc3864d925bc878ae28efaf508ff5dc7ae07147 Mon Sep 17 00:00:00 2001
From: Paulo Matos <pmatos at igalia.com>
Date: Wed, 27 Sep 2023 13:50:39 +0200
Subject: [PATCH] [WebAssembly] Add path to PIC mode for wasm tables
Currently tables cannot be shared between compilation units, therefore
no special treatment is needed for tables.
Fixes #65191
---
.../Target/WebAssembly/WebAssemblyISelLowering.cpp | 10 ++++++++--
llvm/test/MC/WebAssembly/reloc-pic.s | 12 ++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index fd154a90edef1d9..b67615d82d04a54 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1724,8 +1724,14 @@ 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();
+ // is PIC but not a WebAssembly table.
+ // Since WebAssembly tables cannot yet be shared accross modules, we don't need special
+ // treatment for tables in PIC mode.
+ if (isPositionIndependent() &&
+ !(GV->getValueType()->isArrayTy() &&
+ WebAssembly::isWebAssemblyReferenceType(GV->getValueType()->getArrayElementType()))) {
+
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..1758820da93479a 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: [ UNDEFINED ]
+# 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