Skip to content

Commit ca33e10

Browse files
committed
cmd/compile: rework reporting of oversized stack frames
We don't support stack frames over 2GB. Rather than detect this during backend compilation, check for it at the end of compilation. This is arguably a more accurate check anyway, since it takes into account the full frame, including local stack, arguments, and arch-specific rounding, although it's unlikely anyone would ever notice. Also, rather than reporting the error right away, take note of it and report it later, at the top level. This is not relevant now, but it will help with making the backend concurrent, as the append to the list of oversized functions can be cheaply protected by a plain mutex. Updates #15756 Updates #19250 Change-Id: Id3fa21906616d62e9dc66e27a17fd5f83304e96e Reviewed-on: https://go-review.googlesource.com/38972 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 8577f81 commit ca33e10

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/cmd/compile/internal/gc/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ func Main(archInit func(*Arch)) {
523523
if compiling_runtime {
524524
checknowritebarrierrec()
525525
}
526+
for _, largePos := range largeStackFrames {
527+
yyerrorl(largePos, "stack frame too large (>2GB)")
528+
}
526529
}
527530

528531
// Phase 9: Check external declarations.

src/cmd/compile/internal/gc/pgen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
235235
if thearch.LinkArch.InFamily(sys.MIPS, sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) {
236236
s.stksize = Rnd(s.stksize, int64(Widthptr))
237237
}
238-
if s.stksize >= 1<<31 {
239-
yyerrorl(s.curfn.Pos, "stack frame too large (>2GB)")
240-
}
241-
242238
n.Xoffset = -s.stksize
243239
}
244240

@@ -289,6 +285,10 @@ func compile(fn *Node) {
289285
pp := newProgs(fn)
290286
genssa(ssafn, pp)
291287
fieldtrack(pp.Text.From.Sym, fn.Func.FieldTrack)
288+
if pp.Text.To.Offset >= 1<<31 {
289+
largeStackFrames = append(largeStackFrames, fn.Pos)
290+
return
291+
}
292292
pp.Flush()
293293
}
294294

src/cmd/compile/internal/gc/subr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Error struct {
2727

2828
var errors []Error
2929

30+
var largeStackFrames []src.XPos // positions of functions whose stack frames are too large (rare)
31+
3032
func errorexit() {
3133
flusherrors()
3234
if outfile != "" {

0 commit comments

Comments
 (0)