From b3d3c2ae577f41b1d6e656d1fc55dd3df158d033 Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Tue, 18 Mar 2025 15:06:34 +0900 Subject: [PATCH] Add method to update btf_type.size for BTF_KIND_DATASEC size in btf_type of BTF_KIND_DATASEC is 0 at compilation time. So bpf loader needs to update to actual size based on ELF's section size. Bug: 403381101 Test: boot Change-Id: I78fb26a5b8eeb120044b5737667f472fac51d79f --- bpf/loader/NetBpfLoad.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index f8691fd06b..64ebe0c577 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "NetBpfLoad" #include +#include #include #include #include @@ -649,6 +650,24 @@ static bool mapMatchesExpectations(const unique_fd& fd, const string& mapName, return false; } +static int setBtfDatasecSize(ifstream &elfFile, struct btf *btf, + struct btf_type *bt) { + const char *name = btf__name_by_offset(btf, bt->name_off); + if (!name) { + ALOGE("Couldn't resolve section name, errno: %d", errno); + return -errno; + } + + vector data; + int ret = readSectionByName(name, elfFile, data); + if (ret) { + ALOGE("Couldn't read section %s, ret: %d", name, ret); + return ret; + } + bt->size = data.size(); + return 0; +} + static int createMaps(const char* elfPath, ifstream& elfFile, vector& mapFds, const char* prefix, const unsigned int bpfloader_ver) { int ret;