From 2c1c98d6404284df744a194dd23bd3660f365387 Mon Sep 17 00:00:00 2001
From: Georg Koppen <gk@torproject.org>
Date: Fri, 17 Apr 2020 10:24:23 +0000
Subject: [PATCH] Use fixed go-build tmp directory

Use fixed go-build tmp directory, when the directory does not exist, in
order to avoid some reproducibility issues where build directory gets
embedded in generated binaries.
---
 src/cmd/go/internal/work/action.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
index 8beb1345d0..dccf39c1c1 100644
--- a/src/cmd/go/internal/work/action.go
+++ b/src/cmd/go/internal/work/action.go
@@ -279,9 +279,13 @@ func NewBuilder(workDir string) *Builder {
 		if !buildInitStarted {
 			panic("internal error: NewBuilder called before BuildInit")
 		}
-		tmp, err := os.MkdirTemp(cfg.Getenv("GOTMPDIR"), "go-build")
-		if err != nil {
-			base.Fatalf("go: creating work dir: %v", err)
+		tmp := filepath.Join(cfg.Getenv("GOTMPDIR"), "go-build-workdir")
+		_, err := os.Stat(tmp)
+		if !os.IsNotExist(err) {
+			tmp, err = os.MkdirTemp(cfg.Getenv("GOTMPDIR"), "go-build")
+			if err != nil {
+				base.Fatalf("go: creating work dir: %v", err)
+			}
 		}
 		if !filepath.IsAbs(tmp) {
 			abs, err := filepath.Abs(tmp)
-- 
2.39.2

