[lld] [lld][WebAssembly] Do not relocate ABSOLUTE symbols (PR #153763)
YAMAMOTO Takashi via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 17 18:08:47 PDT 2025
https://github.com/yamt updated https://github.com/llvm/llvm-project/pull/153763
>From c5f1d3f41160771d8cd9faca2c0b5beb4e5cc657 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Fri, 15 Aug 2025 17:15:22 +0900
Subject: [PATCH 1/2] [lld][WebAssembly] Do not relocate ABSOLUTE symbols
Fixes https://github.com/llvm/llvm-project/pull/153537
---
lld/wasm/SyntheticSections.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index e1192706ea913..6c1c4391ea0d7 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -442,6 +442,8 @@ void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const {
for (const Symbol *sym : internalGotSymbols) {
if (TLS != sym->isTLS())
continue;
+ if (sym->flags & WASM_SYMBOL_ABSOLUTE)
+ continue;
if (auto *d = dyn_cast<DefinedData>(sym)) {
// Get __memory_base
@@ -503,7 +505,8 @@ void GlobalSection::writeBody() {
bool useExtendedConst = false;
uint32_t globalIdx;
int64_t offset;
- if (ctx.arg.extendedConst && ctx.isPic) {
+ if (ctx.arg.extendedConst && ctx.isPic &&
+ (sym->flags & WASM_SYMBOL_ABSOLUTE) == 0) {
if (auto *d = dyn_cast<DefinedData>(sym)) {
if (!sym->isTLS()) {
globalIdx = ctx.sym.memoryBase->getGlobalIndex();
>From af06b910579c97bfc6d9c4b722c6522ce59267c8 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Mon, 18 Aug 2025 10:08:15 +0900
Subject: [PATCH 2/2] add a test
---
lld/test/wasm/pie.s | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/lld/test/wasm/pie.s b/lld/test/wasm/pie.s
index 21eac79207318..23510b52f8b50 100644
--- a/lld/test/wasm/pie.s
+++ b/lld/test/wasm/pie.s
@@ -41,6 +41,11 @@ foo:
drop
global.get __stack_pointer
+ i32.load 0
+ call_indirect () -> (i32)
+ drop
+
+ global.get __wasm_first_page_end at GOT
end_function
get_data_address:
@@ -173,17 +178,23 @@ _start:
# EXTENDED-CONST-NEXT: Type: I32
# EXTENDED-CONST-NEXT: Mutable: false
# EXTENDED-CONST-NEXT: InitExpr:
+# EXTENDED-CONST-NEXT: Opcode: I32_CONST
+# EXTENDED-CONST-NEXT: Value: 65536
+# EXTENDED-CONST-NEXT: - Index: 7
+# EXTENDED-CONST-NEXT: Type: I32
+# EXTENDED-CONST-NEXT: Mutable: false
+# EXTENDED-CONST-NEXT: InitExpr:
# EXTENDED-CONST-NEXT: Extended: true
# This instruction sequence decodes to:
# (global.get[0x23] 0x1 i32.const[0x41] 0x0C i32.add[0x6A] end[0x0b])
# EXTENDED-CONST-NEXT: Body: 2301410C6A0B
-# EXTENDED-CONST-NEXT: - Index: 7
+# EXTENDED-CONST-NEXT: - Index: 8
# EXTENDED-CONST-NEXT: Type: I32
# EXTENDED-CONST-NEXT: Mutable: false
# EXTENDED-CONST-NEXT: InitExpr:
# EXTENDED-CONST-NEXT: Opcode: GLOBAL_GET
# EXTENDED-CONST-NEXT: Index: 2
-# EXTENDED-CONST-NEXT: - Index: 8
+# EXTENDED-CONST-NEXT: - Index: 9
# EXTENDED-CONST-NEXT: Type: I32
# EXTENDED-CONST-NEXT: Mutable: false
# EXTENDED-CONST-NEXT: InitExpr:
More information about the llvm-commits
mailing list