mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 07:53:40 +00:00
wasm: do not export malloc, calloc, realloc, free
These functions were exported by accident, because the compiler had no
way of saying these functions shouldn't be exported.
This can be a big code size reduction for small programs. Before:
$ tinygo build -o test.wasm -target=wasi -no-debug -scheduler=none ./testdata/alias.go && ls -l test.wasm
-rwxrwxr-x 1 ayke ayke 2947 8 sep 13:47 test.wasm
After:
$ tinygo build -o test.wasm -target=wasi -no-debug -scheduler=none ./testdata/alias.go && ls -l test.wasm
-rwxrwxr-x 1 ayke ayke 968 8 sep 13:47 test.wasm
This is all because the GC isn't needed anymore.
This commit also adds support for using //go:wasm-module to set the
module name of an exported function (the default remains env).
This commit is contained in:
@@ -1059,11 +1059,12 @@ func (b *builder) createFunctionStart(intrinsic bool) {
|
||||
if b.info.section != "" {
|
||||
b.llvmFn.SetSection(b.info.section)
|
||||
}
|
||||
if b.info.exported && strings.HasPrefix(b.Triple, "wasm") {
|
||||
if b.info.exported && b.info.module != "" && strings.HasPrefix(b.Triple, "wasm") {
|
||||
// Set the exported name. This is necessary for WebAssembly because
|
||||
// otherwise the function is not exported.
|
||||
functionAttr := b.ctx.CreateStringAttribute("wasm-export-name", b.info.linkName)
|
||||
b.llvmFn.AddFunctionAttr(functionAttr)
|
||||
b.llvmFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-name", b.info.linkName))
|
||||
// Set the export module.
|
||||
b.llvmFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-module", b.info.module))
|
||||
}
|
||||
|
||||
// Some functions have a pragma controlling the inlining level.
|
||||
|
||||
Reference in New Issue
Block a user