diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index b49a61e7b40494200b033c79be12d22eefca86a1..6992ce19e3fd4af8135aafd005597f17b23fe223 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -1761,6 +1761,8 @@ GOTESTFLAGS =
 CHECK = \
 	GC="$(GOC) $(GOCFLAGS) -L `${PWD_COMMAND}` -L `${PWD_COMMAND}`/.libs"; \
 	export GC; \
+	GOLIBS="$(MATH_LIBS) $(NET_LIBS)"; \
+	export GOLIBS; \
 	RUNTESTFLAGS="$(RUNTESTFLAGS)"; \
 	export RUNTESTFLAGS; \
 	MAKE="$(MAKE)"; \
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 9d61859f812c3d0b8146af05dc3c0e01ed0599f8..cdabd023d1ac42c6e288261252c02f9f0f5d1ea8 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -2077,6 +2077,8 @@ GOTESTFLAGS =
 CHECK = \
 	GC="$(GOC) $(GOCFLAGS) -L `${PWD_COMMAND}` -L `${PWD_COMMAND}`/.libs"; \
 	export GC; \
+	GOLIBS="$(MATH_LIBS) $(NET_LIBS)"; \
+	export GOLIBS; \
 	RUNTESTFLAGS="$(RUNTESTFLAGS)"; \
 	export RUNTESTFLAGS; \
 	MAKE="$(MAKE)"; \
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 296e8a5168ff980a621152dc3013be716f0000e1..69cf8eed06a04fa5a3455d79938f8d4001351496 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -16,7 +16,7 @@ export LC_CTYPE=C
 
 GC=${GC:-gccgo}
 GL=${GL:-${GC-gccgo}}
-GOLIBS=
+GOLIBS=${GOLIBS:-}
 export GC GL GOLIBS
 
 NM=${NM:-nm}