diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-11-13 11:05:37 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-11-16 14:56:38 +0000 |
commit | 730d5f42f919f948ff2841581ecec6fe4b465aee (patch) | |
tree | 57152253494e668d081054f3c7f6797916e6fd19 /src/cmd/go/internal/work/exec.go | |
parent | d8c8fd6c305cf34a569e50a8d1f69aa123f9b32f (diff) | |
download | go-730d5f42f919f948ff2841581ecec6fe4b465aee.tar.gz go-730d5f42f919f948ff2841581ecec6fe4b465aee.zip |
[release-branch.go1.15] cmd/go: permit CGO_LDFLAGS to appear in //go:ldflag
For #42565
Fixes #42567
Change-Id: If7cf39905d124dbd54dfac6a53ee38270498efed
Reviewed-on: https://go-review.googlesource.com/c/go/+/269818
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
(cherry picked from commit 782cf560db4c919790fdb476d1bbe18e5ddf5ffd)
Reviewed-on: https://go-review.googlesource.com/c/go/+/270137
Diffstat (limited to 'src/cmd/go/internal/work/exec.go')
-rw-r--r-- | src/cmd/go/internal/work/exec.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 13d4c8cbb4..dc0c4fc344 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2766,6 +2766,21 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo idx = bytes.Index(src, []byte(cgoLdflag)) } } + + // We expect to find the contents of cgoLDFLAGS in flags. + if len(cgoLDFLAGS) > 0 { + outer: + for i := range flags { + for j, f := range cgoLDFLAGS { + if f != flags[i+j] { + continue outer + } + } + flags = append(flags[:i], flags[i+len(cgoLDFLAGS):]...) + break + } + } + if err := checkLinkerFlags("LDFLAGS", "go:cgo_ldflag", flags); err != nil { return nil, nil, err } |