BPF List
 help / color / mirror / Atom feed
* [RFC] libbbpf/bpftool: Support 32-bit Architectures.
@ 2023-02-15 14:12 Puranjay Mohan
  2023-02-16  1:42 ` Stanislav Fomichev
  0 siblings, 1 reply; 12+ messages in thread
From: Puranjay Mohan @ 2023-02-15 14:12 UTC (permalink / raw)
  To: bpf, quentin, ast, daniel, memxor

The BPF selftests fail to compile on 32-bit architectures as the skeleton
generated by bpftool doesn’t take into consideration the size difference of
variables on 32-bit/64-bit architectures.

As an example,
If a bpf program has a global variable of type: long, its skeleton will include
a bss map that will have a field for this variable. The long variable in BPF is
64-bit. if we are working on a 32-bit machine, the generated skeleton has to
compile for that machine where long is 32-bit.

A reproducer for this issue:
        root@56ec59aa632f:~# cat test.bpf.c
        long var;

        root@56ec59aa632f:~# clang -target bpf -g -c test.bpf.c

        root@56ec59aa632f:~# bpftool btf dump file test.bpf.o format raw
        [1] INT 'long int' size=8 bits_offset=0 nr_bits=64 encoding=SIGNED
        [2] VAR 'var' type_id=1, linkage=global
        [3] DATASEC '.bss' size=0 vlen=1
               type_id=2 offset=0 size=8 (VAR 'var')

       root@56ec59aa632f:~# bpftool gen skeleton test.bpf.o > skeleton.h

       root@56ec59aa632f:~# echo "#include \"skeleton.h\"" > test.c

       root@56ec59aa632f:~# gcc test.c
       In file included from test.c:1:
       skeleton.h: In function 'test_bpf__assert':
       skeleton.h:231:2: error: static assertion failed: "unexpected
size of \'var\'"
         231 |  _Static_assert(sizeof(s->bss->var) == 8, "unexpected
size of 'var'");
                |  ^~~~~~~~~~~~~~

One naive solution for this would be to map ‘long’ to ‘long long’ and
‘unsigned long’ to ‘unsigned long long’. But this doesn’t solve everything
because this problem is also seen with pointers that are 64-bit in BPF and
32-bit in 32-bit machines.

I want to work on solving this and am looking for ideas to solve it efficiently.
The main goal is to make libbbpf/bpftool host architecture agnostic.

Thanks,
Puranjay Mohan.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-02-28  6:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-15 14:12 [RFC] libbbpf/bpftool: Support 32-bit Architectures Puranjay Mohan
2023-02-16  1:42 ` Stanislav Fomichev
2023-02-16 22:13   ` Andrii Nakryiko
2023-02-17 10:25     ` Puranjay Mohan
2023-02-17 11:59       ` Quentin Monnet
2023-02-17 21:56         ` Andrii Nakryiko
2023-02-20 11:28           ` Quentin Monnet
2023-02-28  6:31             ` Andrii Nakryiko
2023-02-17 21:45       ` Andrii Nakryiko
2023-02-18 13:23         ` Puranjay Mohan
2023-02-20 16:30           ` Ilya Leoshkevich
2023-02-20 16:47             ` Puranjay Mohan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox