Skip to content

Commit

Permalink
elf/symbol: Add find_extern_symbol()
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Aug 7, 2024
1 parent a20fd6e commit 199ae6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/elf/elf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ void free_symbol(struct symbol *s);
void rb_free_symbol(struct rb_node *node);
int link_symbol(struct elf_file *elf, struct symbol *s);
struct symbol *find_symbol(struct elf_file *elf, const char *name, int type);
struct symbol *find_extern_symbol(struct elf_file *elf, const char *name,
int type);
int for_each_symbol(struct elf_file *elf, void (*handler)(struct elf_file *,
struct symbol *,
void *),
Expand Down
16 changes: 14 additions & 2 deletions src/elf/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,31 @@ struct symbol *alloc_symbol(const char *name, const GElf_Sym *sym)
return s;
}

struct symbol *find_symbol(struct elf_file *elf, const char *name, int type)
struct symbol *__find_symbol(struct elf_file *elf, const char *name, int type,
bool ext)
{
struct symbol tmp = {
.name = (char *)name,
.type = type,
.is_extern = false,
.is_extern = ext,
};
struct rb_node *node = rb_search_node(&elf->elf_file_symbols,
cmp_symbol_name,
(unsigned long)&tmp);
return node ? rb_entry(node, struct symbol, node) : NULL;
}

struct symbol *find_symbol(struct elf_file *elf, const char *name, int type)
{
return __find_symbol(elf, name, type, false);
}

struct symbol *find_extern_symbol(struct elf_file *elf, const char *name,
int type)
{
return __find_symbol(elf, name, type, true);
}

int for_each_symbol(struct elf_file *elf, void (*handler)(struct elf_file *,
struct symbol *,
void *),
Expand Down

0 comments on commit 199ae6f

Please sign in to comment.