Lines Matching refs:elfFile

265 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
266 elfFile.seekg(0); in readElfHeader()
267 if (elfFile.fail()) return -1; in readElfHeader()
269 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
275 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
279 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
282 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
283 if (elfFile.fail()) return -1; in readSectionHeadersAll()
288 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
294 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
296 int ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
299 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
300 if (elfFile.fail()) return -1; in readSectionByIdx()
303 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
309 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
311 int ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
314 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
321 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
325 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
335 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
340 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
343 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
354 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
355 if (elfFile.fail()) return -1; in readSectionByName()
357 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
366 unsigned int readSectionUint(const char* name, ifstream& elfFile) { in readSectionUint() argument
368 int ret = readSectionByName(name, elfFile, theBytes); in readSectionUint()
389 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
393 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
402 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
403 if (elfFile.fail()) return -1; in readSectionByType()
405 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
417 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
422 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
440 static int readProgDefs(ifstream& elfFile, vector<struct bpf_prog_def>& pd) { in readProgDefs() argument
442 int ret = readSectionByName("progs", elfFile, pdData); in readProgDefs()
462 static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vector<string>& names, in getSectionSymNames() argument
469 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getSectionSymNames()
473 ret = readSectionHeadersAll(elfFile, shTable); in getSectionSymNames()
478 ret = getSymName(elfFile, shTable[i].sh_name, name); in getSectionSymNames()
498 ret = getSymName(elfFile, symtab[i].st_name, s); in getSectionSymNames()
508 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs) { in readCodeSections() argument
512 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
517 ret = readProgDefs(elfFile, pd); in readCodeSections()
520 ret = getSectionSymNames(elfFile, "progs", progDefNames); in readCodeSections()
528 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
547 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
552 ret = getSectionSymNames(elfFile, oldName, csSymNames, STT_FUNC); in readCodeSections()
563 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
567 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
581 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
585 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
590 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
652 static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds, in createMaps() argument
660 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
679 ret = getSectionSymNames(elfFile, "maps", mapNames); in createMaps()
898 static void applyMapRelo(ifstream& elfFile, vector<unique_fd> &mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
901 int ret = getSectionSymNames(elfFile, "maps", mapNames); in applyMapRelo()
912 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
1118 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
1119 if (!elfFile.is_open()) return -1; in loadProg()
1121 ret = readSectionByName("license", elfFile, license); in loadProg()
1130 unsigned int bpfLoaderMinVer = readSectionUint("bpfloader_min_ver", elfFile); in loadProg()
1131 unsigned int bpfLoaderMaxVer = readSectionUint("bpfloader_max_ver", elfFile); in loadProg()
1150 ret = createMaps(elfPath, elfFile, mapFds, prefix, bpfloader_ver); in loadProg()
1159 ret = readCodeSections(elfFile, cs); in loadProg()
1169 applyMapRelo(elfFile, mapFds, cs); in loadProg()