wasm: only export explicitly exported functions
Previously we used the --export-all linker flag to export most functions. However, this is not needed and possibly increases binary size. Instead, we should be exporting the specific functions to be exported.
Этот коммит содержится в:
родитель
0db4b13e37
коммит
c522569378
2 изменённых файлов: 7 добавлений и 2 удалений
|
@ -23,7 +23,7 @@ import (
|
|||
// Version of the compiler pacakge. Must be incremented each time the compiler
|
||||
// package changes in a way that affects the generated LLVM module.
|
||||
// This version is independent of the TinyGo version number.
|
||||
const Version = 1
|
||||
const Version = 2 // last change: adding wasm-export-name attribute
|
||||
|
||||
func init() {
|
||||
llvm.InitializeAllTargets()
|
||||
|
@ -781,6 +781,12 @@ func (b *builder) createFunction() {
|
|||
b.llvmFn.SetVisibility(llvm.HiddenVisibility)
|
||||
b.llvmFn.SetUnnamedAddr(true)
|
||||
}
|
||||
if b.info.exported && 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)
|
||||
}
|
||||
|
||||
// Some functions have a pragma controlling the inlining level.
|
||||
switch b.info.inline {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
"ldflags": [
|
||||
"--allow-undefined",
|
||||
"--stack-first",
|
||||
"--export-all",
|
||||
"--no-demangle"
|
||||
],
|
||||
"emulator": ["node", "targets/wasm_exec.js"],
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче