|
5 | 5 | package mkuimage
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "bytes" |
8 | 9 | "errors"
|
9 | 10 | "fmt"
|
10 | 11 | "os"
|
| 12 | + "os/exec" |
11 | 13 | "runtime"
|
12 | 14 | "strings"
|
13 | 15 |
|
| 16 | + "github.com/u-root/gobusybox/src/pkg/golang" |
14 | 17 | "github.com/u-root/mkuimage/uimage"
|
15 | 18 | "github.com/u-root/mkuimage/uimage/builder"
|
16 | 19 | "github.com/u-root/mkuimage/uimage/templates"
|
@@ -56,6 +59,32 @@ func uimageOpts(l *llog.Logger, m []uimage.Modifier, tpl *templates.Templates, f
|
56 | 59 | return uimage.OptionsFor(append(m, more...)...)
|
57 | 60 | }
|
58 | 61 |
|
| 62 | +func checkAmd64Level(l *llog.Logger, env *golang.Environ) { |
| 63 | + if env.GOARCH != "amd64" { |
| 64 | + return |
| 65 | + } |
| 66 | + |
| 67 | + // Looking for "amd64.v2" in "env.ToolTags" is unreliable; see |
| 68 | + // <https://github.com/golang/go/issues/72791>. Invoke "go env" instead. |
| 69 | + var bad string |
| 70 | + abiLevel, err := exec.Command("go", "env", "GOAMD64").Output() |
| 71 | + if err == nil { |
| 72 | + if bytes.Equal(abiLevel, []byte("v1\n")) { |
| 73 | + return |
| 74 | + } |
| 75 | + bad = "is not" |
| 76 | + } else { |
| 77 | + if exerr, isExErr := err.(*exec.ExitError); isExErr { |
| 78 | + l.Warnf("\"go env\" failed: %s", exerr.Stderr) |
| 79 | + } else { |
| 80 | + l.Warnf("couldn't execute \"go env\": %s", err) |
| 81 | + } |
| 82 | + bad = "may not be" |
| 83 | + } |
| 84 | + l.Warnf("GOAMD64 %s set to v1; on older CPUs, binaries built into " + |
| 85 | + "the initrd may crash or refuse to run.", bad) |
| 86 | +} |
| 87 | + |
59 | 88 | // CreateUimage creates a uimage with the given base modifiers and flags, using args as the list of commands.
|
60 | 89 | func CreateUimage(l *llog.Logger, base []uimage.Modifier, tf *TemplateFlags, f *Flags, args []string) error {
|
61 | 90 | tpl, err := tf.Get()
|
@@ -95,6 +124,8 @@ func CreateUimage(l *llog.Logger, base []uimage.Modifier, tf *TemplateFlags, f *
|
95 | 124 | l.Warnf("GOOS is not linux. Did you mean to set GOOS=linux?")
|
96 | 125 | }
|
97 | 126 |
|
| 127 | + checkAmd64Level(l, env); |
| 128 | + |
98 | 129 | v, err := env.Version()
|
99 | 130 | if err != nil {
|
100 | 131 | l.Infof("Could not get environment's Go version, using runtime's version: %v", err)
|
|
0 commit comments