/branches/dynload/uspace/app/dltest/dltest.c |
---|
38,8 → 38,24 |
void __main(void); |
void __exit(void); |
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 */ |
); |
} |
static void test(void) |
{ |
kputint(-1); |
kputint(42); |
while(1); |
} |
int main(int argc, char *argv[]) |
/branches/dynload/uspace/app/iloader/main.c |
---|
55,7 → 55,7 |
printf("Load program\n"); |
rc = elf_load_file("/tetris", &prog_info); |
rc = elf_load_file("/dltest", &prog_info); |
if (rc < 0) { |
printf("failed to load program\n"); |
return 1; |
64,6 → 64,8 |
printf("Create PCB\n"); |
if (elf_create_pcb(&prog_info) < 0) return 1; |
getchar(); |
printf("Load dynamic linker\n"); |
file_name = "/rtld.so"; |
printf("open and read '%s'...\n", file_name); |
/branches/dynload/uspace/app/iramfs/data.h |
---|
41,9 → 41,9 |
extern const size_t rtld_size; |
extern const char rtld_filename[]; |
extern const uint8_t tetris[]; |
extern const size_t tetris_size; |
extern const char tetris_filename[]; |
extern const uint8_t dltest[]; |
extern const size_t dltest_size; |
extern const char dltest_filename[]; |
#endif |
/branches/dynload/uspace/app/iramfs/main.c |
---|
87,7 → 87,7 |
} while (1); |
if (write_file(rtld, rtld_size, rtld_filename) < 0) return 1; |
if (write_file(tetris, tetris_size, tetris_filename) < 0) return 1; |
if (write_file(dltest, dltest_size, dltest_filename) < 0) return 1; |
printf("done\n"); |
getchar(); |
/branches/dynload/uspace/app/iramfs/Makefile |
---|
87,6 → 87,6 |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
data.c: ../../lib/rtld/rtld.so ../tetris/tetris |
data.c: ../../lib/rtld/rtld.so ../dltest/dltest |
../../../tools/bin2c.py ../../lib/rtld/rtld.so rtld.so rtld >$@ |
../../../tools/bin2c.py ../tetris/tetris tetris tetris >>$@ |
../../../tools/bin2c.py ../dltest/dltest dltest dltest >>$@ |
/branches/dynload/uspace/lib/rtld/include/dynamic.h |
---|
0,0 → 1,96 |
/* |
* 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 DYNAMIC_H_ |
#define DYNAMIC_H_ |
#include <bool.h> |
#include <elf_dyn.h> |
/** |
* Holds the data extracted from an ELF Dynamic section. |
* |
* The data is already pre-processed: Pointers are adjusted |
* to their final run-time values by adding the load bias |
* and indices into the symbol table are converted to pointers. |
*/ |
typedef struct { |
/** Type of relocations used for the PLT, either DT_REL or DT_RELA */ |
int plt_rel; |
/** Relocation table without explicit addends */ |
void *rel; |
size_t rel_sz; |
size_t rel_ent; |
/** Relocation table with explicit addends */ |
void *rela; |
size_t rela_sz; |
size_t rela_ent; |
/** PLT relocation table */ |
void *jmp_rel; |
size_t plt_rel_sz; |
/** Pointer to PLT/GOT (processor-specific) */ |
void *plt_got; |
/** Hash table */ |
void *hash; |
/** String table */ |
char *str_tab; |
size_t str_sz; |
/** Symbol table */ |
void *sym_tab; |
size_t sym_ent; |
void *init; /**< Module initialization code */ |
void *fini; /**< Module cleanup code */ |
char *soname; /**< Library identifier */ |
char *rpath; /**< Library search path list */ |
bool symbolic; |
bool text_rel; |
bool bind_now; |
} dyn_info_t; |
void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info); |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/rtld/dynamic.c |
---|
0,0 → 1,118 |
/* |
* 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 <string.h> |
#include <elf_dyn.h> |
#include <dynamic.h> |
void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info) |
{ |
elf_dyn_t *dp = dyn_ptr; |
void *d_ptr; |
elf_word d_val; |
elf_word soname_idx; |
elf_word rpath_idx; |
printf("memset\n"); |
memset(info, 0, sizeof(info)); |
printf("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; |
switch (dp->d_tag) { |
case DT_PLTRELSZ: info->plt_rel_sz = d_val; break; |
case DT_PLTGOT: info->plt_got = d_ptr; break; |
case DT_HASH: info->hash = d_ptr; break; |
case DT_STRTAB: info->str_tab = d_ptr; break; |
case DT_SYMTAB: info->sym_tab = d_ptr; break; |
case DT_RELA: info->rela = d_ptr; break; |
case DT_RELASZ: info->rela_sz = d_val; break; |
case DT_RELAENT: info->rela_ent = d_val; break; |
case DT_STRSZ: info->str_sz = d_val; break; |
case DT_SYMENT: info->sym_ent = d_val; break; |
case DT_INIT: info->init = d_ptr; break; |
case DT_FINI: info->fini = d_ptr; break; |
case DT_SONAME: soname_idx = d_val; break; |
case DT_RPATH: rpath_idx = d_val; break; |
case DT_SYMBOLIC: info->symbolic = true; break; |
case DT_REL: info->rel = d_ptr; break; |
case DT_RELSZ: info->rel_sz = d_val; break; |
case DT_RELENT: info->rel_ent = d_val; break; |
case DT_PLTREL: info->plt_rel = d_val; break; |
case DT_TEXTREL: info->text_rel = true; break; |
case DT_JMPREL: info->jmp_rel = d_ptr; break; |
case DT_BIND_NOW: info->bind_now = true; break; |
default: break; |
} |
++dp; |
} |
info->soname = info->str_tab + soname_idx; |
info->rpath = info->str_tab + rpath_idx; |
/* |
* Now that we have a pointer to the string table, |
* we can parse DT_NEEDED fields (which contain offsets into it). |
*/ |
printf("pass 2\n"); |
dp = dyn_ptr; |
while (dp->d_tag != DT_NULL) { |
d_val = dp->d_un.d_val; |
switch (dp->d_tag) { |
case DT_NEEDED: |
printf("needed:'%s'\n", info->str_tab + d_val); |
break; |
default: break; |
} |
++dp; |
} |
} |
/** @} |
*/ |
/branches/dynload/uspace/lib/rtld/rtld.c |
---|
39,6 → 39,7 |
#include <fcntl.h> |
#include <rtld.h> |
#include <dynamic.h> |
#include "../../app/iloader/pcb.h" |
static void kputint(unsigned i) |
85,6 → 86,7 |
// test_func(); |
pcb_t *pcb; |
static dyn_info_t dyn_info; |
printf("Hello, world! (from rtld)\n"); |
getchar(); |
91,6 → 93,7 |
printf("Run program..\n"); |
pcb = (pcb_t *)PCB_ADDRESS; |
dynamic_parse(pcb->dynamic, 0, &dyn_info); |
pcb->entry(); |
} |
/branches/dynload/uspace/lib/rtld/Makefile |
---|
56,7 → 56,8 |
OUTPUT = rtld.so |
GENERIC_SOURCES = \ |
rtld.c |
rtld.c \ |
dynamic.c |
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) |
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES))) |