Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | From 971b5626339ce0c4d57f9721c9a81af566c5a044 Mon Sep 17 00:00:00 2001 |
| 2 | From: Alex Kube <alexander.j.kube@gmail.com> |
| 3 | Date: Wed, 23 Oct 2019 21:19:26 +0430 |
| 4 | Subject: [PATCH 8/9] cmd/go: Use GOBUILDMODE to set buildmode |
| 5 | |
| 6 | Upstream-Status: Denied [upstream choose antoher solution: `17a256b |
| 7 | cmd/go: -buildmode=pie for android/arm'] |
| 8 | |
| 9 | While building go itself, the go build system does not support |
| 10 | to set `-buildmode=pie' from environment. |
| 11 | |
| 12 | Add GOBUILDMODE to support it which make PIE executables the default |
| 13 | build mode, as PIE executables are required as of Yocto |
| 14 | |
| 15 | Refers: https://groups.google.com/forum/#!topic/golang-dev/gRCe5URKewI |
| 16 | |
| 17 | Adapted to Go 1.13 from patches originally submitted to |
| 18 | the meta/recipes-devtools/go tree by |
| 19 | Hongxu Jia <hongxu.jia@windriver.com> |
| 20 | |
| 21 | Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com> |
| 22 | --- |
| 23 | src/cmd/go/internal/work/build.go | 8 +++++++- |
| 24 | 1 file changed, 7 insertions(+), 1 deletion(-) |
| 25 | |
| 26 | --- a/src/cmd/go/internal/work/build.go |
| 27 | +++ b/src/cmd/go/internal/work/build.go |
| 28 | @@ -251,7 +251,13 @@ func AddBuildFlags(cmd *base.Command, ma |
| 29 | |
| 30 | cmd.Flag.Var(&load.BuildAsmflags, "asmflags", "") |
| 31 | cmd.Flag.Var(buildCompiler{}, "compiler", "") |
| 32 | - cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "") |
| 33 | + |
| 34 | + if bm := os.Getenv("GOBUILDMODE"); bm != "" { |
| 35 | + cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", bm, "") |
| 36 | + } else { |
| 37 | + cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "") |
| 38 | + } |
| 39 | + |
| 40 | cmd.Flag.Var(&load.BuildGcflags, "gcflags", "") |
| 41 | cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "") |
| 42 | if mask&OmitModFlag == 0 { |