Skip to content

Conversation

yamt
Copy link
Contributor

@yamt yamt commented Aug 15, 2025

Fixes #153759

@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2025

@llvm/pr-subscribers-lld-wasm

Author: YAMAMOTO Takashi (yamt)

Changes

Fixes #153537


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

1 Files Affected:

  • (modified) lld/wasm/SyntheticSections.cpp (+4-1)
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();

@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2025

@llvm/pr-subscribers-lld

Author: YAMAMOTO Takashi (yamt)

Changes

Fixes #153537


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

1 Files Affected:

  • (modified) lld/wasm/SyntheticSections.cpp (+4-1)
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();

@yamt yamt changed the title [lld][WebAssembly] do not relocate ABOSULTE symbols [lld][WebAssembly] do not relocate ABSOLUTE symbols Aug 15, 2025
@yamt yamt force-pushed the wasm-ld-absolute-reloc branch from 0196c11 to 9aa3bf1 Compare August 15, 2025 08:35
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this? Perhaps one of the existing tests for internal GOT symbols could have a reference to an absolute symbol (the page size symbol maybe?) added?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do this 2 lines up before the TLS check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? just because it can be slightly cheaper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sbc100 sbc100 changed the title [lld][WebAssembly] do not relocate ABSOLUTE symbols [lld][WebAssembly] Do not relocate ABSOLUTE symbols Aug 15, 2025
@yamt yamt force-pushed the wasm-ld-absolute-reloc branch 2 times, most recently from af06b91 to 4766075 Compare August 18, 2025 01:25
@yamt
Copy link
Contributor Author

yamt commented Aug 18, 2025

Can we add a test for this? Perhaps one of the existing tests for internal GOT symbols could have a reference to an absolute symbol (the page size symbol maybe?) added?

i added a test.

@yamt yamt force-pushed the wasm-ld-absolute-reloc branch from 4766075 to 08fde96 Compare August 18, 2025 01:33
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % comment

@sbc100 sbc100 merged commit 9247be8 into llvm:main Aug 19, 2025
9 checks passed
@sbc100
Copy link
Collaborator

sbc100 commented Aug 19, 2025

This causes a bunch of test failures on the emscripten waterfall, mostly lsan tests.

I'm guessing that not all symbols we add with addOptionalDataSymbol and/or addSyntheticDataSymbol should be treated as absolute like this.

I think we should revert until we can figure out the best approach here.

sbc100 added a commit that referenced this pull request Aug 19, 2025
sbc100 added a commit that referenced this pull request Aug 19, 2025
Reverts #153763

This caused a bunch of failures on the emscripten waterfall,
specifically most of the lsan tests started failing.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 19, 2025
…s" (#154371)

Reverts llvm/llvm-project#153763

This caused a bunch of failures on the emscripten waterfall,
specifically most of the lsan tests started failing.
@yamt
Copy link
Contributor Author

yamt commented Aug 20, 2025

This causes a bunch of test failures on the emscripten waterfall, mostly lsan tests.

where can i see them?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 20, 2025

https://ci.chromium.org/ui/p/emscripten-releases/builders/luci.emscripten-releases.ci/linux-test-suites

Looks like all the tests that use lsan + dynamic linking are reporting false leaks:

