Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame^] | 1 | From 0e0c247f0caec23528889ff09d98348cba9028f1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Hongxu Jia <hongxu.jia@windriver.com> |
| 3 | Date: Fri, 26 Oct 2018 15:02:32 +0800 |
| 4 | Subject: [PATCH] use GOBUILDMODE to set buildmode |
| 5 | |
| 6 | While building go itself, the go build system does not support |
| 7 | to set `-buildmode=pie' from environment. |
| 8 | |
| 9 | Add GOBUILDMODE to support it which make PIE executables the default |
| 10 | build mode, as PIE executables are required as of Yocto |
| 11 | |
| 12 | Refers: https://groups.google.com/forum/#!topic/golang-dev/gRCe5URKewI |
| 13 | Upstream-Status: Denied [upstream choose antoher solution: `17a256b |
| 14 | cmd/go: -buildmode=pie for android/arm'] |
| 15 | |
| 16 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> |
| 17 | --- |
| 18 | src/cmd/go/internal/work/build.go | 6 +++++- |
| 19 | 1 file changed, 5 insertions(+), 1 deletion(-) |
| 20 | |
| 21 | diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go |
| 22 | index 145b875..595d703 100644 |
| 23 | --- a/src/cmd/go/internal/work/build.go |
| 24 | +++ b/src/cmd/go/internal/work/build.go |
| 25 | @@ -218,7 +218,11 @@ func AddBuildFlags(cmd *base.Command) { |
| 26 | |
| 27 | cmd.Flag.Var(&load.BuildAsmflags, "asmflags", "") |
| 28 | cmd.Flag.Var(buildCompiler{}, "compiler", "") |
| 29 | - cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "") |
| 30 | + if bm := os.Getenv("GOBUILDMODE"); bm != "" { |
| 31 | + cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", bm, "") |
| 32 | + } else { |
| 33 | + cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "") |
| 34 | + } |
| 35 | cmd.Flag.Var(&load.BuildGcflags, "gcflags", "") |
| 36 | cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "") |
| 37 | cmd.Flag.StringVar(&cfg.BuildMod, "mod", "", "") |
| 38 | -- |
| 39 | 2.7.4 |
| 40 | |