Changeset View
Changeset View
Standalone View
Standalone View
head/sys/boot/common/load_elf_obj.c
Show First 20 Lines • Show All 514 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* Look up the address of a specified symbol. */ | /* Look up the address of a specified symbol. */ | ||||
static Elf_Addr | static Elf_Addr | ||||
__elfN(obj_symaddr)(struct elf_file *ef, Elf_Size symidx) | __elfN(obj_symaddr)(struct elf_file *ef, Elf_Size symidx) | ||||
{ | { | ||||
Elf_Sym sym; | Elf_Sym sym; | ||||
Elf_Addr base; | Elf_Addr base; | ||||
int symcnt; | |||||
symcnt = ef->e_shdr[ef->symtabindex].sh_size / sizeof(Elf_Sym); | if (symidx >= ef->e_shdr[ef->symtabindex].sh_size / sizeof(Elf_Sym)) | ||||
if (symidx >= symcnt) | |||||
return (0); | return (0); | ||||
COPYOUT(ef->e_shdr[ef->symtabindex].sh_addr + symidx * sizeof(Elf_Sym), | COPYOUT(ef->e_shdr[ef->symtabindex].sh_addr + symidx * sizeof(Elf_Sym), | ||||
&sym, sizeof(sym)); | &sym, sizeof(sym)); | ||||
if (sym.st_shndx == SHN_UNDEF || sym.st_shndx >= ef->hdr.e_shnum) | if (sym.st_shndx == SHN_UNDEF || sym.st_shndx >= ef->hdr.e_shnum) | ||||
return (0); | return (0); | ||||
base = ef->e_shdr[sym.st_shndx].sh_addr; | base = ef->e_shdr[sym.st_shndx].sh_addr; | ||||
if (base == 0) | if (base == 0) | ||||
return (0); | return (0); | ||||
return (base + sym.st_value); | return (base + sym.st_value); | ||||
} | } |