Skip to content

(ARM64) Rust Example Tracecon Does Not Compile #247

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

Closed
7anya opened this issue Jan 7, 2024 · 2 comments
Closed

(ARM64) Rust Example Tracecon Does Not Compile #247

7anya opened this issue Jan 7, 2024 · 2 comments

Comments

@7anya
Copy link

7anya commented Jan 7, 2024

When trying to build the examples using cargo build --release, the following errors arise in building tracecon:

error: failed to run custom build command for `tracecon v0.1.0 (/home/tanya/workspace/libbpf-bootstrap/examples/rust/tracecon)`

Caused by:
  process didn't exit successfully: `/home/tanya/workspace/libbpf-bootstrap/examples/rust/target/release/build/tracecon-cbe3e5b4ae219d9a/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at tracecon/build.rs:22:10:
  bpf compilation failed: Build("Failed to compile obj=/tmp/.tmpevJHx5/tracecon.o with status=exit status: 1
 stdout=
 
 stderr=
 ./src/bpf/tracecon.bpf.c:78:5: error: incomplete definition of type 'struct user_pt_regs'
   78 | int BPF_KPROBE(getaddrinfo_enter, const char *hostname, const char *service,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   79 |                const struct addrinfo *hints, struct addrinfo **res)
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:469:20: note: expanded from macro 'BPF_KPROBE'
  469 |         return ____##name(___bpf_kprobe_args(args));                        \\
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:449:41: note: expanded from macro '___bpf_kprobe_args'
  449 | #define ___bpf_kprobe_args(args...)     ___bpf_apply(___bpf_kprobe_args, ___bpf_narg(args))(args)
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_helpers.h:184:29: note: expanded from macro '___bpf_apply'
  184 | #define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
      |                             ^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:445:41: note: expanded from macro '___bpf_kprobe_args2'
  445 | #define ___bpf_kprobe_args2(x, args...) ___bpf_kprobe_args1(args), (void *)PT_REGS_PARM2(ctx)
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:444:72: note: expanded from macro '___bpf_kprobe_args1'
  444 | #define ___bpf_kprobe_args1(x)          ___bpf_kprobe_args0(), (void *)PT_REGS_PARM1(ctx)
      |                                                                        ^~~~~~~~~~~~~~~~~~
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:272:44: note: expanded from macro 'PT_REGS_PARM1'
  272 | #define PT_REGS_PARM1(x) (__PT_REGS_CAST(x)->__PT_PARM1_REG)
      |                           ~~~~~~~~~~~~~~~~~^
./src/bpf/tracecon.bpf.c:78:5: note: forward declaration of 'struct user_pt_regs'
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:469:20: note: expanded from macro 'BPF_KPROBE'
  469 |         return ____##name(___bpf_kprobe_args(args));                        \\
      |                           ^
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:449:41: note: expanded from macro '___bpf_kprobe_args'
  449 | #define ___bpf_kprobe_args(args...)     ___bpf_apply(___bpf_kprobe_args, ___bpf_narg(args))(args)
      |                                         ^
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_helpers.h:184:29: note: expanded from macro '___bpf_apply'
  184 | #define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
      |                             ^
note: (skipping 5 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:444:72: note: expanded from macro '___bpf_kprobe_args1'
  444 | #define ___bpf_kprobe_args1(x)          ___bpf_kprobe_args0(), (void *)PT_REGS_PARM1(ctx)
      |                                                                        ^
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:272:27: note: expanded from macro 'PT_REGS_PARM1'
  272 | #define PT_REGS_PARM1(x) (__PT_REGS_CAST(x)->__PT_PARM1_REG)
      |                           ^
/tmp/.tmp44XFnJ/bpf/src/bpf/bpf_tracing.h:168:42: note: expanded from macro '__PT_REGS_CAST'
  168 | #define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
      |                                          ^

The above error repeats 9 times.

The source of the error is the missing struct user_pt_regs in the examples/rust/tracecon/src/bpf/vmlinux.h

Placing the following code in the file seems to solve the issue:


/*
 * User structures for general purpose, floating point and debug registers.
 * Taken from /usr/include/asm/ptrace.h 
*/
struct user_pt_regs {
	__u64		regs[31];
	__u64		sp;
	__u64		pc;
	__u64		pstate;
};

As noted, the struct is borrowed from the relevant ptrace header for arm64.

@danielocfb
Copy link
Collaborator

I suspect it may be another instance of the "vendored" vmlinux.h being x86 specific (libbpf/libbpf-rs#615).

danielocfb pushed a commit to danielocfb/libbpf-bootstrap that referenced this issue Jan 12, 2024
The example need to include the correct vmlinux.h header for the current
architecture if they aim to build on arches other than x86. Adjust the
logic accordingly.

Fixes: libbpf#247
danielocfb pushed a commit to danielocfb/libbpf-bootstrap that referenced this issue Jan 12, 2024
The example need to include the correct vmlinux.h header for the current
architecture if they aim to build on arches other than x86. Adjust the
logic accordingly.

Fixes: libbpf#247

Signed-off-by: Daniel Müller <[email protected]>
@danielocfb
Copy link
Collaborator

I don't have an ARM64 system at hand, but you can try out #248 and see if it fixes the issue @7anya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants