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
This commit is contained in:
Motomu Utsumi 2025-03-18 15:06:34 +09:00 • committed by Maciej Żenczykowski
commit b3d3c2ae57

View file

@ -17,6 +17,7 @@
#define LOG_TAG "NetBpfLoad"
#include <arpa/inet.h>
#include <bpf/btf.h>
#include <bpf/libbpf.h>
#include <dirent.h>
#include <elf.h>
@ -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<char> 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<unique_fd>& mapFds,
const char* prefix, const unsigned int bpfloader_ver) {
int ret;