"cmd/internal/bio"
"cmd/internal/obj"
"cmd/internal/objabi"
+ "cmd/internal/src"
"crypto/sha256"
"fmt"
"io"
return off
}
-func stringsym(s string) (data *obj.LSym) {
+func stringsym(pos src.XPos, s string) (data *obj.LSym) {
var symname string
if len(s) > 100 {
// Huge strings are hashed to avoid long names in object files.
if !symdata.SeenGlobl() {
// string data
- off := dsname(symdata, 0, s)
+ off := dsname(symdata, 0, s, pos, "string")
ggloblsym(symdata, int32(off), obj.DUPOK|obj.RODATA|obj.LOCAL)
}
sym.Def = asTypesNode(newname(sym))
lsym := sym.Linksym()
- off := dsname(lsym, 0, s)
+ off := dsname(lsym, 0, s, nam.Pos, "slice")
ggloblsym(lsym, int32(off), obj.NOPTR|obj.LOCAL)
if nam.Op != ONAME {
duintptr(nsym, off, uint64(len))
}
-func dsname(s *obj.LSym, off int, t string) int {
+func dsname(s *obj.LSym, off int, t string, pos src.XPos, what string) int {
+ // Objects that are too large will cause the data section to overflow right away,
+ // causing a cryptic error message by the linker. Check for oversize objects here
+ // and provide a useful error message instead.
+ if int64(len(t)) > 2e9 {
+ yyerrorl(pos, "%v with length %v is too big", what, len(t))
+ return 0
+ }
+
s.WriteString(Ctxt, int64(off), len(t), t)
return off + len(t)
}
}
case string:
- symdata := stringsym(u)
+ symdata := stringsym(nam.Pos, u)
s.WriteAddr(Ctxt, nam.Xoffset, Widthptr, symdata, 0)
s.WriteInt(Ctxt, nam.Xoffset+int64(Widthptr), Widthptr, int64(len(u)))
return s1.name < s2.name
}
-const cutoff int64 = 2e9 // 2 GB (or so; looks better in errors than 2^31)
+// cutoff is the maximum data section size permitted by the linker
+// (see issue #9862).
+const cutoff = 2e9 // 2 GB (or so; looks better in errors than 2^31)
func checkdatsize(ctxt *Link, datsize int64, symn sym.SymKind) {
if datsize > cutoff {
- Errorf(nil, "too much data in section %v (over %d bytes)", symn, cutoff)
+ Errorf(nil, "too much data in section %v (over %v bytes)", symn, cutoff)
}
}