Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
867c2675 by Cheng Shao at 2025-09-20T06:49:28-04:00
wasm: fix dyld handling for forward declared GOT.func items
This patch fixes wasm shared linker's handling of forward declared
GOT.func items, see linked issue for details. Also adds T26430 test to
witness the fix. Fixes #26430.
Co-authored-by: Codex
- - - - -
6 changed files:
- + testsuite/tests/ghci-wasm/Makefile
- + testsuite/tests/ghci-wasm/T26430.hs
- + testsuite/tests/ghci-wasm/T26430A.c
- + testsuite/tests/ghci-wasm/T26430B.c
- + testsuite/tests/ghci-wasm/all.T
- utils/jsffi/dyld.mjs
Changes:
=====================================
testsuite/tests/ghci-wasm/Makefile
=====================================
@@ -0,0 +1,7 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+T26430_setup :
+ '$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -shared T26430A.c -o libT26430A.so
+ '$(TEST_HC)' $(TEST_HC_OPTS) $(ghciWayFlags) -shared -L. -lT26430A T26430B.c -o libT26430B.so
=====================================
testsuite/tests/ghci-wasm/T26430.hs
=====================================
@@ -0,0 +1 @@
+foreign import ccall unsafe "baz" main :: IO ()
=====================================
testsuite/tests/ghci-wasm/T26430A.c
=====================================
@@ -0,0 +1,5 @@
+void foo(void);
+
+void bar(void (*)(void));
+
+__attribute__((export_name("baz"))) void baz(void) { bar(foo); }
=====================================
testsuite/tests/ghci-wasm/T26430B.c
=====================================
@@ -0,0 +1,3 @@
+__attribute__((export_name("foo"))) void foo(void) {}
+
+__attribute__((export_name("bar"))) void bar(void (*f)(void)) { f(); }
=====================================
testsuite/tests/ghci-wasm/all.T
=====================================
@@ -0,0 +1,12 @@
+setTestOpts([
+ unless(arch('wasm32'), skip),
+ only_ways(['ghci', 'ghci-opt']),
+ extra_ways(['ghci', 'ghci-opt'])
+])
+
+test('T26430', [
+ extra_files(['T26430A.c', 'T26430B.c']),
+ pre_cmd('$MAKE -s --no-print-directory T26430_setup ghciWayFlags=' + config.ghci_way_flags),
+ extra_hc_opts('-L. -lT26430B')]
+, compile_and_run, ['']
+)
=====================================
utils/jsffi/dyld.mjs
=====================================
@@ -1013,10 +1013,13 @@ class DyLD {
// anything, if it's required later a GOT.func entry will be
// created on demand.
if (this.#gotFunc[k]) {
- // ghc-prim/ghc-internal may export functions imported by
- // rts
- console.assert(this.#gotFunc[k].value === DyLD.#poison);
- this.#table.set(this.#gotFunc[k].value, v);
+ const got = this.#gotFunc[k];
+ if (got.value === DyLD.#poison) {
+ const idx = this.#table.grow(1, v);
+ got.value = idx;
+ } else {
+ this.#table.set(got.value, v);
+ }
}
continue;
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/867c26755e8855c6df949e65df0c2aeb...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/867c26755e8855c6df949e65df0c2aeb...
You're receiving this email because of your account on gitlab.haskell.org.