-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelf_symtab.c
More file actions
70 lines (54 loc) · 1.4 KB
/
elf_symtab.c
File metadata and controls
70 lines (54 loc) · 1.4 KB
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
62
63
64
65
66
67
68
69
70
/*
Copyright (C) 2009 Red Hat Inc.
Copyright (C) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
*/
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "dutil.h"
#include "elf_symtab.h"
#define HASHSYMS__BITS 8
#define HASHSYMS__SIZE (1UL << HASHSYMS__BITS)
struct elf_symtab *elf_symtab__new(const char *name, Elf *elf, GElf_Ehdr *ehdr)
{
if (name == NULL)
name = ".symtab";
GElf_Shdr shdr;
Elf_Scn *sec = elf_section_by_name(elf, ehdr, &shdr, name, NULL);
if (sec == NULL)
return NULL;
if (gelf_getshdr(sec, &shdr) == NULL)
return NULL;
struct elf_symtab *self = malloc(sizeof(*self));
if (self == NULL)
return NULL;
self->name = strdup(name);
if (self->name == NULL)
goto out_delete;
self->syms = elf_getdata(sec, NULL);
if (self->syms == NULL)
goto out_free_name;
sec = elf_getscn(elf, shdr.sh_link);
if (sec == NULL)
goto out_free_name;
self->symstrs = elf_getdata(sec, NULL);
if (self->symstrs == NULL)
goto out_free_name;
self->nr_syms = shdr.sh_size / shdr.sh_entsize;
return self;
out_free_name:
free(self->name);
out_delete:
free(self);
return NULL;
}
void elf_symtab__delete(struct elf_symtab *self)
{
if (self == NULL)
return;
free(self->name);
free(self);
}