diff options
author | Stefan Bucur <stefan@stefan-mac.(none)> | 2009-07-04 19:47:29 +0300 |
---|---|---|
committer | Stefan Bucur <stefan@stefan-mac.(none)> | 2009-07-04 19:47:29 +0300 |
commit | 2ab2c16e359d266719ce8639ca0fa057d0f7a099 (patch) | |
tree | a3907756a1b2ed01e630ddbf114929d72ebd2631 /com32/lib/sys/module/shallow_module.c | |
parent | c9d910a68845661946d1e040faaa4f46076fd64f (diff) | |
download | syslinux-elf-2ab2c16e359d266719ce8639ca0fa057d0f7a099.tar.gz syslinux-elf-2ab2c16e359d266719ce8639ca0fa057d0f7a099.tar.xz syslinux-elf-2ab2c16e359d266719ce8639ca0fa057d0f7a099.zip |
Added support in shallow modules to offset symbols.
The symbol values can be offset so that they could match
a memory region, in case it is created dynamically and the
symbol table does not include the offsets.
Diffstat (limited to 'com32/lib/sys/module/shallow_module.c')
-rw-r--r-- | com32/lib/sys/module/shallow_module.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c index f198c0db..f43582c4 100644 --- a/com32/lib/sys/module/shallow_module.c +++ b/com32/lib/sys/module/shallow_module.c @@ -115,8 +115,29 @@ 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) { +int module_load_shallow(struct elf_module *module, Elf32_Off offset) { int res; Elf32_Ehdr elf_hdr; @@ -143,6 +164,8 @@ int module_load_shallow(struct elf_module *module) { // 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); |