enable btf for offload.o & test.o

The objdump -x visible changes between old and new versions of the
mainline shipped .o files are really very minimal: just the inclusion
of a new .BTF section and changes/removals of some 'l' entries from
the symbol table.  However, it turns out a change to symbol ordering
is incompatible with BpfLoader <v0.10 which doesn't know to skip
non-function symbols, and as such enabling btf requires a little
bit of gymnastics.

After:
  $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/*.o
  -rw-r--r-- 1 system system 118352 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload.o
  -rw-r--r-- 1 system system 123424 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload@btf.o
  -rw-r--r-- 1 system system   2232 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test.o
  -rw-r--r-- 1 system system   6376 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test@btf.o

$ adbz shell logcat -d | egrep offload.*[.]o
07-15 13:10:43.358     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload.o with license Apache 2.0
07-15 13:10:43.359     0     0 I LibBpfLoader: BpfLoader version 0x00019 ignoring ELF object /apex/com.android.tethering/etc/bpf/offload.o with max ver 0x00019
07-15 13:10:43.359     0     0 I bpfloader: Loaded object: /apex/com.android.tethering/etc/bpf/offload.o
07-15 13:10:43.374     0     0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with license Apache 2.0
07-15 13:10:43.375     0     0 I LibBpfLoader: BpfLoader version 0x00019 processing ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with ver [0x00019,0x10000)
07-15 13:10:43.452     0     0 D LibBpfLoader: map_fd found at 0 is 6 in /apex/com.android.tethering/etc/bpf/offload@btf.o
...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id658818d1d42763358747523615b7918d312588e
This commit is contained in:
Maciej Żenczykowski 2022-04-23 12:33:32 -07:00
parent 16e244ed0f
commit 07d3013b0d
6 changed files with 42 additions and 0 deletions

View File

@ -88,7 +88,9 @@ apex {
"dscp_policy.o",
"netd.o",
"offload.o",
"offload@btf.o",
"test.o",
"test@btf.o",
],
apps: [
"ServiceConnectivityResources",

View File

@ -91,6 +91,17 @@ bpf {
],
}
bpf {
name: "offload@btf.o",
srcs: ["offload@btf.c"],
btf: true,
cflags: [
"-Wall",
"-Werror",
"-DBTF",
],
}
bpf {
name: "test.o",
srcs: ["test.c"],
@ -100,6 +111,17 @@ bpf {
],
}
bpf {
name: "test@btf.o",
srcs: ["test@btf.c"],
btf: true,
cflags: [
"-Wall",
"-Werror",
"-DBTF",
],
}
bpf {
name: "clatd.o",
srcs: ["clatd.c"],

View File

@ -24,8 +24,16 @@
#define __kernel_udphdr udphdr
#include <linux/udp.h>
#ifdef BTF
// BTF is incompatible with bpfloaders < v0.10, hence for S (v0.2) we must
// ship a different file than for later versions, but we need bpfloader v0.25+
// for obj@ver.o support
#define BPFLOADER_MIN_VER BPFLOADER_OBJ_AT_VER_VERSION
#else /* BTF */
// The resulting .o needs to load on the Android S bpfloader
#define BPFLOADER_MIN_VER BPFLOADER_S_VERSION
#define BPFLOADER_MAX_VER BPFLOADER_OBJ_AT_VER_VERSION
#endif /* BTF */
#include "bpf_helpers.h"
#include "bpf_net_helpers.h"

1
bpf_progs/offload@btf.c Symbolic link
View File

@ -0,0 +1 @@
offload.c

View File

@ -18,8 +18,16 @@
#include <linux/in.h>
#include <linux/ip.h>
#ifdef BTF
// BTF is incompatible with bpfloaders < v0.10, hence for S (v0.2) we must
// ship a different file than for later versions, but we need bpfloader v0.25+
// for obj@ver.o support
#define BPFLOADER_MIN_VER BPFLOADER_OBJ_AT_VER_VERSION
#else /* BTF */
// The resulting .o needs to load on the Android S bpfloader
#define BPFLOADER_MIN_VER BPFLOADER_S_VERSION
#define BPFLOADER_MAX_VER BPFLOADER_OBJ_AT_VER_VERSION
#endif /* BTF */
#include "bpf_helpers.h"
#include "bpf_net_helpers.h"

1
bpf_progs/test@btf.c Symbolic link
View File

@ -0,0 +1 @@
test.c