Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3561 → Rev 3562

/branches/dynload/uspace/lib/rtld/include/rtld.h
41,6 → 41,15
#include <dynamic.h>
#include <module.h>
 
/* Define to enable debugging mode. */
#undef RTLD_DEBUG
 
#ifdef RTLD_DEBUG
#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__);
#else
#define DPRINTF(format, ...)
#endif
 
typedef struct {
elf_dyn_t *rtld_dynamic;
module_t rtld;
/branches/dynload/uspace/lib/rtld/dynamic.c
39,6 → 39,7
 
#include <elf_dyn.h>
#include <dynamic.h>
#include <rtld.h>
 
void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
{
50,13 → 51,13
elf_word soname_idx;
elf_word rpath_idx;
 
printf("memset\n");
DPRINTF("memset\n");
memset(info, 0, sizeof(info));
 
soname_idx = 0;
rpath_idx = 0;
 
printf("pass 1\n");
DPRINTF("pass 1\n");
while (dp->d_tag != DT_NULL) {
d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
d_val = dp->d_un.d_val;
98,11 → 99,11
/* This will be useful for parsing dependencies later */
info->dynamic = dyn_ptr;
 
printf("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n",
DPRINTF("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n",
(uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname);
printf("soname='%s'\n", info->soname);
printf("rpath='%s'\n", info->rpath);
printf("hash=0x%x\n", (uintptr_t)info->hash);
DPRINTF("soname='%s'\n", info->soname);
DPRINTF("rpath='%s'\n", info->rpath);
DPRINTF("hash=0x%x\n", (uintptr_t)info->hash);
 
/*
* Now that we have a pointer to the string table,
109,7 → 110,7
* we can parse DT_NEEDED fields (which contain offsets into it).
*/
 
printf("pass 2\n");
DPRINTF("pass 2\n");
dp = dyn_ptr;
while (dp->d_tag != DT_NULL) {
d_val = dp->d_un.d_val;
118,7 → 119,7
case DT_NEEDED:
/* Assume just for now there's only one dependency */
info->needed = info->str_tab + d_val;
printf("needed:'%s'\n", info->needed);
DPRINTF("needed:'%s'\n", info->needed);
break;
 
default: break;
/branches/dynload/uspace/lib/rtld/module.c
53,7 → 53,7
*/
void module_process_relocs(module_t *m)
{
printf("module_process_relocs('%s')\n", m->dyn.soname);
DPRINTF("module_process_relocs('%s')\n", m->dyn.soname);
if (m->dyn.plt_rel == DT_REL) {
if (m->dyn.rel != NULL)
rel_table_process(m, m->dyn.rel, m->dyn.rel_sz);
61,9 → 61,9
if (m->dyn.jmp_rel != NULL)
rel_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
} else { /* (m->dyn.plt_rel == DT_RELA) */
printf("table type DT_RELA\n");
DPRINTF("table type DT_RELA\n");
if (m->dyn.rela != NULL) {
printf("non-empty\n");
DPRINTF("non-empty\n");
rela_table_process(m, m->dyn.rela, m->dyn.rela_sz);
}
}
133,7 → 133,7
 
/* FIXME: need to vary bias / allocate address space */
m->bias = 0x20000;
printf("filename:'%s'\n", name_buf);
DPRINTF("filename:'%s'\n", name_buf);
 
rc = elf_load_file(name_buf, m->bias, ELDF_RW, &info);
if (rc < 0) {
141,7 → 141,7
exit(1);
}
 
printf("parse dynamic section\n");
DPRINTF("parse dynamic section\n");
/* Parse ELF .dynamic section. Store info to m->dyn. */
dynamic_parse(info.dynamic, m->bias, &m->dyn);
 
193,7 → 193,7
if (dp->d_tag == DT_NEEDED) {
dep_name = m->dyn.str_tab + dp->d_un.d_val;
 
printf("%s needs %s\n", m->dyn.soname, dep_name);
DPRINTF("%s needs %s\n", m->dyn.soname, dep_name);
dm = module_find(dep_name);
if (!dm) {
dm = module_load(dep_name);
/branches/dynload/uspace/lib/rtld/rtld.c
54,7 → 54,7
static module_t prog;
// module_t *rtld;
 
printf("Hello, world! (from rtld)\n");
DPRINTF("Hello, world! (from rtld)\n");
 
/*
* First we need to process dynamic sections of the two modules
64,10 → 64,10
 
/* rtld_dynamic and rtld->bias were filled out by the bootstrap code */
// rtld = &runtime_env.rtld;
// printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
// DPRINTF("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
// dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
 
printf("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
DPRINTF("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
dynamic_parse(__pcb->dynamic, 0, &prog.dyn);
prog.bias = 0;
prog.dyn.soname = "[program]";
84,7 → 84,7
* Now we can continue with loading all other modules.
*/
 
printf("Load all program dependencies\n");
DPRINTF("Load all program dependencies\n");
module_load_deps(&prog);
 
/*
92,13 → 92,17
*/
 
/* Process relocations in all modules */
printf("Relocate all modules\n");
DPRINTF("Relocate all modules\n");
modules_process_relocs();
 
/*
* Finally, run the main program.
*/
printf("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry);
DPRINTF("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry);
 
#ifndef RTLD_DEBUG
close_console();
#endif
//__pcb->entry();
program_run(__pcb->entry, __pcb);
}
/branches/dynload/uspace/lib/rtld/symbol.c
70,7 → 70,7
elf_word bucket;
 
// module_name = m->dyn.soname;
// printf("def_find_in_module('%s', %s)\n", name, module_name);
// DPRINTF("def_find_in_module('%s', %s)\n", name, module_name);
 
sym_table = m->dyn.sym_tab;
nbucket = m->dyn.hash[0];
/branches/dynload/uspace/lib/rtld/arch/ia32/src/reloc.c
69,16 → 69,16
elf_symbol_t *sym_def;
module_t *dest;
 
printf("parse relocation table\n");
DPRINTF("parse relocation table\n");
 
sym_table = m->dyn.sym_tab;
rt_entries = rt_size / sizeof(elf_rel_t);
str_tab = m->dyn.str_tab;
 
printf("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
for (i = 0; i < rt_entries; ++i) {
// printf("symbol %d: ", i);
// DPRINTF("symbol %d: ", i);
r_offset = rt[i].r_offset;
r_info = rt[i].r_info;
 
85,7 → 85,7
sym_idx = ELF32_R_SYM(r_info);
sym = &sym_table[sym_idx];
 
/* printf("name '%s', value 0x%x, size 0x%x\n",
/* DPRINTF("name '%s', value 0x%x, size 0x%x\n",
str_tab + sym->st_name,
sym->st_value,
sym->st_size);
94,16 → 94,16
r_ptr = (uint32_t *)(r_offset + m->bias);
 
if (sym->st_name != 0) {
// printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
// DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
sym_def = symbol_def_find(str_tab + sym->st_name,
m, &dest);
// printf("dest name: '%s'\n", dest->dyn.soname);
// printf("dest bias: 0x%x\n", dest->bias);
// DPRINTF("dest name: '%s'\n", dest->dyn.soname);
// DPRINTF("dest bias: 0x%x\n", dest->bias);
if (sym_def) {
sym_addr = symbol_get_addr(sym_def, dest);
// printf("symbol definition found, addr=0x%x\n", sym_addr);
// DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
} else {
printf("symbol definition not found\n");
DPRINTF("symbol definition not found\n");
continue;
}
}
111,17 → 111,17
switch (rel_type) {
case R_386_GLOB_DAT:
case R_386_JUMP_SLOT:
// printf("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n");
// DPRINTF("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n");
*r_ptr = sym_addr;
break;
 
case R_386_32:
// printf("fixup R_386_32 (b+v+a)\n");
// DPRINTF("fixup R_386_32 (b+v+a)\n");
*r_ptr += sym_addr;
break;
case R_386_RELATIVE:
// printf("fixup R_386_RELATIVE (b+a)\n");
// DPRINTF("fixup R_386_RELATIVE (b+a)\n");
*r_ptr += m->bias;
break;
}