runtime: fix crash in badsignal()
The linker can generate split stack prolog when a textflag 7 function
makes an indirect function call.  If it happens, badsignal() crashes
trying to dereference g.
Fixes #5337.

R=bradfitz, dave, adg, iant, r, minux.ma
CC=adonovan, golang-dev
https://golang.org/cl/9226043
diff --git a/src/pkg/runtime/os_darwin.c b/src/pkg/runtime/os_darwin.c
index 390e76e..276362a 100644
--- a/src/pkg/runtime/os_darwin.c
+++ b/src/pkg/runtime/os_darwin.c
@@ -540,14 +540,17 @@
 void
 runtime·badsignal(int32 sig)
 {
+	int32 len;
+
 	if (sig == SIGPROF) {
 		return;  // Ignore SIGPROFs intended for a non-Go thread.
 	}
 	runtime·write(2, badsignal, sizeof badsignal - 1);
 	if (0 <= sig && sig < NSIG) {
-		// Call runtime·findnull dynamically to circumvent static stack size check.
-		static int32 (*findnull)(byte*) = runtime·findnull;
-		runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name));
+		// Can't call findnull() because it will split stack.
+		for(len = 0; runtime·sigtab[sig].name[len]; len++)
+			;
+		runtime·write(2, runtime·sigtab[sig].name, len);
 	}
 	runtime·write(2, "\n", 1);
 	runtime·exit(1);
diff --git a/src/pkg/runtime/os_freebsd.c b/src/pkg/runtime/os_freebsd.c
index 357ad80..f454ab3 100644
--- a/src/pkg/runtime/os_freebsd.c
+++ b/src/pkg/runtime/os_freebsd.c
@@ -252,14 +252,17 @@
 void
 runtime·badsignal(int32 sig)
 {
+	int32 len;
+
 	if (sig == SIGPROF) {
 		return;  // Ignore SIGPROFs intended for a non-Go thread.
 	}
 	runtime·write(2, badsignal, sizeof badsignal - 1);
 	if (0 <= sig && sig < NSIG) {
-		// Call runtime·findnull dynamically to circumvent static stack size check.
-		static int32 (*findnull)(byte*) = runtime·findnull;
-		runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name));
+		// Can't call findnull() because it will split stack.
+		for(len = 0; runtime·sigtab[sig].name[len]; len++)
+			;
+		runtime·write(2, runtime·sigtab[sig].name, len);
 	}
 	runtime·write(2, "\n", 1);
 	runtime·exit(1);
diff --git a/src/pkg/runtime/os_linux.c b/src/pkg/runtime/os_linux.c
index e4ae1a5..6b86d2b 100644
--- a/src/pkg/runtime/os_linux.c
+++ b/src/pkg/runtime/os_linux.c
@@ -300,14 +300,17 @@
 void
 runtime·badsignal(int32 sig)
 {
+	int32 len;
+
 	if (sig == SIGPROF) {
 		return;  // Ignore SIGPROFs intended for a non-Go thread.
 	}
 	runtime·write(2, badsignal, sizeof badsignal - 1);
 	if (0 <= sig && sig < NSIG) {
-		// Call runtime·findnull dynamically to circumvent static stack size check.
-		static int32 (*findnull)(byte*) = runtime·findnull;
-		runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name));
+		// Can't call findnull() because it will split stack.
+		for(len = 0; runtime·sigtab[sig].name[len]; len++)
+			;
+		runtime·write(2, runtime·sigtab[sig].name, len);
 	}
 	runtime·write(2, "\n", 1);
 	runtime·exit(1);
diff --git a/src/pkg/runtime/os_netbsd.c b/src/pkg/runtime/os_netbsd.c
index 936334c..7679ec2 100644
--- a/src/pkg/runtime/os_netbsd.c
+++ b/src/pkg/runtime/os_netbsd.c
@@ -292,14 +292,17 @@
 void
 runtime·badsignal(int32 sig)
 {
+	int32 len;
+
 	if (sig == SIGPROF) {
 		return;  // Ignore SIGPROFs intended for a non-Go thread.
 	}
 	runtime·write(2, badsignal, sizeof badsignal - 1);
 	if (0 <= sig && sig < NSIG) {
-		// Call runtime·findnull dynamically to circumvent static stack size check.
-		static int32 (*findnull)(byte*) = runtime·findnull;
-		runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name));
+		// Can't call findnull() because it will split stack.
+		for(len = 0; runtime·sigtab[sig].name[len]; len++)
+			;
+		runtime·write(2, runtime·sigtab[sig].name, len);
 	}
 	runtime·write(2, "\n", 1);
 	runtime·exit(1);
diff --git a/src/pkg/runtime/os_openbsd.c b/src/pkg/runtime/os_openbsd.c
index 4ce64f9..4ce102e 100644
--- a/src/pkg/runtime/os_openbsd.c
+++ b/src/pkg/runtime/os_openbsd.c
@@ -274,14 +274,17 @@
 void
 runtime·badsignal(int32 sig)
 {
+	int32 len;
+
 	if (sig == SIGPROF) {
 		return;  // Ignore SIGPROFs intended for a non-Go thread.
 	}
 	runtime·write(2, badsignal, sizeof badsignal - 1);
 	if (0 <= sig && sig < NSIG) {
-		// Call runtime·findnull dynamically to circumvent static stack size check.
-		static int32 (*findnull)(byte*) = runtime·findnull;
-		runtime·write(2, runtime·sigtab[sig].name, findnull((byte*)runtime·sigtab[sig].name));
+		// Can't call findnull() because it will split stack.
+		for(len = 0; runtime·sigtab[sig].name[len]; len++)
+			;
+		runtime·write(2, runtime·sigtab[sig].name, len);
 	}
 	runtime·write(2, "\n", 1);
 	runtime·exit(1);