Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(selftest): handle arm64 function names #350

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion selftest/global-variable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"reflect"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -60,7 +61,8 @@ func main() {
if err != nil {
exitWithErr(err)
}
if _, err := prog.AttachKprobe("__x64_sys_mmap"); err != nil {
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
if _, err := prog.AttachKprobe(funcName); err != nil {
exitWithErr(err)
}

Expand Down Expand Up @@ -96,3 +98,14 @@ func main() {
rb.Stop()
rb.Close()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}
2 changes: 1 addition & 1 deletion selftest/iter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
thisPid := syscall.Getpid()
pids := make(map[int]*os.Process, 0)
for i := 0; i < totalExecs; i++ {
cmd := exec.Command("ping", "-w", "15", "8.8.8.8")
cmd := exec.Command("ping", "-w", "10", "8.8.8.8")
err := cmd.Start()
if err != nil {
exitWithErr(err)
Expand Down
15 changes: 14 additions & 1 deletion selftest/map-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "C"

import (
"os"
"runtime"
"time"
"unsafe"

Expand Down Expand Up @@ -79,7 +80,8 @@ func main() {
value2Unsafe := unsafe.Pointer(&value2[0])
testerMap.Update(key2Unsafe, value2Unsafe)

_, err = prog.AttachKprobe("__x64_sys_mmap")
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
_, err = prog.AttachKprobe(funcName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
Expand Down Expand Up @@ -116,3 +118,14 @@ func main() {
pb.Stop()
pb.Close()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}
4 changes: 4 additions & 0 deletions selftest/multiple-objects/first.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include "map.bpf.h"

// Large instruction count
#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_openat")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_openat")
#endif
int openat_fentry(struct pt_regs* ctx)
{
bpf_printk("openat (multiple objects-1)");
Expand Down
4 changes: 4 additions & 0 deletions selftest/multiple-objects/second.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include "map.bpf.h"

// Large instruction count
#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_mmap")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_mmap")
#endif
int mmap_fentry(struct pt_regs* ctx)
{
bpf_printk("Mmap (multiple objects-2)");
Expand Down
12 changes: 12 additions & 0 deletions selftest/object-iterator/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ struct {
__uint(max_entries, 1);
} two SEC(".maps");

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_mmap")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_mmap")
#endif
int mmap_fentry(struct pt_regs *ctx)
{
return 0;
}

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_execve")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_execve")
#endif
int execve_fentry(struct pt_regs *ctx)
{
return 0;
}

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_execveat")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_execveat")
#endif
int execveat_fentry(struct pt_regs *ctx)
{
return 0;
Expand Down
4 changes: 4 additions & 0 deletions selftest/percpu/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ struct {
__type(value, __u64);
} percpu_hash SEC(".maps");

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_mmap")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_mmap")
#endif
int mmap_fentry(struct pt_regs *ctx)
{
__u32 key = 0;
Expand Down
15 changes: 14 additions & 1 deletion selftest/perfbuffers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "C"

import (
"os"
"runtime"

"encoding/binary"
"fmt"
Expand Down Expand Up @@ -49,7 +50,8 @@ func main() {
os.Exit(-1)
}

_, err = prog.AttachKprobe("__x64_sys_mmap")
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
_, err = prog.AttachKprobe(funcName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
Expand Down Expand Up @@ -92,3 +94,14 @@ recvLoop:
pb.Close()
pb.Stop()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}
15 changes: 14 additions & 1 deletion selftest/ringbuffers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "C"

import (
"os"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -50,7 +51,8 @@ func main() {
os.Exit(-1)
}

_, err = prog.AttachKprobe("__x64_sys_mmap")
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
_, err = prog.AttachKprobe(funcName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
Expand Down Expand Up @@ -92,3 +94,14 @@ recvLoop:
rb.Close()
rb.Stop()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}
15 changes: 14 additions & 1 deletion selftest/set-attach/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "C"
import (
"encoding/binary"
"os"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -32,7 +33,8 @@ func main() {
// prog.SetProgramType(bpf.BPFProgTypeTracing)
prog.SetAttachType(bpf.BPFAttachTypeTraceFentry)

err = prog.SetAttachTarget(0, "__x64_sys_mmap")
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
err = prog.SetAttachTarget(0, funcName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
Expand Down Expand Up @@ -79,3 +81,14 @@ recvLoop:
rb.Stop()
rb.Close()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}
4 changes: 4 additions & 0 deletions selftest/spinlocks/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ struct {
__uint(max_entries, 1 << 24);
} events SEC(".maps");

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_mmap")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_mmap")
#endif
int mmap_fentry(struct pt_regs *ctx)
{
int *process;
Expand Down
4 changes: 4 additions & 0 deletions selftest/tracing/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ struct {
} events SEC(".maps");
long ringbuffer_flags = 0;

#ifdef __TARGET_ARCH_amd64
SEC("fentry/__x64_sys_mmap")
#elif defined(__TARGET_ARCH_arm64)
SEC("fentry/__arm64_sys_mmap")
#endif
int mmap_fentry(struct pt_regs *ctx)
{
int *process;
Expand Down
15 changes: 14 additions & 1 deletion selftest/tracing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "C"
import (
"encoding/binary"
"os"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -34,7 +35,8 @@ func main() {
os.Exit(-1)
}

sym, err := m.GetSymbolByName("system", "__x64_sys_mmap")
funcName := fmt.Sprintf("__%s_sys_mmap", ksymArch())
sym, err := m.GetSymbolByName("system", funcName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
Expand Down Expand Up @@ -90,3 +92,14 @@ recvLoop:
rb.Stop()
rb.Close()
}

func ksymArch() string {
switch runtime.GOARCH {
case "amd64":
return "x64"
case "arm64":
return "arm64"
default:
panic("unsupported architecture")
}
}