diff --git a/ChangeLog b/ChangeLog
index 9c688eb..7a7ade2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-21  Ben Elliston  <bje@gnu.org>
+
+	* config.guess (set_cc_for_build): Prevent multiple calls by
+	chechking if $tmp is already set. We can't check CC_FOR_BUILD as
+	the user may set it externally. Thanks to Torbjörn Granlund for
+	the bug report.
+
 2019-12-21  Torbjörn Granlund  <tg@gmplib.org>
 
 	* config.guess (alpha:Linux:*:*): Guard against missing
diff --git a/config.guess b/config.guess
index fe242a4..95b16c7 100755
--- a/config.guess
+++ b/config.guess
@@ -99,6 +99,8 @@ tmp=
 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
 
 set_cc_for_build() {
+    # prevent multiple calls if $tmp is already set
+    test "$tmp" && return 0
     : "${TMPDIR=/tmp}"
     # shellcheck disable=SC2039
     { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||