summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go-1.9/0011-use-GOBUILDMODE-to-set-buildmode.patch
blob: da93dc5c1483e462ffd800aa69458c9fcfae72de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From b928fafab1d9425aae9341806bd2f6178ba1da1f Mon Sep 17 00:00:00 2001
From: Hongxu Jia <hongxu.jia@windriver.com>
Date: Fri, 26 Oct 2018 16:32:50 +0800
Subject: [PATCH] use GOBUILDMODE to set buildmode

While building go itself, the go build system does not support
to set `-buildmode=pie' from environment.

Add GOBUILDMODE to support it which make PIE executables the default
build mode, as PIE executables are required as of Yocto

Refers: https://groups.google.com/forum/#!topic/golang-dev/gRCe5URKewI
Upstream-Status: Denied [upstream choose antoher solution: `17a256b
cmd/go: -buildmode=pie for android/arm']

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 src/cmd/go/internal/work/build.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index b276de5..1683e7e 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -211,7 +211,11 @@ func AddBuildFlags(cmd *base.Command) {
 
 	cmd.Flag.Var((*base.StringsFlag)(&buildAsmflags), "asmflags", "")
 	cmd.Flag.Var(buildCompiler{}, "compiler", "")
-	cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
+	if bm := os.Getenv("GOBUILDMODE"); bm != "" {
+		cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", bm, "")
+	} else {
+		cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
+	}
 	cmd.Flag.Var((*base.StringsFlag)(&buildGcflags), "gcflags", "")
 	cmd.Flag.Var((*base.StringsFlag)(&buildGccgoflags), "gccgoflags", "")
 	cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
-- 
2.7.4