1

I'm building an eBPF program. For it to build I need to add as include paths (-I) some headers located in /usr/src/linux-headers-*/arch/x86/include.

Since this path is x86-specific, to be able to compile it for non-x86 architectures I will need to pick the right path as part of the build process.

However, the names of the architectures used in the Linux sources don't match those returned by uname -m. Eg, if uname -m returns x86_64 I need to include arch/x86/include, but if uname -m returns aarch64, then I need to include arch/arm64/include.

Is there a way to find which is the right arch/* to include, without the need to use a mapping (uname -m -> arch path) for all my supported architectures?

  • Since I'm new I can't tag this as ebpf (because it's not a popular tag), but it would be nice if someone can do it. – Albert Vaca Cintora May 17 at 12:14
  • /lib/modules/$(uname -r)/source/Makefile contains the mapping (and .../build/Makefile knows how to find it); that’s how out-of-tree kernel modules get the right includes. There might be a way of re-using that for eBPF builds... – Stephen Kitt May 17 at 14:41
  • Could you detail what headers you are looking for in /usr/src/linux-headers-*/arch/x86/include/? – Qeole Jun 6 at 9:40
  • @Qeole I'm including <linux/ptrace.h> and that ends up pulling from there. – Albert Vaca Cintora Jun 7 at 19:01
  • Hmm I don't need to pass any -I flag when including <linux/ptrace.h> on my machine :/. Any chance you could provide a minimal example + command line you use to compile? – Qeole Jun 8 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.