Skip to content

Commit

Permalink
for s390x arch the auto generated objects need to have s390x prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Jan 16, 2024
1 parent bfbacc1 commit 26e3445
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
33 changes: 17 additions & 16 deletions cmd/bpf2go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ Options:
// 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"},
"386": {"bpfel", "x86", "x86"},
"amd64": {"bpfel", "x86", "x86"},
"arm": {"bpfel", "arm", "arm"},
"arm64": {"bpfel", "arm64", "arm64"},
"loong64": {"bpfel", "loongarch", "loongarch"},
"mips": {"bpfeb", "mips", "mips"},
"mipsle": {"bpfel", "", ""},
"mips64": {"bpfeb", "", ""},
"mips64le": {"bpfel", "", ""},
"ppc64": {"bpfeb", "powerpc", "powerpc"},
"ppc64le": {"bpfel", "powerpc", "powerpc"},
"riscv64": {"bpfel", "riscv", "riscv"},
"s390x": {"bpfeb", "s390", "s390x"},
}

func run(stdout io.Writer, pkg, outputDir string, args []string) (err error) {
Expand Down Expand Up @@ -309,7 +309,7 @@ func (b2g *bpf2go) convert(tgt target, goarches []goarch) (err error) {
}
stem := fmt.Sprintf("%s_%s", outputStem, tgt.clang)
if tgt.linux != "" {
stem = fmt.Sprintf("%s_%s_%s", outputStem, tgt.clang, tgt.linux)
stem = fmt.Sprintf("%s_%s_%s", outputStem, tgt.clang, tgt.goarch)
}

objFileName := filepath.Join(b2g.outputDir, stem+".o")
Expand Down Expand Up @@ -421,7 +421,8 @@ type target struct {
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
linux string
goarch string
}

type goarch string
Expand Down Expand Up @@ -458,7 +459,7 @@ func collectTargets(targets []string) (map[target][]goarch, error) {
}
}
slices.Sort(goarches)
result[target{tgt, ""}] = goarches
result[target{tgt, "", ""}] = goarches

case "native":
tgt = runtime.GOARCH
Expand Down
18 changes: 12 additions & 6 deletions cmd/bpf2go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,28 @@ func TestCollectTargets(t *testing.T) {
{
[]string{"bpf", "bpfel", "bpfeb"},
map[target][]goarch{
{"bpf", ""}: nil,
{"bpfel", ""}: clangArches["bpfel"],
{"bpfeb", ""}: clangArches["bpfeb"],
{"bpf", "", ""}: nil,
{"bpfel", "", ""}: clangArches["bpfel"],
{"bpfeb", "", ""}: clangArches["bpfeb"],
},
},
{
[]string{"amd64", "386"},
map[target][]goarch{
{"bpfel", "x86"}: linuxArchesLE["x86"],
{"bpfel", "x86", "x86"}: linuxArchesLE["x86"],
},
},
{
[]string{"amd64", "ppc64"},
map[target][]goarch{
{"bpfeb", "powerpc"}: linuxArchesBE["powerpc"],
{"bpfel", "x86"}: linuxArchesLE["x86"],
{"bpfeb", "powerpc", "powerpc"}: linuxArchesBE["powerpc"],
{"bpfel", "x86", "x86"}: linuxArchesLE["x86"],
},
},
{
[]string{"s390x"},
map[target][]goarch{
{"bpfeb", "s390", "s390x"}: linuxArchesBE["s390"],
},
},
{
Expand Down

0 comments on commit 26e3445

Please sign in to comment.