mirror of https://github.com/golang/go.git
Merge 6f6997ce30 into 49cdf0c42e
This commit is contained in:
commit
6a564023c5
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue