return r;
}
-static Elf_Scn* pakfire_file_get_elf_section(struct pakfire_file* file,
- Elf* elf, const Elf64_Word type) {
- Elf_Scn* section = NULL;
+static int pakfire_file_get_elf_section(struct pakfire_file* file,
+ Elf* elf, const Elf64_Word type, Elf_Scn** section, GElf_Shdr* header, Elf_Data** data) {
+ Elf_Scn* s = NULL;
+
GElf_Shdr shdr;
// Walk through all sections
for (;;) {
- section = elf_nextscn(elf, section);
- if (!section)
+ s = elf_nextscn(elf, s);
+ if (!s)
break;
// Fetch the section header
- gelf_getshdr(section, &shdr);
+ gelf_getshdr(s, &shdr);
// Return any matching sections
- if (shdr.sh_type == type)
- return section;
+ if (shdr.sh_type == type) {
+ *section = s;
+
+ // Send header if requested
+ if (header)
+ gelf_getshdr(s, header);
+
+ // Send data if requested
+ if (data)
+ *data = elf_getdata(s, NULL);
+
+ return 0;
+ }
}
// No section found
- return NULL;
+ return 1;
}
static int __pakfire_file_get_elf_type(struct pakfire_file* file, Elf* elf, void* data) {
}
static int __pakfire_file_check_debuginfo(struct pakfire_file* file, Elf* elf, void* data) {
+ Elf_Scn* symtab = NULL;
+ int r;
+
// Fetch the symbol table
- Elf_Scn* symtab = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB);
+ r = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB, &symtab, NULL, NULL);
// Not found
- if (!symtab) {
+ if (r) {
DEBUG(file->pakfire, "%s has no debug sections\n", file->path);
// Store the result
Elf_Data* elf_data = NULL;
GElf_Sym symbol;
const char* name = NULL;
+ int r;
// Fetch the symbol table
- symtab = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB);
- if (!symtab) {
+ r = pakfire_file_get_elf_section(file, elf, SHT_SYMTAB, &symtab, &shdr, &elf_data);
+ if (r) {
ERROR(file->pakfire, "%s has no symbol table\n", file->path);
return 1;
}
- // Fetch the section header
- gelf_getshdr(symtab, &shdr);
-
// Count any global functions
size_t counter = 0;
- // Fetch a pointer to the section data
- elf_data = elf_getdata(symtab, NULL);
-
// Walk through all symbols
for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
gelf_getsym(elf_data, i, &symbol);