Repository: cilium/ebpf
Pull request #1310 (2024-01-16 15:32:39)

cmd/bpf2go: clean up goarch / clang / linux target handling
cmd/bpf2go: make arch / targets more distinct

    The bpf2go target selection code is currently pretty confusing since it
    deals with three different but related concepts:

    1. GOARCH values 2. clang -target names 3. libbpf / linux target names

    Introduce a type goarch and document type target properly.

    Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

cmd/bpf2go: clean up invalid goarches

    Remove invalid GOOS=linux GOARCH=xzy combinations. They clutter the help 
    output and are confusing to users. Add a test to ensure that we only include 
    valid combinations.

    Signed-off-by: Lorenz Bauer <lmb@isovalent.com>



Patch:
diff --git a/cmd/bpf2go/main.go b/cmd/bpf2go/main.go
index a852fcf..8a4fea5 100644
--- a/cmd/bpf2go/main.go
+++ b/cmd/bpf2go/main.go
@@ -16,6 +16,8 @@ import (
 	"sort"
 	"strings"
 
+	"golang.org/x/exp/slices"
+
 	"github.com/cilium/ebpf"
 )
 
@@ -47,28 +49,23 @@ Options:
 //
 // Targets without a Linux string can't be used directly and are only included
 // for the generic bpf, bpfel, bpfeb targets.
