Skip to content

Wasm testsuite failure: cgrun069

The wasm NCG fails cgrun069 with:

clang-15: error: unable to execute command: Segmentation fault (core dumped)
clang-15: error: linker command failed due to signal (use -v to see invocation)
wasm32-wasi-ghc: `clang' failed in phase `Linker'. (Exit code: 1)

The offending input assembly, when minimized:

	.functype memmoveErr () -> ()
	.section memmoveErr,"",@
	.size memmoveErr,0
memmoveErr:
	.asciz "Memmove 0 Occurred\n"

Which corresponds to this Cmm declaration:

section "rodata" { memmoveErr : bits8[] "Memmove Error Occurred\n"; }

So the bug is obvious at this point. memmoveErr is a data section, but somehow the GHC in-memory CLabel was a function label, so the wasm NCG also emitted a fallback .functype clause for it, and this inconsistency crashed wasm-ld at link-time.

Now, it's easy to add a check in the wasm NCG, to remove fallback .functype declaration for a symbol if it's a data section defined in the current compilation unit. However, I'm very reluctant to rush towards this solution, since it's just sweeping the bug under the rug. Some questions I need to figure out before a proper fix:

  • Why does it work for unregisterised codegen? (And can we get rid of those import CLOSURE things?)
  • Can we fix this in Cmm once and for all, make CLabel function/data kind distinction 100% accurate for all targets?
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information