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?

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • 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 '19 at 12:14
  • 1
    `/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 '19 at 14:41
  • Could you detail what headers you are looking for in `/usr/src/linux-headers-*/arch/x86/include/`? – Qeole Jun 06 '19 at 09:40
  • @Qeole I'm including and that ends up pulling from there. – Albert Vaca Cintora Jun 07 '19 at 19:01
  • Hmm I don't need to pass any `-I` flag when including `` on my machine :/. Any chance you could provide a minimal example + command line you use to compile? – Qeole Jun 08 '19 at 13:05
  • `linux/ptrace.h` includes `linux/sched.h` which includes `linux/cputime.h` which includes `asm/cputime.h` which is arch-specific. This is with kernel 4.9. – Albert Vaca Cintora Jun 10 '19 at 13:56

0 Answers0