-var targetByGoArch = map[string]target{
-	"386":         {"bpfel", "x86"},
-	"amd64":       {"bpfel", "x86"},
-	"amd64p32":    {"bpfel", ""},
-	"arm":         {"bpfel", "arm"},
-	"arm64":       {"bpfel", "arm64"},
-	"loong64":     {"bpfel", "loongarch"},
-	"mipsle":      {"bpfel", ""},
-	"mips64le":    {"bpfel", ""},
-	"mips64p32le": {"bpfel", ""},
-	"ppc64le":     {"bpfel", "powerpc"},
-	"riscv64":     {"bpfel", "riscv"},
-	"armbe":       {"bpfeb", "arm"},
-	"arm64be":     {"bpfeb", "arm64"},
-	"mips":        {"bpfeb", ""},
-	"mips64":      {"bpfeb", ""},
-	"mips64p32":   {"bpfeb", ""},
-	"ppc64":       {"bpfeb", "powerpc"},
-	"s390":        {"bpfeb", "s390"},
-	"s390x":       {"bpfeb", "s390"},
-	"sparc":       {"bpfeb", "sparc"},
-	"sparc64":     {"bpfeb", "sparc"},
+//
+// See https://go.dev/doc/install/source#environment for valid GOARCHes when
+// GOOS=linux.
+var targetByGoArch = map[goarch]target{
+	"386":      {"bpfel", "x86"},
+	"amd64":    {"bpfel", "x86"},
+	"arm":      {"bpfel", "arm"},
+	"arm64":    {"bpfel", "arm64"},
+	"loong64":  {"bpfel", "loongarch"},
+	"mips":     {"bpfeb", "mips"},
+	"mipsle":   {"bpfel", ""},
+	"mips64":   {"bpfeb", ""},
+	"mips64le": {"bpfel", ""},
+	"ppc64":    {"bpfeb", "powerpc"},
+	"ppc64le":  {"bpfel", "powerpc"},
+	"riscv64":  {"bpfel", "riscv"},
+	"s390x":    {"bpfeb", "s390"},
 }
 
 func run(stdout io.Writer, pkg, outputDir string, args []string) (err error) {
@@ -96,7 +93,7 @@ type bpf2go struct {
 	// Valid go identifier.
 	identStem string
 	// Targets to build for.
-	targetArches map[target][]string
+	targetArches map[target][]goarch
 	// C compiler.
 	cc string
 	// Command used to strip DWARF.
@@ -298,7 +295,7 @@ func (b2g *bpf2go) convertAll() (err error) {
 	return nil
 }
 
-func (b2g *bpf2go) convert(tgt target, arches []string) (err error) {
+func (b2g *bpf2go) convert(tgt target, goarches []goarch) (err error) {
 	removeOnError := func(f *os.File) {
 		if err != nil {
 			os.Remove(f.Name())
@@ -323,8 +320,8 @@ func (b2g *bpf2go) convert(tgt target, arches []string) (err error) {
 	}
 
 	var archConstraint constraint.Expr
-	for _, arch := range arches {
-		tag := &constraint.TagExpr{Tag: arch}
+	for _, goarch := range goarches {
+		tag := &constraint.TagExpr{Tag: string(goarch)}
 		archConstraint = orConstraints(archConstraint, tag)
 	}
 
@@ -419,17 +416,23 @@ func (b2g *bpf2go) convert(tgt target, arches []string) (err error) {
 }
 
 type target struct {
+	// Clang arch string, used to define the clang -target flag, as per
+	// "clang -print-targets".
 	clang string
+	// Linux arch string, used to define __TARGET_ARCH_xzy macros used by
+	// https://github.com/libbpf/libbpf/blob/master/src/bpf_tracing.h
 	linux string
 }
 
+type goarch string
+
 func printTargets(w io.Writer) {
 	var arches []string
-	for arch, archTarget := range targetByGoArch {
+	for goarch, archTarget := range targetByGoArch {
 		if archTarget.linux == "" {
 			continue
 		}
-		arches = append(arches, arch)
+		arches = append(arches, string(goarch))
 	}
 	sort.Strings(arches)
 
@@ -442,19 +445,19 @@ func printTargets(w io.Writer) {
 
 var errInvalidTarget = errors.New("unsupported target")
 
-func collectTargets(targets []string) (map[target][]string, error) {
-	result := make(map[target][]string)
+func collectTargets(targets []string) (map[target][]goarch, error) {
+	result := make(map[target][]goarch)
 	for _, tgt := range targets {
 		switch tgt {
 		case "bpf", "bpfel", "bpfeb":
-			var goarches []string
+			var goarches []goarch
 			for arch, archTarget := range targetByGoArch {
 				if archTarget.clang == tgt {
 					// Include tags for all goarches that have the same endianness.
 					goarches = append(goarches, arch)
 				}
 			}
-			sort.Strings(goarches)
+			slices.Sort(goarches)
 			result[target{tgt, ""}] = goarches
 
 		case "native":
@@ -462,12 +465,12 @@ func collectTargets(targets []string) (map[target][]string, error) {
 			fallthrough
 
 		default:
-			archTarget, ok := targetByGoArch[tgt]
+			archTarget, ok := targetByGoArch[goarch(tgt)]
 			if !ok || archTarget.linux == "" {
 				return nil, fmt.Errorf("%q: %w", tgt, errInvalidTarget)
 			}
 
-			var goarches []string
+			var goarches []goarch
 			for goarch, lt := range targetByGoArch {
 				if lt == archTarget {
 					// Include tags for all goarches that have the same
@@ -476,7 +479,7 @@ func collectTargets(targets []string) (map[target][]string, error) {
 				}
 			}
 
-			sort.Strings(goarches)
+			slices.Sort(goarches)
 			result[archTarget] = goarches
 		}
 	}
diff --git a/docs/examples/getting_started/counter_bpfeb.go b/docs/examples/getting_started/counter_bpfeb.go
index 03496f0..b4ab10c 100644
--- a/docs/examples/getting_started/counter_bpfeb.go
+++ b/docs/examples/getting_started/counter_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/docs/examples/getting_started/counter_bpfel.go b/docs/examples/getting_started/counter_bpfel.go
index 2eaabd2..6e09ca1 100644
--- a/docs/examples/getting_started/counter_bpfel.go
+++ b/docs/examples/getting_started/counter_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/cgroup_skb/bpf_bpfeb.go b/examples/cgroup_skb/bpf_bpfeb.go
index 46fcc5d..3b716c9 100644
--- a/examples/cgroup_skb/bpf_bpfeb.go
+++ b/examples/cgroup_skb/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/cgroup_skb/bpf_bpfel.go b/examples/cgroup_skb/bpf_bpfel.go
index b7eb4a1..086736d 100644
--- a/examples/cgroup_skb/bpf_bpfel.go
+++ b/examples/cgroup_skb/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/fentry/bpf_bpfeb.go b/examples/fentry/bpf_bpfeb.go
index 46c4bea..d81f533 100644
--- a/examples/fentry/bpf_bpfeb.go
+++ b/examples/fentry/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/fentry/bpf_bpfel.go b/examples/fentry/bpf_bpfel.go
index 5501d22..467e23d 100644
--- a/examples/fentry/bpf_bpfel.go
+++ b/examples/fentry/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/kprobe/bpf_bpfeb.go b/examples/kprobe/bpf_bpfeb.go
index 5ff2001..07a3b0b 100644
--- a/examples/kprobe/bpf_bpfeb.go
+++ b/examples/kprobe/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/kprobe/bpf_bpfel.go b/examples/kprobe/bpf_bpfel.go
index bc18f91..dcbf486 100644
--- a/examples/kprobe/bpf_bpfel.go
+++ b/examples/kprobe/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/kprobe_percpu/bpf_bpfeb.go b/examples/kprobe_percpu/bpf_bpfeb.go
index 5ff2001..07a3b0b 100644
--- a/examples/kprobe_percpu/bpf_bpfeb.go
+++ b/examples/kprobe_percpu/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/kprobe_percpu/bpf_bpfel.go b/examples/kprobe_percpu/bpf_bpfel.go
index bc18f91..dcbf486 100644
--- a/examples/kprobe_percpu/bpf_bpfel.go
+++ b/examples/kprobe_percpu/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/kprobepin/bpf_bpfeb.go b/examples/kprobepin/bpf_bpfeb.go
index 5ff2001..07a3b0b 100644
--- a/examples/kprobepin/bpf_bpfeb.go
+++ b/examples/kprobepin/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/kprobepin/bpf_bpfel.go b/examples/kprobepin/bpf_bpfel.go
index bc18f91..dcbf486 100644
--- a/examples/kprobepin/bpf_bpfel.go
+++ b/examples/kprobepin/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/ringbuffer/bpf_bpfeb.go b/examples/ringbuffer/bpf_bpfeb.go
index 738a9c5..8a87d84 100644
--- a/examples/ringbuffer/bpf_bpfeb.go
+++ b/examples/ringbuffer/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/ringbuffer/bpf_bpfel.go b/examples/ringbuffer/bpf_bpfel.go
index c001c51..4e7b898 100644
--- a/examples/ringbuffer/bpf_bpfel.go
+++ b/examples/ringbuffer/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/tcprtt/bpf_bpfeb.go b/examples/tcprtt/bpf_bpfeb.go
index 9e39d8c..2a5966e 100644
--- a/examples/tcprtt/bpf_bpfeb.go
+++ b/examples/tcprtt/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/tcprtt/bpf_bpfel.go b/examples/tcprtt/bpf_bpfel.go
index 13c66c3..d599a52 100644
--- a/examples/tcprtt/bpf_bpfel.go
+++ b/examples/tcprtt/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/tcprtt_sockops/bpf_bpfeb.go b/examples/tcprtt_sockops/bpf_bpfeb.go
index a821a7d..4db569a 100644
--- a/examples/tcprtt_sockops/bpf_bpfeb.go
+++ b/examples/tcprtt_sockops/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build (arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64) && linux
+//go:build (mips || mips64 || ppc64 || s390x) && linux
 
 package main
 
diff --git a/examples/tcprtt_sockops/bpf_bpfel.go b/examples/tcprtt_sockops/bpf_bpfel.go
index 3675d72..7e7e724 100644
--- a/examples/tcprtt_sockops/bpf_bpfel.go
+++ b/examples/tcprtt_sockops/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build (386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64) && linux
+//go:build (386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64) && linux
 
 package main
 
diff --git a/examples/tracepoint_in_c/bpf_bpfeb.go b/examples/tracepoint_in_c/bpf_bpfeb.go
index 9fc50cb..f422bb8 100644
--- a/examples/tracepoint_in_c/bpf_bpfeb.go
+++ b/examples/tracepoint_in_c/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/tracepoint_in_c/bpf_bpfel.go b/examples/tracepoint_in_c/bpf_bpfel.go
index 3638d09..dd9c860 100644
--- a/examples/tracepoint_in_c/bpf_bpfel.go
+++ b/examples/tracepoint_in_c/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 
diff --git a/examples/xdp/bpf_bpfeb.go b/examples/xdp/bpf_bpfeb.go
index 5fd2ab7..bcc09fc 100644
--- a/examples/xdp/bpf_bpfeb.go
+++ b/examples/xdp/bpf_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package main
 
diff --git a/examples/xdp/bpf_bpfel.go b/examples/xdp/bpf_bpfel.go
index 3fbd47b..4541c12 100644
--- a/examples/xdp/bpf_bpfel.go
+++ b/examples/xdp/bpf_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package main
 


Test patch:
diff --git a/cmd/bpf2go/main_test.go b/cmd/bpf2go/main_test.go
index 493cde0..f8f595a 100644
--- a/cmd/bpf2go/main_test.go
+++ b/cmd/bpf2go/main_test.go
@@ -2,18 +2,19 @@ package main
 
 import (
 	"bytes"
+	"errors"
 	"fmt"
 	"io"
 	"os"
 	"os/exec"
 	"path/filepath"
 	"runtime"
-	"sort"
 	"strings"
 	"testing"
 
 	"github.com/go-quicktest/qt"
 	"github.com/google/go-cmp/cmp"
+	"golang.org/x/exp/slices"
 )
 
 func TestRun(t *testing.T) {
@@ -127,9 +128,9 @@ func TestDisableStripping(t *testing.T) {
 }
 
 func TestCollectTargets(t *testing.T) {
-	clangArches := make(map[string][]string)
-	linuxArchesLE := make(map[string][]string)
-	linuxArchesBE := make(map[string][]string)
+	clangArches := make(map[string][]goarch)
+	linuxArchesLE := make(map[string][]goarch)
+	linuxArchesBE := make(map[string][]goarch)
 	for arch, archTarget := range targetByGoArch {
 		clangArches[archTarget.clang] = append(clangArches[archTarget.clang], arch)
 		if archTarget.clang == "bpfel" {
@@ -139,18 +140,18 @@ func TestCollectTargets(t *testing.T) {
 		linuxArchesBE[archTarget.linux] = append(linuxArchesBE[archTarget.linux], arch)
 	}
 	for i := range clangArches {
-		sort.Strings(clangArches[i])
+		slices.Sort(clangArches[i])
 	}
 	for i := range linuxArchesLE {
-		sort.Strings(linuxArchesLE[i])
+		slices.Sort(linuxArchesLE[i])
 	}
 	for i := range linuxArchesBE {
-		sort.Strings(linuxArchesBE[i])
+		slices.Sort(linuxArchesBE[i])
 	}
 
-	nativeTarget := make(map[target][]string)
+	nativeTarget := make(map[target][]goarch)
 	for arch, archTarget := range targetByGoArch {
-		if arch == runtime.GOARCH {
+		if arch == goarch(runtime.GOARCH) {
 			if archTarget.clang == "bpfel" {
 				nativeTarget[archTarget] = linuxArchesLE[archTarget.linux]
 			} else {
@@ -162,11 +163,11 @@ func TestCollectTargets(t *testing.T) {
 
 	tests := []struct {
 		targets []string
-		want    map[target][]string
+		want    map[target][]goarch
 	}{
 		{
 			[]string{"bpf", "bpfel", "bpfeb"},
-			map[target][]string{
+			map[target][]goarch{
 				{"bpf", ""}:   nil,
 				{"bpfel", ""}: clangArches["bpfel"],
 				{"bpfeb", ""}: clangArches["bpfeb"],
@@ -174,15 +175,15 @@ func TestCollectTargets(t *testing.T) {
 		},
 		{
 			[]string{"amd64", "386"},
-			map[target][]string{
+			map[target][]goarch{
 				{"bpfel", "x86"}: linuxArchesLE["x86"],
 			},
 		},
 		{
-			[]string{"amd64", "arm64be"},
-			map[target][]string{
-				{"bpfeb", "arm64"}: linuxArchesBE["arm64"],
-				{"bpfel", "x86"}:   linuxArchesLE["x86"],
+			[]string{"amd64", "ppc64"},
+			map[target][]goarch{
+				{"bpfeb", "powerpc"}: linuxArchesBE["powerpc"],
+				{"bpfel", "x86"}:     linuxArchesLE["x86"],
 			},
 		},
 		{
@@ -430,6 +431,23 @@ func TestParseArgs(t *testing.T) {
 	})
 }
 
+func TestGoarches(t *testing.T) {
+	exe, err := exec.LookPath("go")
+	if errors.Is(err, exec.ErrNotFound) {
+		t.Skip("go binary is not in PATH")
+	}
+	qt.Assert(t, qt.IsNil(err))
+
+	for goarch := range targetByGoArch {
+		t.Run(string(goarch), func(t *testing.T) {
+			goEnv := exec.Command(exe, "env")
+			goEnv.Env = []string{"GOOS=linux", "GOARCH=" + string(goarch)}
+			output, err := goEnv.CombinedOutput()
+			qt.Assert(t, qt.IsNil(err), qt.Commentf("go output is:\n%s", string(output)))
+		})
+	}
+}
+
 func clangBin(t *testing.T) string {
 	t.Helper()
 
diff --git a/cmd/bpf2go/test/test_bpfeb.go b/cmd/bpf2go/test/test_bpfeb.go
index 8b2cc82..62d5b43 100644
--- a/cmd/bpf2go/test/test_bpfeb.go
+++ b/cmd/bpf2go/test/test_bpfeb.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build arm64be || armbe || mips || mips64 || mips64p32 || ppc64 || s390 || s390x || sparc || sparc64
+//go:build mips || mips64 || ppc64 || s390x
 
 package test
 
diff --git a/cmd/bpf2go/test/test_bpfel.go b/cmd/bpf2go/test/test_bpfel.go
index 55678e9..94efcde 100644
--- a/cmd/bpf2go/test/test_bpfel.go
+++ b/cmd/bpf2go/test/test_bpfel.go
@@ -1,5 +1,5 @@
 // Code generated by bpf2go; DO NOT EDIT.
-//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
+//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64
 
 package test