Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2997 → Rev 2998

/branches/dynload/uspace/lib/rtld/include/elf_dyn.h
111,6 → 111,11
#define SHN_COMMON 0xfff2
#define SHN_HIRESERVE 0xffff
 
/*
* Special symbol table index
*/
#define STN_UNDEF 0
 
#endif
 
/** @}
/branches/dynload/uspace/lib/rtld/include/symbol.h
39,6 → 39,7
#include <elf.h>
 
elf_symbol_t *symbol_def_find(char *name, module_t **m);
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m);
 
#endif
 
/branches/dynload/uspace/lib/rtld/symbol.c
42,38 → 42,65
#include <symbol.h>
#include <elf.h>
 
/*
* Hash tables are 32-bit (elf_word) even for 64-bit ELF files.
*/
static elf_word elf_hash(const unsigned char *name)
{
elf_word h = 0, g;
 
while (*name) {
h = (h << 4) + *name++;
g = h & 0xf0000000;
if (g != 0) h ^= g >> 24;
h &= ~g;
}
 
return h;
}
 
static elf_symbol_t *def_find_in_module(char *name, module_t *m)
{
elf_symbol_t *sym_table;
elf_symbol_t *sym;
elf_symbol_t *s, *sym;
elf_word nbucket;
elf_word nchain;
size_t i;
elf_word i;
char *s_name;
char *module_name;
elf_word bucket;
 
module_name = m->dyn.soname;
// module_name = m->dyn.soname;
// printf("def_find_in_module('%s', %s)\n", name, module_name);
 
sym_table = m->dyn.sym_tab;
nbucket = m->dyn.hash[0];
nchain = m->dyn.hash[1];
 
for (i = 0; i < nchain; ++i) {
sym = &sym_table[i];
s_name = m->dyn.str_tab + sym->st_name;
// printf("cmp sym '%s'\n", s_name);
bucket = elf_hash((unsigned char *)name) % nbucket;
i = m->dyn.hash[2 + bucket];
 
sym = NULL;
while (i != STN_UNDEF) {
s = &sym_table[i];
s_name = m->dyn.str_tab + s->st_name;
 
if (strcmp(name, s_name) == 0) {
// printf("name match\n");
if (sym->st_shndx != SHN_UNDEF) {
// printf("definition found. idx=%d\n", i);
return sym;
} else {
// printf("not a definition\n");
}
sym = s;
break;
}
 
i = m->dyn.hash[2 + nbucket + i];
}
 
// printf("not found\n");
return NULL;
if (!sym)
return NULL; /* Not found */
 
if (sym->st_shndx == SHN_UNDEF) {
/* Not a definition */
return NULL;
}
 
return sym; /* Found */
}
 
 
95,5 → 122,15
return NULL;
}
 
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m)
{
if (sym->st_shndx == SHN_ABS) {
/* Do not add bias to absolute symbols */
return sym->st_value;
} else {
return sym->st_value + m->bias;
}
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ppc32/src/reloc.c
83,7 → 83,6
{
uint32_t *plt;
uint32_t *_plt_ent;
int i;
 
plt = m->dyn.plt_got;
if (!plt) {
191,12 → 190,7
printf("dest name: '%s'\n", dest->dyn.soname);
printf("dest bias: 0x%x\n", dest->bias);
if (sym_def) {
if (sym_def->st_shndx == SHN_ABS) {
/* Do not add bias to absolute symbols */
sym_addr = sym_def->st_value;
} else {
sym_addr = sym_def->st_value + dest->bias;
}
sym_addr = symbol_get_addr(sym_def, dest);
printf("symbol definition found, addr=0x%x\n", sym_addr);
} else {
printf("symbol definition not found\n");
214,7 → 208,7
while(1);
}
//_plt_table[pidx] = sym_addr;
plt[18+2*pidx] = _b(sym_addr, &plt[18+2*pidx]);
plt[18+2*pidx] = _b((void *)sym_addr, &plt[18+2*pidx]);
break;
 
case R_PPC_ADDR32:
/branches/dynload/uspace/lib/rtld/arch/ppc32/src/bootstrap.c
229,12 → 229,12
// r_ptr should point to a plt entry...
uint32_t pidx = (r_ptr - _plt_ent) / 2;
if (pidx >= plt_n) {
kputint(0xee00ee0ee00);
kputint(0xee00ee00);
while(1);
}
// _plt_table[pidx] = sym_addr;
// kputint(pidx);
plt[18+2*pidx] = _b(sym_addr, &plt[18+2*pidx]);
plt[18+2*pidx] = _b((void *)sym_addr, &plt[18+2*pidx]);
// kputint(&plt[18]);
// kputint(plt[18]);
// while(1);
/branches/dynload/uspace/lib/rtld/arch/ia32/src/reloc.c
99,12 → 99,7
// printf("dest name: '%s'\n", dest->dyn.soname);
// printf("dest bias: 0x%x\n", dest->bias);
if (sym_def) {
if (sym_def->st_shndx == SHN_ABS) {
/* Do not add bias to absolute symbols */
sym_addr = sym_def->st_value;
} else {
sym_addr = sym_def->st_value + dest->bias;
}
sym_addr = symbol_get_addr(sym_def, dest);
// printf("symbol definition found, addr=0x%x\n", sym_addr);
} else {
printf("symbol definition not found\n");