aboutsummaryrefslogtreecommitdiffhomepage
path: root/builder
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-03-12 21:52:52 +0100
committerdeadprogram <[email protected]>2024-03-19 07:12:22 +0100
commit78775007fa475a08dd64d5bd4b0093e8ece6fc52 (patch)
tree07998052605f5fe3ae14cd42dc9cf485c11ce7ea /builder
parentad4d722f54b1521e163ce5d0687f51817fccf617 (diff)
downloadtinygo-78775007fa475a08dd64d5bd4b0093e8ece6fc52.tar.gz
tinygo-78775007fa475a08dd64d5bd4b0093e8ece6fc52.zip
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.
Diffstat (limited to 'builder')
-rw-r--r--builder/ar.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/builder/ar.go b/builder/ar.go
index 3f1c8c213..578b88ba5 100644
--- a/builder/ar.go
+++ b/builder/ar.go
@@ -78,17 +78,27 @@ func makeArchive(arfile *os.File, objs []string) error {
} else if dbg, err := wasm.Parse(objfile); err == nil {
for _, s := range dbg.Sections {
switch section := s.(type) {
- case *wasm.SectionImport:
- for _, ln := range section.Entries {
-
- if ln.Kind != wasm.ExtKindFunction {
- // Not a function
+ case *wasm.SectionLinking:
+ for _, symbol := range section.Symbols {
+ if symbol.Flags&wasm.LinkingSymbolFlagUndefined != 0 {
+ // Don't list undefined functions.
+ 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 {
name string
fileIndex int
- }{ln.Field, i})
+ }{symbol.Name, i})
}
}
}