Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2972 → Rev 2973

/branches/dynload/uspace/app/dltest/dltest.c
34,6 → 34,8
* @file
*/
 
#include <libtest.h>
 
void __io_init(void);
void __main(void);
void __exit(void);
61,6 → 63,8
int main(int argc, char *argv[])
{
test();
/* Unreachable, yet. Just to create a relocation entry */
test_func();
return 0;
}
 
/branches/dynload/uspace/app/dltest/Makefile
36,7 → 36,7
SOFTINT_PREFIX = ../../lib/softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I../../srv/kbd/include
CFLAGS += -I../../lib/libtest -O0
LFLAGS := -Bdynamic -I/rtld.so
 
# LIBS = $(LIBC_PREFIX)/libc.a
/branches/dynload/uspace/app/iloader/main.c
66,7 → 66,7
printf("Create PCB\n");
if (elf_create_pcb(&prog_info) < 0) return 1;
 
getchar();
// getchar();
 
printf("Load dynamic linker\n");
file_name = "/rtld.so";
/branches/dynload/uspace/lib/rtld/include/arch.h
0,0 → 1,45
/*
* 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 ARCH_H_
#define ARCH_H_
 
#include <rtld.h>
 
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size);
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/include/rtld.h
35,6 → 35,15
#ifndef RTLD_H_
#define RTLD_H_
 
#include <sys/types.h>
 
#include <dynamic.h>
 
typedef struct {
dyn_info_t dyn;
size_t bias;
} module_t;
 
void _rtld_main(void);
 
#endif
/branches/dynload/uspace/lib/rtld/rtld.c
42,24 → 42,13
#include <dynamic.h>
#include <pcb.h>
#include <elf_load.h>
#include <arch.h>
 
static void kputint(unsigned i)
{
unsigned dummy;
asm volatile (
"movl $30, %%eax;"
"int $0x30"
: "=d" (dummy) /* output - %edx clobbered */
: "d" (i) /* input */
: "%eax","%ecx" /* all scratch registers clobbered */
);
}
 
void _rtld_main(void)
{
pcb_t *pcb;
static dyn_info_t dyn_info;
elf_info_t lib_info;
static module_t prog;
int rc;
 
printf("Hello, world! (from rtld)\n");
67,9 → 56,9
 
printf("Parse .dynamic section\n");
pcb = (pcb_t *)PCB_ADDRESS;
dynamic_parse(pcb->dynamic, 0, &dyn_info);
dynamic_parse(pcb->dynamic, 0, &prog.dyn);
 
printf("Program requested library '%s'\n", dyn_info.needed);
printf("Program requested library '%s'\n", prog.dyn.needed);
rc = elf_load_file("/libtest.so.0", 0x20000, &lib_info);
if (rc < 0) {
77,6 → 66,10
return;
}
 
/* 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);
 
printf("Run program..\n");
pcb->entry();
}
/branches/dynload/uspace/lib/rtld/arch/ia32/Makefile.inc
31,5 → 31,6
ARCH_SOURCES := \
arch/$(ARCH)/src/entry.s \
arch/$(ARCH)/src/bootstrap.c \
arch/$(ARCH)/src/runtime.c
arch/$(ARCH)/src/runtime.c \
arch/$(ARCH)/src/reloc.c
 
/branches/dynload/uspace/lib/rtld/arch/ia32/src/reloc.c
0,0 → 1,117
/*
* 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 <arch.h>
#include <elf_dyn.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)
{
unsigned bias;
int i;
 
size_t rt_entries;
size_t r_offset;
elf_word r_info;
unsigned rel_type;
elf_word sym_idx;
// uintptr_t sym_addr;
elf_symbol_t *sym_table;
elf_symbol_t *sym;
uint32_t *r_ptr;
char *str_tab;
 
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;
 
printf("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
for (i = 0; i < rt_entries; ++i) {
printf("symbol %d: ", i);
r_offset = rt[i].r_offset;
r_info = rt[i].r_info;
 
sym_idx = ELF32_R_SYM(r_info);
sym = &sym_table[sym_idx];
 
printf("name '%s', value 0x%x, size 0x%x\n",
str_tab + sym->st_name,
sym->st_value,
sym->st_size);
 
rel_type = ELF32_R_TYPE(r_info);
r_ptr = (uint32_t *)(r_offset + bias);
 
printf("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
/*
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);
 
*r_ptr = sym_addr;
break;
 
case R_386_32:
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
*r_ptr += sym_addr;
break;
case R_386_RELATIVE:
*r_ptr += bias;
break;
}*/
}
 
}
 
/** @}
*/