diff options
| -rw-r--r-- | meta/recipes-devtools/go/go-1.18.3.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-devtools/go/go/filter-build-paths.patch | 48 |
2 files changed, 49 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.18.3.inc b/meta/recipes-devtools/go/go-1.18.3.inc index 68062952ca..693b045e8f 100644 --- a/meta/recipes-devtools/go/go-1.18.3.inc +++ b/meta/recipes-devtools/go/go-1.18.3.inc | |||
| @@ -13,5 +13,6 @@ SRC_URI += "\ | |||
| 13 | file://0007-cmd-go-make-GOROOT-precious-by-default.patch \ | 13 | file://0007-cmd-go-make-GOROOT-precious-by-default.patch \ |
| 14 | file://0001-exec.go-do-not-write-linker-flags-into-buildids.patch \ | 14 | file://0001-exec.go-do-not-write-linker-flags-into-buildids.patch \ |
| 15 | file://0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \ | 15 | file://0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \ |
| 16 | file://filter-build-paths.patch \ | ||
| 16 | " | 17 | " |
| 17 | SRC_URI[main.sha256sum] = "0012386ddcbb5f3350e407c679923811dbd283fcdc421724931614a842ecbc2d" | 18 | SRC_URI[main.sha256sum] = "0012386ddcbb5f3350e407c679923811dbd283fcdc421724931614a842ecbc2d" |
diff --git a/meta/recipes-devtools/go/go/filter-build-paths.patch b/meta/recipes-devtools/go/go/filter-build-paths.patch new file mode 100644 index 0000000000..caf727714e --- /dev/null +++ b/meta/recipes-devtools/go/go/filter-build-paths.patch | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | Filter out build time paths from ldflags and other flags variables when they're | ||
| 2 | embedded in the go binary so that builds are reproducible regardless of build | ||
| 3 | location. This codepath is hit for statically linked go binaries such as those | ||
| 4 | on mips/ppc. | ||
| 5 | |||
| 6 | Upstream-Status: Pending | ||
| 7 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> | ||
| 8 | |||
| 9 | Index: go/src/cmd/go/internal/load/pkg.go | ||
| 10 | =================================================================== | ||
| 11 | --- go.orig/src/cmd/go/internal/load/pkg.go | ||
| 12 | +++ go/src/cmd/go/internal/load/pkg.go | ||
| 13 | @@ -2225,6 +2225,17 @@ func (p *Package) collectDeps() { | ||
| 14 | // to their VCS information (vcsStatusError). | ||
| 15 | var vcsStatusCache par.Cache | ||
| 16 | |||
| 17 | +func filterCompilerFlags(flags string) string { | ||
| 18 | + var newflags []string | ||
| 19 | + for _, flag := range strings.Fields(flags) { | ||
| 20 | + if strings.HasPrefix(flag, "--sysroot") || strings.HasPrefix(flag, "-fmacro-prefix-map") || strings.HasPrefix(flag, "-fdebug-prefix-map") { | ||
| 21 | + continue | ||
| 22 | + } | ||
| 23 | + newflags = append(newflags, flag) | ||
| 24 | + } | ||
| 25 | + return strings.Join(newflags, " ") | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | // setBuildInfo gathers build information, formats it as a string to be | ||
| 29 | // embedded in the binary, then sets p.Internal.BuildInfo to that string. | ||
| 30 | // setBuildInfo should only be called on a main package with no errors. | ||
| 31 | @@ -2329,7 +2340,7 @@ func (p *Package) setBuildInfo(includeVC | ||
| 32 | appendSetting("-gcflags", BuildGcflags.String()) | ||
| 33 | } | ||
| 34 | if BuildLdflags.present { | ||
| 35 | - appendSetting("-ldflags", BuildLdflags.String()) | ||
| 36 | + appendSetting("-ldflags", filterCompilerFlags(BuildLdflags.String())) | ||
| 37 | } | ||
| 38 | if cfg.BuildMSan { | ||
| 39 | appendSetting("-msan", "true") | ||
| 40 | @@ -2347,7 +2358,7 @@ func (p *Package) setBuildInfo(includeVC | ||
| 41 | appendSetting("CGO_ENABLED", cgo) | ||
| 42 | if cfg.BuildContext.CgoEnabled { | ||
| 43 | for _, name := range []string{"CGO_CFLAGS", "CGO_CPPFLAGS", "CGO_CXXFLAGS", "CGO_LDFLAGS"} { | ||
| 44 | - appendSetting(name, cfg.Getenv(name)) | ||
| 45 | + appendSetting(name, filterCompilerFlags(cfg.Getenv(name))) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | appendSetting("GOARCH", cfg.BuildContext.GOARCH) | ||
