mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 16:03:41 +00:00
wasm: fix symbol table index for archives
The symbol table was generated incorrectly. The correct way is to use the custom linking WebAssembly section, which I implemented in go-wasm for this purpose. This fixes https://github.com/tinygo-org/tinygo/issues/4114 and is a prerequisite for https://github.com/tinygo-org/tinygo/pull/4176.
This commit is contained in:
committed by
deadprogram
parent
ad4d722f54
commit
78775007fa
+16
-6
@@ -78,17 +78,27 @@ func makeArchive(arfile *os.File, objs []string) error {
|
|||||||
} else if dbg, err := wasm.Parse(objfile); err == nil {
|
} else if dbg, err := wasm.Parse(objfile); err == nil {
|
||||||
for _, s := range dbg.Sections {
|
for _, s := range dbg.Sections {
|
||||||
switch section := s.(type) {
|
switch section := s.(type) {
|
||||||
case *wasm.SectionImport:
|
case *wasm.SectionLinking:
|
||||||
for _, ln := range section.Entries {
|
for _, symbol := range section.Symbols {
|
||||||
|
if symbol.Flags&wasm.LinkingSymbolFlagUndefined != 0 {
|
||||||
if ln.Kind != wasm.ExtKindFunction {
|
// Don't list undefined functions.
|
||||||
// Not a function
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if symbol.Flags&wasm.LinkingSymbolFlagBindingLocal != 0 {
|
||||||
|
// Don't include local symbols.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if symbol.Kind != wasm.LinkingSymbolKindFunction && symbol.Kind != wasm.LinkingSymbolKindData {
|
||||||
|
// Link functions and data symbols.
|
||||||
|
// Some data symbols need to be included, such as
|
||||||
|
// __log_data.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Include in the archive.
|
||||||
symbolTable = append(symbolTable, struct {
|
symbolTable = append(symbolTable, struct {
|
||||||
name string
|
name string
|
||||||
fileIndex int
|
fileIndex int
|
||||||
}{ln.Field, i})
|
}{symbol.Name, i})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module github.com/tinygo-org/tinygo
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc
|
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
|
||||||
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee
|
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee
|
||||||
github.com/chromedp/chromedp v0.7.6
|
github.com/chromedp/chromedp v0.7.6
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc h1:Yp49g+qqgQRPk/gcRSmAsXgnT16XPJ6Y5JM1poc6gYM=
|
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c h1:4T0Vj1UkGgcpkRrmn7SbokebnlfxJcMZPgWtOYACAAA=
|
||||||
github.com/aykevl/go-wasm v0.0.2-0.20220616010729-4a0a888aebdc/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
|
github.com/aykevl/go-wasm v0.0.2-0.20240312204833-50275154210c/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
|
||||||
github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
|
github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
|
||||||
|
|||||||
Reference in New Issue
Block a user