-
Notifications
You must be signed in to change notification settings - Fork 5
/
elf.c
62 lines (50 loc) · 1.4 KB
/
elf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (c) 2009 Message Systems, Inc. All rights reserved
* For licensing information, see:
* https://bitbucket.org/wez/gimli/src/tip/LICENSE
*/
#ifndef __MACH__
#include "impl.h"
static int for_each_symbol(struct gimli_elf_ehdr *elf,
struct gimli_elf_symbol *sym, void *arg)
{
gimli_mapped_object_t f = arg;
#if 0
/* ignore non-code symbols */
if (GIMLI_ELF_TYPE(sym->st_info) != GIMLI_STT_FUNC) {
return 0;
}
#endif
sym->st_value += f->base_addr;
if (sym->st_size && sym->name[0] && !strchr(sym->name, '.') &&
!strchr(sym->name, '$')) {
gimli_add_symbol(f, sym->name, sym->st_value, sym->st_size);
return 1;
}
return 0;
}
int gimli_process_elf(gimli_mapped_object_t f)
{
char altpath[1024];
if (!f->elf) return 0;
#ifdef __linux
/* LSB says that debugging versions may be present in /usr/lib/debug,
* so let's try those first */
snprintf(altpath, sizeof(altpath)-1, "/usr/lib/debug%s.debug", f->objname);
f->aux_elf = gimli_elf_open(altpath);
if (!f->aux_elf) {
/* ubuntu has it without the .debug suffix */
snprintf(altpath, sizeof(altpath)-1, "/usr/lib/debug%s", f->objname);
f->aux_elf = gimli_elf_open(altpath);
}
#endif
gimli_elf_enum_symbols(f->elf, for_each_symbol, f);
if (f->aux_elf) {
f->aux_elf->gobject = f;
gimli_elf_enum_symbols(f->aux_elf, for_each_symbol, f);
}
return 1;
}
#endif
/* vim:ts=2:sw=2:et:
*/