From ce6cb1dacf8112bc2f0627ac51a50e28ca25a984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Fri, 1 Aug 2025 13:58:02 -0700 Subject: [PATCH] NetBpfLoad: move getSymNameByIdx() & getSymOffsetByName() up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so that elf object related functions are next to each other Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski Change-Id: I159e4e7ad96e3764206546f9f8c69ff156bcf790 --- bpf/loader/NetBpfLoad.cpp | 55 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 5ea606a472..b523a154aa 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -357,6 +357,34 @@ static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vect return 0; } +static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { + vector symtab; + int ret = 0; + + ret = readSymTab(elfFile, 0 /* !sort */, symtab); + if (ret) return ret; + + if (index >= (int)symtab.size()) return -1; + + return getSymName(elfFile, symtab[index].st_name, name); +} + +static int getSymOffsetByName(ifstream &elfFile, const char *name, int *off) { + vector symtab; + int ret = readSymTab(elfFile, 1 /* sort */, symtab); + if (ret) return ret; + for (int i = 0; i < (int)symtab.size(); i++) { + string s; + ret = getSymName(elfFile, symtab[i].st_name, s); + if (ret) continue; + if (!strcmp(s.c_str(), name)) { + *off = symtab[i].st_value; + return 0; + } + } + return -1; +} + // Read a section by its index - for ex to get sec hdr strtab blob static int readCodeSections(ifstream& elfFile, vector& cs) { vector shTable; @@ -434,17 +462,6 @@ static int readCodeSections(ifstream& elfFile, vector& cs) { return 0; } -static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { - vector symtab; - int ret = 0; - - ret = readSymTab(elfFile, 0 /* !sort */, symtab); - if (ret) return ret; - - if (index >= (int)symtab.size()) return -1; - - return getSymName(elfFile, symtab[index].st_name, name); -} static bool mapMatchesExpectations(const unique_fd& fd, const struct bpf_map_def& mapDef, const enum bpf_map_type type) { @@ -521,22 +538,6 @@ static int setBtfDatasecSize(ifstream &elfFile, struct btf *btf, return 0; } -static int getSymOffsetByName(ifstream &elfFile, const char *name, int *off) { - vector symtab; - int ret = readSymTab(elfFile, 1 /* sort */, symtab); - if (ret) return ret; - for (int i = 0; i < (int)symtab.size(); i++) { - string s; - ret = getSymName(elfFile, symtab[i].st_name, s); - if (ret) continue; - if (!strcmp(s.c_str(), name)) { - *off = symtab[i].st_value; - return 0; - } - } - return -1; -} - static int setBtfVarOffset(ifstream &elfFile, struct btf *btf, struct btf_type *datasecBt) { int i, vars = btf_vlen(datasecBt);