]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: default to GOARM=7 on all non-arm systems
authorRuss Cox <rsc@golang.org>
Thu, 23 Feb 2023 13:37:08 +0000 (08:37 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 23 Feb 2023 17:50:29 +0000 (17:50 +0000)
If you run make.bash on an arm system without GOARM set,
we sniff the local system to find the maximum default GOARM
that will actually work on that system. That's fine, and we can
keep doing that.

But the story for cross-compiling is weirder.
If we build a windows/amd64 toolchain and then use it to
cross-compile linux/arm binaries, we get GOARM=7 binaries.
Do the same on a linux/amd64 system and you get GOARM=5 binaries.
This clearly makes no sense, and worse it makes the builds
non-reproducible in a subtle way.

This CL simplifies the logic and improves reproducibility by
defaulting to GOARM=7 any time we wouldn't sniff the local system.

On go.dev/dl we serve a linux-armv6l distribution with a default GOARM=6.
That is built by setting GOARM=6 during make.bash, so it is unaffected
by this CL and will continue to be GOARM=6.

For #24904.

Change-Id: I4331709876d5948fd33ec6e4a7b18b3cef12f240
Reviewed-on: https://go-review.googlesource.com/c/go/+/470695
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/dist/util.go

index 0083e9fb4064cd787e0ce5e2040c12940d073e68..2eeab18a93f1b6ffc92acd30c04a4c6465d45f48 100644 (file)
@@ -373,35 +373,36 @@ func xsamefile(f1, f2 string) bool {
 }
 
 func xgetgoarm() string {
-       if goos == "android" {
-               // Assume all android devices have VFPv3.
-               // These ports are also mostly cross-compiled, so it makes little
-               // sense to auto-detect the setting.
-               return "7"
-       }
-       if goos == "windows" {
-               // windows/arm only works with ARMv7 executables.
-               return "7"
-       }
-       if gohostarch != "arm" || goos != gohostos {
-               // Conservative default for cross-compilation.
+       // If we're building on an actual arm system, and not building
+       // a cross-compiling toolchain, try to exec ourselves
+       // to detect whether VFP is supported and set the default GOARM.
+       // Windows requires ARMv7, so we can skip the check.
+       // We've always assumed Android is ARMv7 too.
+       if gohostarch == "arm" && goarch == "arm" && goos == gohostos && goos != "windows" && goos != "android" {
+               // Try to exec ourselves in a mode to detect VFP support.
+               // Seeing how far it gets determines which instructions failed.
+               // The test is OS-agnostic.
+               out := run("", 0, os.Args[0], "-check-goarm")
+               v1ok := strings.Contains(out, "VFPv1 OK.")
+               v3ok := strings.Contains(out, "VFPv3 OK.")
+               if v1ok && v3ok {
+                       return "7"
+               }
+               if v1ok {
+                       return "6"
+               }
                return "5"
        }
 
-       // Try to exec ourselves in a mode to detect VFP support.
-       // Seeing how far it gets determines which instructions failed.
-       // The test is OS-agnostic.
-       out := run("", 0, os.Args[0], "-check-goarm")
-       v1ok := strings.Contains(out, "VFPv1 OK.")
-       v3ok := strings.Contains(out, "VFPv3 OK.")
-
-       if v1ok && v3ok {
-               return "7"
-       }
-       if v1ok {
-               return "6"
-       }
-       return "5"
+       // Otherwise, in the absence of local information, assume GOARM=7.
+       //
+       // We used to assume GOARM=5 in certain contexts but not others,
+       // which produced inconsistent results. For example if you cross-compiled
+       // for linux/arm from a windows/amd64 machine, you got GOARM=7 binaries,
+       // but if you cross-compiled for linux/arm from a linux/amd64 machine,
+       // you got GOARM=5 binaries. Now the default is independent of the
+       // host operating system, for better reproducibility of builds.
+       return "7"
 }
 
 func min(a, b int) int {