runtime: on 32-bit systems, limit default GOMAXPROCS to 32

Otherwise we can easily run out of stack space for threads.

The user can still override by setting GOMAXPROCS.

Change-Id: I30cebf1d08434f55c44c44ed9894e3e507665d35
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/219278
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/libgo/go/runtime/proc.go b/libgo/go/runtime/proc.go
index c0e8577..e3f934a 100644
--- a/libgo/go/runtime/proc.go
+++ b/libgo/go/runtime/proc.go
@@ -563,6 +563,14 @@
 
 	sched.lastpoll = uint64(nanotime())
 	procs := ncpu
+
+	// In 32-bit mode, we can burn a lot of memory on thread stacks.
+	// Try to avoid this by limiting the number of threads we run
+	// by default.
+	if sys.PtrSize == 4 && procs > 32 {
+		procs = 32
+	}
+
 	if n, ok := atoi32(gogetenv("GOMAXPROCS")); ok && n > 0 {
 		procs = n
 	}