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);