Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2977 → Rev 2978

/branches/dynload/uspace/app/dltest/dltest.c
53,16 → 53,16
}
 
 
static void test(void)
/*static void test(void)
{
kputint(-1);
kputint(42);
while(1);
}
}*/
 
int main(int argc, char *argv[])
{
test();
// test();
/* Unreachable, yet. Just to create a relocation entry */
test_func();
return 0;
/branches/dynload/uspace/lib/rtld/include/arch.h
37,7 → 37,8
 
#include <rtld.h>
 
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size);
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size,
module_t *dest);
 
#endif
 
/branches/dynload/uspace/lib/rtld/include/elf_dyn.h
38,8 → 38,8
#include <arch/elf.h>
#include <sys/types.h>
 
#include "elf.h"
#include "arch/elf_dyn.h"
#include <elf.h>
#include <arch/elf_dyn.h>
 
#define ELF32_R_SYM(i) ((i)>>8)
#define ELF32_R_TYPE(i) ((unsigned char)(i))
/branches/dynload/uspace/lib/rtld/include/dynamic.h
67,7 → 67,7
void *plt_got;
 
/** Hash table */
void *hash;
elf_word *hash;
 
/** String table */
char *str_tab;
/branches/dynload/uspace/lib/rtld/include/symbol.h
0,0 → 1,46
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef SYMBOL_H_
#define SYMBOL_H_
 
#include <rtld.h>
#include <elf.h>
 
elf_symbol_t *symbol_def_find(module_t *m, char *name);
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/rtld.c
49,6 → 49,7
pcb_t *pcb;
elf_info_t lib_info;
static module_t prog;
static module_t lib;
int rc;
 
printf("Hello, world! (from rtld)\n");
57,6 → 58,7
printf("Parse .dynamic section\n");
pcb = (pcb_t *)PCB_ADDRESS;
dynamic_parse(pcb->dynamic, 0, &prog.dyn);
prog.bias = 0;
 
printf("Program requested library '%s'\n", prog.dyn.needed);
66,9 → 68,12
return;
}
 
dynamic_parse(lib_info.dynamic, 0x20000, &lib.dyn);
lib.bias = 0x20000;
 
/* Parse program's relocation tables */
rel_table_process(&prog, prog.dyn.rel, prog.dyn.rel_sz);
rel_table_process(&prog, prog.dyn.jmp_rel, prog.dyn.plt_rel_sz);
rel_table_process(&prog, prog.dyn.rel, prog.dyn.rel_sz, &lib);
rel_table_process(&prog, prog.dyn.jmp_rel, prog.dyn.plt_rel_sz, &lib);
 
printf("Run program..\n");
pcb->entry();
/branches/dynload/uspace/lib/rtld/symbol.c
0,0 → 1,73
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @file
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <rtld.h>
#include <symbol.h>
#include <elf.h>
 
elf_symbol_t *symbol_def_find(module_t *m, char *name)
{
elf_symbol_t *sym_table;
elf_symbol_t *sym;
elf_word nchain;
size_t i;
char *s_name;
 
printf("symbol_def_find(m, '%s')\n", name);
 
sym_table = m->dyn.sym_tab;
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);
if (strcmp(name, s_name) == 0) {
printf("found. idx=%d\n", i);
return sym;
}
}
 
printf("not found\n");
return NULL;
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/Makefile
57,8 → 57,9
OUTPUT = rtld.so
GENERIC_SOURCES = \
rtld.c \
elf_load.c \
dynamic.c \
elf_load.c
symbol.c
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
/branches/dynload/uspace/lib/rtld/arch/ia32/src/reloc.c
38,14 → 38,15
 
#include <arch.h>
#include <elf_dyn.h>
#include <symbol.h>
#include <rtld.h>
 
/**
* Process (fixup) all relocations in a relocation table.
*/
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size,
module_t *dest)
{
unsigned bias;
int i;
 
size_t rt_entries;
53,17 → 54,18
elf_word r_info;
unsigned rel_type;
elf_word sym_idx;
// uintptr_t sym_addr;
uintptr_t sym_addr;
elf_symbol_t *sym_table;
elf_symbol_t *sym;
uint32_t *r_ptr;
char *str_tab;
elf_symbol_t *sym_def;
 
printf("parse relocation table\n");
 
sym_table = m->dyn.sym_tab;
bias = m->bias;
rt_entries = rt_size / sizeof(elf_rel_t);
str_tab = m->dyn.str_tab;
 
83,32 → 85,35
sym->st_size);
 
rel_type = ELF32_R_TYPE(r_info);
r_ptr = (uint32_t *)(r_offset + bias);
r_ptr = (uint32_t *)(r_offset + m->bias);
 
printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
/*
sym_def = symbol_def_find(dest, str_tab + sym->st_name);
if (sym_def) {
sym_addr = sym_def->st_value + dest->bias;
printf("symbol definition found, addr=0x%x\n", sym_addr);
} else {
printf("symbol definition not found\n");
continue;
}
 
switch (rel_type) {
case R_386_GLOB_DAT:
case R_386_JUMP_SLOT:
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
printf("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n");
*r_ptr = sym_addr;
break;
 
case R_386_32:
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
printf("fixup R_386_32 (b+v+a)\n");
*r_ptr += sym_addr;
break;
case R_386_RELATIVE:
*r_ptr += bias;
printf("fixup R_386_RELATIVE (b+a)\n");
*r_ptr += dest->bias;
break;
}*/
}
}
 
}