FAIL: test_dylink_i64_invoke_rtld_local_no_bigint (test_core.asan)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/chrome-bot/.cache/vpython-root.1000/store/cpython+tkj8tpr2n0oj8m0t270p0m71s0/contents/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
    yield
  File "/home/chrome-bot/.cache/vpython-root.1000/store/cpython+tkj8tpr2n0oj8m0t270p0m71s0/contents/lib/python3.8/unittest/case.py", line 676, in run
    self._callTestMethod(testMethod)
  File "/home/chrome-bot/.cache/vpython-root.1000/store/cpython+tkj8tpr2n0oj8m0t270p0m71s0/contents/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
    method()
  File "/b/s/w/ir/x/w/install/emscripten/test/common.py", line 917, in resulting_test
    return func(self, *args)
  File "/b/s/w/ir/x/w/install/emscripten/test/common.py", line 576, in metafunc
    f(self, *args, **kwargs)
  File "/b/s/w/ir/x/w/install/emscripten/test/test_core.py", line 153, in decorated
    return func(self, *args, **kwargs)
  File "/b/s/w/ir/x/w/install/emscripten/test/test_core.py", line 4504, in test_dylink_i64_invoke
    self.dylink_test(r'''\
  File "/b/s/w/ir/x/w/install/emscripten/test/test_core.py", line 4063, in dylink_test
    return self.dylink_testf(main, side, expected, main_module=main_module, **kwargs)
  File "/b/s/w/ir/x/w/install/emscripten/test/test_core.py", line 4118, in dylink_testf
    self.do_runf(main, expected, force_c=force_c, **kwargs)
  File "/b/s/w/ir/x/w/install/emscripten/test/common.py", line 1958, in do_runf
    return self._build_and_run(filename, expected_output, **kwargs)
  File "/b/s/w/ir/x/w/install/emscripten/test/common.py", line 2006, in _build_and_run
    js_output = self.run_js(js_file, engine, args,
  File "/b/s/w/ir/x/w/install/emscripten/test/common.py", line 1586, in run_js
    self.fail('JS subprocess failed (%s): %s (expected=%s).  Output:\n%s' % (error.cmd, error.returncode, assert_returncode, ret))
  File "/home/chrome-bot/.cache/vpython-root.1000/store/cpython+tkj8tpr2n0oj8m0t270p0m71s0/contents/lib/python3.8/unittest/case.py", line 753, in fail
    raise self.failureException(msg)
AssertionError: JS subprocess failed (/b/s/w/ir/cache/builder/emscripten-releases/node-v22.16.0-linux-x64/bin/node --stack-trace-limit=50 --trace-uncaught /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js): 1 (expected=0).  Output:
got 84
got 0

=================================================================
==42==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 46 byte(s) in 1 object(s) allocated from:
    #0 0x000222dc in calloc+0x222dc (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x222dc)
    #1 0x00009ccf in load_library_start+0x9ccf (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9ccf)
    #2 0x00009a77 in _dlopen+0x9a77 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9a77)
    #3 0x00009976 in dlopen+0x9976 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9976)
    #4 0x00008b68 in main+0x8b68 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x8b68)
    #5 0x800016f9 in callMain /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5881:15
    #6 0x80001723 in doRun /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5923:24
    #7 0x8000172d in run /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5933:5
    #8 0x8000115c in removeRunDependency /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:4444:7
    #9 0x8000028e in receiveInstance /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:654:5
    #10 0x8000029c in receiveInstantiationResult /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:668:12
    #11 0x800002b3 in createWasm /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:691:17

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x000222dc in calloc+0x222dc (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x222dc)
    #1 0x00009570 in new_dlevent+0x9570 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9570)
    #2 0x00009ed1 in load_library_done+0x9ed1 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9ed1)
    #3 0x00009a90 in _dlopen+0x9a90 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9a90)
    #4 0x00009976 in dlopen+0x9976 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x9976)
    #5 0x00008b68 in main+0x8b68 (/b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js+0x8b68)
    #6 0x800016f9 in callMain /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5881:15
    #7 0x80001723 in doRun /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5923:24
    #8 0x8000172d in run /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:5933:5
    #9 0x8000115c in removeRunDependency /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:4444:7
    #10 0x8000028e in receiveInstance /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:654:5
    #11 0x8000029c in receiveInstantiationResult /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:668:12
    #12 0x800002b3 in createWasm /b/s/w/ir/x/t/emtest_73mrsv9g/emscripten_test_asan_z7vmenc8/main.js:691:17

SUMMARY: AddressSanitizer: 62 byte(s) leaked in 2 allocation(s).

At least I assume that are false positives, since they go away when this change is reverted.

My guess is that we are using ABSOLUTE for more symbols that just __wasm_first_page_end so we need some way to differentiate these two types of symbols.

@yamt
Copy link
Contributor Author

yamt commented Aug 20, 2025

My guess is that we are using ABSOLUTE for more symbols that just __wasm_first_page_end so we need some way to differentiate these two types of symbols.

#154494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lld][WebAssembly] __wasm_first_page_end is wrongly relocated

3 participants