}
}
+// cutoff is the maximum data section size permitted by the linker
+// (see issue #9862).
+const cutoff = int64(2e9) // 2 GB (or so; looks better in errors than 2^31)
+
func (w *writer) Sym(s *LSym) {
abi := uint16(s.ABI())
if s.Static() {
// don't bother setting align to 1.
}
}
+ if s.Size > cutoff {
+ w.ctxt.Diag("%s: symbol too large (%d bytes > %d bytes)", s.Name, s.Size, cutoff)
+ }
var o goobj.Sym
o.SetName(name, w.Writer)
o.SetABI(abi)
package obj
import (
+ "bytes"
"cmd/internal/goobj"
"cmd/internal/sys"
+ "internal/testenv"
+ "io/ioutil"
+ "os"
+ "os/exec"
+ "path/filepath"
"testing"
+ "unsafe"
)
var dummyArch = LinkArch{Arch: sys.ArchAMD64}
}
}
}
+
+func TestSymbolTooLarge(t *testing.T) { // Issue 42054
+ testenv.MustHaveGoBuild(t)
+ if unsafe.Sizeof(uintptr(0)) < 8 {
+ t.Skip("skip on 32-bit architectures")
+ }
+
+ tmpdir, err := ioutil.TempDir("", "TestSymbolTooLarge")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(tmpdir)
+
+ src := filepath.Join(tmpdir, "p.go")
+ err = ioutil.WriteFile(src, []byte("package p; var x [1<<32]byte"), 0666)
+ if err != nil {
+ t.Fatalf("failed to write source file: %v\n", err)
+ }
+ obj := filepath.Join(tmpdir, "p.o")
+ cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", obj, src)
+ out, err := cmd.CombinedOutput()
+ if err == nil {
+ t.Fatalf("did not fail\noutput: %s", out)
+ }
+ const want = "symbol too large"
+ if !bytes.Contains(out, []byte(want)) {
+ t.Errorf("unexpected error message: want: %q, got: %s", want, out)
+ }
+}
-// compile
+// skip
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// Issue 4348. After switch to 64-bit ints the compiler generates
// illegal instructions when using large array bounds or indexes.
+// Skip. We reject symbols larger that 2GB (Issue #9862).
+
package main
// 1<<32 on a 64-bit machine, 1 otherwise.