builder: add strlen to wasm builtins

LLVM 22 can replace string-scanning loops with calls to strlen during
optimization. Add the implementation to wasmbuiltins and invalidate
cached archives.

Add an optimized wasm-unknown smoke test that exercises the reflect
name-decoding path which exposed the missing symbol.
This commit is contained in:
Jake Bailey
2026-08-29 23:45:30 -07:00
committed by Ron Evans
parent 61c315cbfb
commit fc0673430d
4 changed files with 24 additions and 7 deletions
+2 -2
View File
@@ -43,11 +43,11 @@ var libWasmBuiltins = Library{
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/wasi-libc") },
librarySources: func(target string, _ bool) ([]string, error) {
return []string{
// memory builtins needed for llvm.memcpy.*, llvm.memmove.*, and
// llvm.memset.* LLVM intrinsics.
// Memory builtins needed for LLVM intrinsics and library calls.
"libc-top-half/musl/src/string/memcpy.c",
"libc-top-half/musl/src/string/memmove.c",
"libc-top-half/musl/src/string/memset.c",
"libc-top-half/musl/src/string/strlen.c",
// exp, exp2, and log are needed for LLVM math builtin functions
// like llvm.exp.*.
+3 -2
View File
@@ -23,8 +23,9 @@ import (
// builder.Library struct but that's hard to do since we want to know the
// library path in advance in several places).
var libVersions = map[string]int{
"musl": 3,
"bdwgc": 2,
"musl": 3,
"bdwgc": 2,
"wasmbuiltins": 1,
}
// Config keeps all configuration affecting the build in a single struct.
+4 -3
View File
@@ -573,9 +573,10 @@ smoketest-riscv: | build/smoke
smoketest-wasm: SMOKE_OUT = build/smoke/wasm
smoketest-wasm: | build/smoke
ifneq ($(WASM), 0)
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm examples/wasm/export
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm examples/wasm/main
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm-unknown examples/hello-wasm-unknown
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm examples/wasm/export
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm examples/wasm/main
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm-unknown examples/hello-wasm-unknown
$(TINYGO) build -size short -o $(SMOKE_OUT).wasm -target=wasm-unknown -opt=2 ./testdata/wasm-unknown-opt
endif
smoketest-flags: SMOKE_OUT = build/smoke/flags
+15
View File
@@ -0,0 +1,15 @@
package main
import "reflect"
type value struct {
Field int
}
//go:wasmexport typeNameLength
func typeNameLength() uint32 {
return uint32(len(reflect.TypeOf(value{}).String()))
}
func main() {
}