Re: Support for gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hello, I use gcc 12.1.0 to compile a source file:
> t.c
> struct t {
>   int a:2;
>   int b:3;
>   int c:2;
> } g;
> with gcc -c -gbtf t.c
> and try to use libbpf API btf__parse_split, bpf_object__open, and
> bpf_object__open to parse and load into the kernel, but it failed with
> "libbpf: elf: /path/to/t.o is not a valid eBPF object file".
>
> Is it wrong for me to do so? Due to some constraint, I cannot use
> clang but gcc. How to parse and load gcc compiled object file with
> libbpf?

It seems to me that you are most likely using a GCC targetted at your
local architecture (x86_64-linux-gnu perhaps?) instead of
bpf-unknown-none.

(Note that GCC can generate BTF for any target, not just BPF.)

So you need a bpf-unknown-none-gcc toolchain.
You can either:

a) Install a pre-compiled cross available in your distro.
   Debian ships gcc-bpf, for example.  See
   https://gcc.gnu.org/wiki/BPFBackEnd for a list.

or,

b) Build crossed versions of binutils and gcc, configuring with
   --target=bpf-unknown-none.

or,

c) Use crosstool-ng to build a GCC BPF cross.  We recently added support
   for bpf-unknown-none there.

Hope this helps.



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux