Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-unknown target doesn't define memset or memcpy #4174

Open
adambratschikaye opened this issue Mar 4, 2024 · 2 comments
Open

wasm-unknown target doesn't define memset or memcpy #4174

adambratschikaye opened this issue Mar 4, 2024 · 2 comments
Labels
next-release Will be part of next release wasm WebAssembly

Comments

@adambratschikaye
Copy link

Hello, I was trying out the new wasm-unknown target and found that it doesn't seem to be able to compile applications that require memset or memcpy.

I compiled tinygo from source on commit 377415a using llvm 16. With main.go:

package main

func main() {
}

//go:export run
func run() byte {
	var arg []byte
	for i := 0; i < int(100); i++ {
		arg = append(arg, 0)
	}
	return arg[5]
}

I get the following error:

❯ tinygo build -target=wasm-unknown main.go
wasm-ld-16: error: lto.tmp: undefined symbol: memset
wasm-ld-16: error: lto.tmp: undefined symbol: memcpy
error: failed to link /tmp/tinygo826502402/main: exit status 1

I tried enabling the bulk memory feature in targets/wasm-unknown.json:

       "llvm-target":   "wasm32-unknown-unknown",
       "cpu":           "generic",
-       "features":      "+mutable-globals,+nontrapping-fptoint,+sign-ext,-bulk-memory",
+       "features":      "+mutable-globals,+nontrapping-fptoint,+sign-ext,+bulk-memory",
       "build-tags":    ["tinygo.wasm", "wasm_unknown"],
       "goos":          "linux",
       "default-stack-size": 4096,
       "cflags": [
-                "-mno-bulk-memory",
                "-mnontrapping-fptoint",
                "-msign-ext"
       ],

to see if they'd get compiled to mem.init and mem.copy respectively and that does seem to work.

Is there an easy way to enable the bulk memory feature without forking the repo?

@aykevl
Copy link
Member

aykevl commented Mar 4, 2024

This is related to #4176 and #4169.

@aykevl
Copy link
Member

aykevl commented Mar 13, 2024

❯ tinygo build -target=wasm-unknown main.go
wasm-ld-16: error: lto.tmp: undefined symbol: memset
wasm-ld-16: error: lto.tmp: undefined symbol: memcpy
error: failed to link /tmp/tinygo826502402/main: exit status 1

This is still an issue, so reopening. After #4176 gets merged, this should be easy to add.

Is there an easy way to enable the bulk memory feature without forking the repo?

Not at the moment (though the -llvm-features flag might help). Ideally we'd have either a GOWASM environment variable or maybe a -cpu flag that sets the supported wasm support level (MVP, wasm 2.0, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-release Will be part of next release wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

3 participants