mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-18 02:19:39 +00:00
libkldelf: add elf_lookup_symbol function
The elf_lookup_symbol function looks up the symbol with a given symbol name. A pointer to the GElf_Sym of the symbol is returned if the symbol exists in the opened ELF file. Sponsored by: Juniper Networks, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D46764
This commit is contained in:
parent
0a2cfd653e
commit
2c7d847956
@ -89,6 +89,7 @@ static struct elf_file_ops ef_file_ops = {
|
||||
.seg_read_string = ef_seg_read_string,
|
||||
.symaddr = ef_symaddr,
|
||||
.lookup_set = ef_lookup_set,
|
||||
.lookup_symbol = ef_lookup_symbol,
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -109,6 +109,7 @@ static struct elf_file_ops ef_obj_file_ops = {
|
||||
.seg_read_string = ef_obj_seg_read_string,
|
||||
.symaddr = ef_obj_symaddr,
|
||||
.lookup_set = ef_obj_lookup_set,
|
||||
.lookup_symbol = ef_obj_lookup_symbol,
|
||||
};
|
||||
|
||||
static GElf_Off
|
||||
|
@ -686,3 +686,9 @@ elf_reloc(struct elf_file *efile, const void *reldata, Elf_Type reltype,
|
||||
return (efile->ef_reloc(efile, reldata, reltype, relbase, dataoff, len,
|
||||
dest));
|
||||
}
|
||||
|
||||
int
|
||||
elf_lookup_symbol(struct elf_file *efile, const char *name, GElf_Sym **sym)
|
||||
{
|
||||
return (EF_LOOKUP_SYMBOL(efile, name, sym));
|
||||
}
|
||||
|
@ -48,6 +48,8 @@
|
||||
(ef)->ef_ops->symaddr((ef)->ef_ef, symidx)
|
||||
#define EF_LOOKUP_SET(ef, name, startp, stopp, countp) \
|
||||
(ef)->ef_ops->lookup_set((ef)->ef_ef, name, startp, stopp, countp)
|
||||
#define EF_LOOKUP_SYMBOL(ef, name, sym) \
|
||||
(ef)->ef_ops->lookup_symbol((ef)->ef_ef, name, sym)
|
||||
|
||||
/* XXX, should have a different name. */
|
||||
typedef struct ef_file *elf_file_t;
|
||||
@ -67,6 +69,7 @@ struct elf_file_ops {
|
||||
GElf_Addr (*symaddr)(elf_file_t ef, GElf_Size symidx);
|
||||
int (*lookup_set)(elf_file_t ef, const char *name, GElf_Addr *startp,
|
||||
GElf_Addr *stopp, long *countp);
|
||||
int (*lookup_symbol)(elf_file_t ef, const char *name, GElf_Sym **sym);
|
||||
};
|
||||
|
||||
typedef int (elf_reloc_t)(struct elf_file *ef, const void *reldata,
|
||||
@ -310,6 +313,16 @@ int elf_read_mod_pnp_match_info(struct elf_file *efile, GElf_Addr addr,
|
||||
int elf_reloc(struct elf_file *ef, const void *reldata, Elf_Type reltype,
|
||||
GElf_Addr relbase, GElf_Addr dataoff, size_t len, void *dest);
|
||||
|
||||
/*
|
||||
* Find the symbol with the specified symbol name 'name' within the given
|
||||
* 'efile'. 0 is returned when such a symbol is found, otherwise ENOENT is
|
||||
* returned.
|
||||
*
|
||||
* XXX: This only return the first symbol being found when traversing symtab.
|
||||
*/
|
||||
int elf_lookup_symbol(struct elf_file *efile, const char *name,
|
||||
GElf_Sym **sym);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _KLDELF_H_*/
|
||||
|
Loading…
Reference in New Issue
Block a user