cmd/compile: consolidate size limits

We currently have symbol size limit and go:embed file size limit
both as 2000000000 (2 GB or so; looks better than 2^31). Use the
same limit for string constants. So we don't have many arbitrary
limits.

Change-Id: I029dd9224f07f41585276c59c0f3bd78f73b1860
Reviewed-on: https://go-review.googlesource.com/c/go/+/771660
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Cherry Mui 2026-04-28 15:16:53 -04:00
parent 343fbe2971
commit b8e0cb88c8
4 changed files with 11 additions and 9 deletions

View file

@ -110,7 +110,7 @@ func StringSymNoCommon(s string) (data *obj.LSym) {
// maxFileSize is the maximum file size permitted by the linker
// (see issue #9862).
const maxFileSize = int64(2e9)
const maxFileSize = obj.MaxSymSize
// fileStringSym returns a symbol for the contents and the size of file.
// If readonly is true, the symbol shares storage with any literal string

View file

@ -49,9 +49,10 @@ func (check *Checker) overflow(x *operand, opPos syntax.Pos) {
return
}
const maxLen = 1 * 1024 * 1024 * 1024
const maxLen = int(2e9) // cmd/internal/obj.MaxSymSize
if x.val.Kind() == constant.String && len(constant.StringVal(x.val)) > maxLen {
check.error(atPos(opPos), InvalidConstVal, "constant string too long")
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)",
len(constant.StringVal(x.val)), maxLen)
x.val = constant.MakeUnknown()
return
}

View file

@ -309,9 +309,9 @@ func (w *writer) StringTable() {
}
}
// cutoff is the maximum data section size permitted by the linker
// MaxSymSize 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)
const MaxSymSize = int64(2e9) // 2 GB (or so; looks better in errors than 2^31)
func (w *writer) Sym(s *LSym) {
name := s.Name
@ -377,8 +377,8 @@ func (w *writer) Sym(s *LSym) {
// TODO: Check that alignment is set for all symbols.
w.ctxt.Diag("%s: is content-addressable but alignment is not set (size is %d)", s.Name, s.Size)
}
if s.Size > cutoff {
w.ctxt.Diag("%s: symbol too large (%d bytes > %d bytes)", s.Name, s.Size, cutoff)
if s.Size > MaxSymSize {
w.ctxt.Diag("%s: symbol too large (%d bytes > %d bytes)", s.Name, s.Size, MaxSymSize)
}
o := &w.tmpSym
o.SetName(name, w.Writer)

View file

@ -51,9 +51,10 @@ func (check *Checker) overflow(x *operand, opPos token.Pos) {
return
}
const maxLen = 1 * 1024 * 1024 * 1024
const maxLen = int(2e9) // cmd/internal/obj.MaxSymSize
if x.val.Kind() == constant.String && len(constant.StringVal(x.val)) > maxLen {
check.error(atPos(opPos), InvalidConstVal, "constant string too long")
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)",
len(constant.StringVal(x.val)), maxLen)
x.val = constant.MakeUnknown()
return
}