From 4e7dc15d06a158d8d0b0fd32b4536626b3090de0 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Sun, 5 Jul 2009 23:46:23 +0300 Subject: elf: Replaced symbol offsets with module base address. --- com32/elflink/test_com32.c | 4 +--- com32/include/sys/exec.h | 2 +- com32/include/sys/module.h | 2 +- com32/lib/sys/module/exec.c | 7 +++++-- com32/lib/sys/module/shallow_module.c | 26 ++------------------------ 5 files changed, 10 insertions(+), 31 deletions(-) diff --git a/com32/elflink/test_com32.c b/com32/elflink/test_com32.c index 20c19cf7..115bba87 100644 --- a/com32/elflink/test_com32.c +++ b/com32/elflink/test_com32.c @@ -8,8 +8,6 @@ #define INFO_PRINT(fmt, args...) printf("[COM32] " fmt, ##args) -#define COM32_OFFSET 0x110000 - #define MAX_COMMAND_SIZE 80 // Maximum size of the cmd line #define COMMAND_DELIM " \t\n" // Whitespace delimiters #define MAX_COMMAND_ARGS (MAX_COMMAND_SIZE/2) // Maximum argument count for @@ -181,7 +179,7 @@ int main(int argc, char **argv) { // Open a standard r/w console openconsole(&dev_stdcon_r, &dev_stdcon_w); - res = exec_init(COM32_OFFSET); + res = exec_init(); if (res != 0) { printf("Failed to initialize the execution environment.\n"); return res; diff --git a/com32/include/sys/exec.h b/com32/include/sys/exec.h index d76ae74c..24379d96 100644 --- a/com32/include/sys/exec.h +++ b/com32/include/sys/exec.h @@ -42,7 +42,7 @@ * loaded by the lower module layer gets to be executed by the CPU, * thus becoming part of the SYSLINUX environment. */ -extern int exec_init(size_t root_addr); +extern int exec_init(); /** diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h index 97f7ce09..4de57105 100644 --- a/com32/include/sys/module.h +++ b/com32/include/sys/module.h @@ -229,7 +229,7 @@ extern int module_load(struct elf_module *module); * Its current use is to describe the root COM32 module to the rest of the * module subsystem. */ -extern int module_load_shallow(struct elf_module *module, Elf32_Off offset); +extern int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr); /** * module_unload - unloads the module from the system. diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 9da1d572..cbd81d42 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -11,6 +11,9 @@ #include #include +// The symbol declared in the linker script that indicates the loading point +// of the COM32R module +extern char _start[]; #define DBG_PRINT(fmt, args...) fprintf(stderr, "[EXEC] " fmt, ##args) @@ -30,7 +33,7 @@ static char *module_get_fullname(const char *name) { return name_buff; } -int exec_init(size_t root_addr) { +int exec_init() { int res; res = modules_init(); @@ -44,7 +47,7 @@ int exec_init(size_t root_addr) { if (mod_root == NULL) return -1; - res = module_load_shallow(mod_root, root_addr); + res = module_load_shallow(mod_root, (Elf32_Addr)_start); if (res != 0) { mod_root = NULL; diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c index f43582c4..fdcb20f8 100644 --- a/com32/lib/sys/module/shallow_module.c +++ b/com32/lib/sys/module/shallow_module.c @@ -115,29 +115,8 @@ out: return res; } -static int offset_symbols(struct elf_module *module, Elf32_Off offset) { - unsigned int i; - Elf32_Sym *crt_sym = NULL; - - for (i = 1; i < module->symtable_size; i++) { - crt_sym = (Elf32_Sym*)(module->sym_table + i*module->syment_size); - - // Skip the undefined or absolute symbols - if (crt_sym->st_shndx == SHN_UNDEF || crt_sym->st_shndx == SHN_ABS) - continue; - // Also skip the non-local symbols - if (ELF32_ST_BIND(crt_sym->st_info) != STB_GLOBAL && - ELF32_ST_BIND(crt_sym->st_info) != STB_WEAK) - continue; - - crt_sym->st_value += offset; - } - - return 0; -} - -int module_load_shallow(struct elf_module *module, Elf32_Off offset) { +int module_load_shallow(struct elf_module *module, Elf32_Addr base_addr) { int res; Elf32_Ehdr elf_hdr; @@ -160,12 +139,11 @@ int module_load_shallow(struct elf_module *module, Elf32_Off offset) { CHECKED(res, check_header_shallow(&elf_hdr), error); CHECKED(res, load_shallow_sections(module, &elf_hdr), error); + module->base_addr = base_addr; // Check the symbols for duplicates / missing definitions CHECKED(res, check_symbols(module), error); - CHECKED(res, offset_symbols(module, offset), error); - // Add the module at the beginning of the module list list_add(&module->list, &modules_head); -- cgit v1.2.3