This commit is contained in:
Zxilly 2025-06-20 15:31:52 -04:00 committed by GitHub
commit 6a564023c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View File

@ -124,6 +124,7 @@ var dataSects []wasmDataSect
func asmb(ctxt *ld.Link, ldr *loader.Loader) {
sections := []*sym.Section{
ldr.SymSect(ldr.Lookup("go:buildinfo", 0)),
ldr.SymSect(ldr.Lookup("runtime.rodata", 0)),
ldr.SymSect(ldr.Lookup("runtime.typelink", 0)),
ldr.SymSect(ldr.Lookup("runtime.itablink", 0)),

View File

@ -1684,3 +1684,44 @@ func TestLinknameBSS(t *testing.T) {
t.Errorf("executable failed to run: %v\n%s", err, out)
}
}
func TestWasmBuildinfo(t *testing.T) {
testenv.MustHaveGoBuild(t)
t.Parallel()
tmpdir := t.TempDir()
src := filepath.Join(tmpdir, "hello.go")
err := os.WriteFile(src, []byte(`package main; func main() { println("hello") }`), 0666)
if err != nil {
t.Fatal(err)
}
exe := filepath.Join(tmpdir, "hello.wasm")
cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
env := []string{"GOOS=js", "GOARCH=wasm"}
for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOOS=") || strings.HasPrefix(v, "GOARCH=") {
continue
}
env = append(env, v)
}
cmd.Env = env
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed: %v\n%s", err, out)
}
const magic = "\xff Go buildinf:"
data, err := os.ReadFile(exe)
if err != nil {
t.Fatalf("failed to read output file: %v", err)
}
if !bytes.Contains(data, []byte(magic)) {
t.Fatalf("output does not contain buildinfo magic: %q", out)
}
}