From 064bc313542022e0131f98064ab5e1f73164af55 Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Tue, 1 Jun 2021 16:12:43 +0200 Subject: [PATCH] headers/vmlinux: Add arch specific vmlinux.h defines Signed-off-by: Jesper Dangaard Brouer --- headers/vmlinux/arch/x86/vmlinux.h | 29 +++++++++++++++++++++++++++++ headers/vmlinux_local.h | 20 ++++++++++++++++---- ktrace-CO-RE/Makefile | 4 ---- lib/common.mk | 7 +++++++ 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 headers/vmlinux/arch/x86/vmlinux.h diff --git a/headers/vmlinux/arch/x86/vmlinux.h b/headers/vmlinux/arch/x86/vmlinux.h new file mode 100644 index 0000000..d02ec90 --- /dev/null +++ b/headers/vmlinux/arch/x86/vmlinux.h @@ -0,0 +1,29 @@ +#ifndef __VMLINUX_ARCH_X86_H__ +#define __VMLINUX_ARCH_X86_H__ + + +struct pt_regs { + long unsigned int r15; + long unsigned int r14; + long unsigned int r13; + long unsigned int r12; + long unsigned int bp; + long unsigned int bx; + long unsigned int r11; + long unsigned int r10; + long unsigned int r9; + long unsigned int r8; + long unsigned int ax; + long unsigned int cx; + long unsigned int dx; + long unsigned int si; + long unsigned int di; + long unsigned int orig_ax; + long unsigned int ip; + long unsigned int cs; + long unsigned int flags; + long unsigned int sp; + long unsigned int ss; +}; + +#endif /* __VMLINUX_ARCH_X86_H__ */ diff --git a/headers/vmlinux_local.h b/headers/vmlinux_local.h index 6c03fab..53a63e0 100644 --- a/headers/vmlinux_local.h +++ b/headers/vmlinux_local.h @@ -9,10 +9,6 @@ */ #ifndef __VMLINUX_H__ #define __VMLINUX_H__ -/* - * Notice: Defining __VMLINUX_H__ (or __KERNEL__) cause - * header file to define architecture specific PT_REGS_PARM's. - */ #include /* Needed for __uNN in vmlinux/vmlinux_types.h */ @@ -24,6 +20,22 @@ #include "vmlinux/vmlinux_common.h" #include "vmlinux/vmlinux_net.h" +/* + * Notice: Defining __VMLINUX_H__ (or __KERNEL__) cause + * header file to define architecture specific PT_REGS_PARM's. + * + * When using '-target bpf' the fallback mechanism doesn't detect right arch + * via compiler defines. + * + * Makefile system in lib/common.mk detect ARCH and defines the + * defines __TARGET_ARCH_$(ARCH) matched on below. + */ +#if defined(__TARGET_ARCH_x86) +#include "vmlinux/arch/x86/vmlinux.h" +#else +#warning "Makefile for BPF-tracing on this arch: not supported yet" +#endif + #ifndef BPF_NO_PRESERVE_ACCESS_INDEX #pragma clang attribute pop #endif diff --git a/ktrace-CO-RE/Makefile b/ktrace-CO-RE/Makefile index f90ed0a..3c69d6c 100644 --- a/ktrace-CO-RE/Makefile +++ b/ktrace-CO-RE/Makefile @@ -1,9 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -# The BPF tracing header (/usr/include/bpf/bpf_tracing.h) need to know -# CPU architecture due to PT_REGS_PARM resolution of ASM call convention -ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/') - USER_TARGETS := ktrace01 BPF_TARGETS := ktrace01_kern diff --git a/lib/common.mk b/lib/common.mk index 2719d98..798d632 100644 --- a/lib/common.mk +++ b/lib/common.mk @@ -33,6 +33,13 @@ ifeq ($(SYSTEM_LIBBPF),n) LIBBPF_SOURCES := $(wildcard $(LIBBPF_DIR)/src/*.[ch]) endif +# The BPF tracing header (/usr/include/bpf/bpf_tracing.h) need to know +# CPU architecture due to PT_REGS_PARM resolution of ASM call convention +# +ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/') + +BPF_CFLAGS += -D__TARGET_ARCH_$(ARCH) + # BPF-prog kern and userspace shares struct via header file: KERN_USER_H ?= $(wildcard common_kern_user.h)