Skip to content

[lld][WebAssembly] Update incorrect assertion in global relocation code - #215929

Merged
sbc100 merged 1 commit into
llvm:mainfrom
sbc100:fix-lld-wasm-extended-const-tls
Aug 13, 2026
Merged

[lld][WebAssembly] Update incorrect assertion in global relocation code#215929
sbc100 merged 1 commit into
llvm:mainfrom
sbc100:fix-lld-wasm-extended-const-tls

Conversation

@sbc100

@sbc100 sbc100 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

When extended-const is enabled, non-TLS global relocations are handled via extended constant expressions. However, TLS GOT entries still require runtime relocation code in __wasm_apply_global_tls_relocs because TLS global addresses depend on __tls_base.

Allow GlobalSection::generateRelocationCode to be called when TLS is true even if ctx.arg.extendedConst is set.

When extended-const is enabled, non-TLS global relocations are handled
via extended constant expressions. However, TLS GOT entries still
require runtime relocation code in `__wasm_apply_global_tls_relocs`
because TLS global addresses depend on `__tls_base`.

Allow `GlobalSection::generateRelocationCode` to be called when `TLS` is
true even if `ctx.arg.extendedConst` is set.
@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-lld-wasm

@llvm/pr-subscribers-lld

Author: Sam Clegg (sbc100)

Changes

When extended-const is enabled, non-TLS global relocations are handled via extended constant expressions. However, TLS GOT entries still require runtime relocation code in __wasm_apply_global_tls_relocs because TLS global addresses depend on __tls_base.

Allow GlobalSection::generateRelocationCode to be called when TLS is true even if ctx.arg.extendedConst is set.


Full diff: https://github.com/llvm/llvm-project/pull/215929.diff

2 Files Affected:

  • (modified) lld/test/wasm/tls-init-symbols.s (+1)
  • (modified) lld/wasm/SyntheticSections.cpp (+1-1)
diff --git a/lld/test/wasm/tls-init-symbols.s b/lld/test/wasm/tls-init-symbols.s
index 601766d681d85..944c9c349701a 100644
--- a/lld/test/wasm/tls-init-symbols.s
+++ b/lld/test/wasm/tls-init-symbols.s
@@ -9,6 +9,7 @@
 
 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
 # RUN: wasm-ld -no-gc-sections --shared-memory -o %t.wasm %t.o
+# RUN: wasm-ld -no-gc-sections --shared-memory --extra-features=extended-const -o %t.extended.wasm %t.o
 # RUN: obj2yaml %t.wasm | FileCheck %s
 # RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
 
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 050f61c7f5c56..b6d572277e7cd 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -474,7 +474,7 @@ void GlobalSection::addInternalGOTEntry(Symbol *sym) {
 }
 
 void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const {
-  assert(!ctx.arg.extendedConst);
+  assert(!ctx.arg.extendedConst || TLS);
   bool is64 = ctx.arg.is64.value_or(false);
   unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD : WASM_OPCODE_I32_ADD;
 

@sbc100
sbc100 merged commit 82ea231 into llvm:main Aug 13, 2026
15 checks passed
@sbc100
sbc100 deleted the fix-lld-wasm-extended-const-tls branch August 13, 2026 16:02
zhangweize9-cyber pushed a commit to zhangweize9-cyber/llvm-project that referenced this pull request Aug 16, 2026
…de (llvm#215929)

When extended-const is enabled, non-TLS global relocations are handled
via extended constant expressions. However, TLS GOT entries still
require runtime relocation code in `__wasm_apply_global_tls_relocs`
because TLS global addresses depend on `__tls_base`.

Allow `GlobalSection::generateRelocationCode` to be called when `TLS` is
true even if `ctx.arg.extendedConst` is set.
@sbc100 sbc100 added this to the LLVM 23.x Release milestone Aug 19, 2026
@sbc100

sbc100 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

/cherry-pick 82ea231

@llvmbot

llvmbot commented Aug 19, 2026

Copy link
Copy Markdown
Member

/pull-request #217380

dyung pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 20, 2026
…de (llvm#215929)

When extended-const is enabled, non-TLS global relocations are handled
via extended constant expressions. However, TLS GOT entries still
require runtime relocation code in `__wasm_apply_global_tls_relocs`
because TLS global addresses depend on `__tls_base`.

Allow `GlobalSection::generateRelocationCode` to be called when `TLS` is
true even if `ctx.arg.extendedConst` is set.

(cherry picked from commit 82ea231)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

3 participants