dutil: Move elf_section_by_name to dutil
Will be used by more than one file. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
4848eef743
commit
8bf5eb9bc8
17
ctf_loader.c
17
ctf_loader.c
|
@ -55,23 +55,6 @@ struct ctf_state {
|
|||
int in_fd;
|
||||
};
|
||||
|
||||
static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
|
||||
GElf_Shdr *shp, const char *name)
|
||||
{
|
||||
Elf_Scn *sec = NULL;
|
||||
|
||||
while ((sec = elf_nextscn(elf, sec)) != NULL) {
|
||||
char *str;
|
||||
|
||||
gelf_getshdr(sec, shp);
|
||||
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
|
||||
if (!strcmp(name, str))
|
||||
break;
|
||||
}
|
||||
|
||||
return sec;
|
||||
}
|
||||
|
||||
struct elf_sym_iter_state {
|
||||
int (*func)(struct ctf_state *sp, const char *sym_name,
|
||||
int sym_index, int call_index, void *data);
|
||||
|
|
17
dutil.c
17
dutil.c
|
@ -108,3 +108,20 @@ int strlist__has_entry(const struct strlist *self, const char *entry)
|
|||
{
|
||||
return tfind(entry, &self->entries, str_compare) != NULL;
|
||||
}
|
||||
|
||||
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
|
||||
GElf_Shdr *shp, const char *name)
|
||||
{
|
||||
Elf_Scn *sec = NULL;
|
||||
|
||||
while ((sec = elf_nextscn(elf, sec)) != NULL) {
|
||||
char *str;
|
||||
|
||||
gelf_getshdr(sec, shp);
|
||||
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
|
||||
if (!strcmp(name, str))
|
||||
break;
|
||||
}
|
||||
|
||||
return sec;
|
||||
}
|
||||
|
|
5
dutil.h
5
dutil.h
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <elf.h>
|
||||
#include <gelf.h>
|
||||
|
||||
#ifndef __unused
|
||||
#define __unused __attribute__ ((unused))
|
||||
|
@ -55,4 +57,7 @@ int strlist__has_entry(const struct strlist *self, const char *entry);
|
|||
|
||||
void *zalloc(const size_t size);
|
||||
|
||||
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
|
||||
GElf_Shdr *shp, const char *name);
|
||||
|
||||
#endif /* _DUTIL_H_ */
|
||||
|
|
Loading…
Reference in New Issue