-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WebAssembly] Add path to PIC mode for wasm tables #67545
Conversation
@llvm/pr-subscribers-backend-webassembly @llvm/pr-subscribers-mc ChangesCurrently tables cannot be shared between compilation units, therefore Fixes #65191 Full diff: https://github.com/llvm/llvm-project/pull/67545.diff 2 Files Affected:
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
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that shouldAssumeDSOLocal() is always true for table symbols?
Why can't tables be imported/exported like any other symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it stands tables need to be always declared with static. Symbols cannot be exported. I will get around to implementing it at some point to fix #64532.
6dc3864
to
b8d0c58
Compare
Currently tables cannot be shared between compilation units, therefore no special treatment is needed for tables. Fixes llvm#65191
b8d0c58
to
0730f2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % a couple more comments
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something is OK to do in lit test? I've not seen this sed pattern before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have at least test in WebAssembly (tls-local-exec.ll) using sed. There are many in RISCV which uses sed to replace types depending on current running arch, etc. We need this here to ensure that without reference types we don't add a table and if we do have reference types, the result is correct. Alternatively we need another test file. I am happy to do that if you're not keen on sed but sed is very much used together with lit tests in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will wait for a further thumbs up from you if you're happy with introducing this sed pattern into the tests.
Currently tables cannot be shared between compilation units, therefore
no special treatment is needed for tables.
Fixes #65191