Changeset 17341d4 in mainline for uspace/lib/c/generic/rtld
- Timestamp:
- 2016-04-20T17:25:48Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dc0d8b52
- Parents:
- 13dfa3f9
- Location:
- uspace/lib/c/generic/rtld
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/rtld/module.c
r13dfa3f9 r17341d4 91 91 * path components are ignored. 92 92 */ 93 module_t *module_find( const char *name)93 module_t *module_find(rtld_t *rtld, const char *name) 94 94 { 95 95 const char *p, *soname; … … 106 106 107 107 /* Traverse list of all modules. Not extremely fast, but simple */ 108 list_foreach(r untime_env->modules, modules_link, module_t, m) {108 list_foreach(rtld->modules, modules_link, module_t, m) { 109 109 DPRINTF("m = %p\n", m); 110 110 if (str_cmp(m->dyn.soname, soname) == 0) { … … 122 122 * Currently this trivially tries to load '/<name>'. 123 123 */ 124 module_t *module_load( const char *name)125 { 126 elf_ info_t info;124 module_t *module_load(rtld_t *rtld, const char *name) 125 { 126 elf_finfo_t info; 127 127 char name_buf[NAME_BUF_SIZE]; 128 128 module_t *m; … … 135 135 } 136 136 137 m->rtld = rtld; 138 137 139 if (str_size(name) > NAME_BUF_SIZE - 2) { 138 140 printf("soname too long. increase NAME_BUF_SIZE\n"); … … 145 147 146 148 /* FIXME: need to real allocation of address space */ 147 m->bias = r untime_env->next_bias;148 r untime_env->next_bias += 0x100000;149 m->bias = rtld->next_bias; 150 rtld->next_bias += 0x100000; 149 151 150 152 DPRINTF("filename:'%s'\n", name_buf); … … 171 173 172 174 /* Insert into the list of loaded modules */ 173 list_append(&m->modules_link, &r untime_env->modules);175 list_append(&m->modules_link, &rtld->modules); 174 176 175 177 return m; … … 221 223 222 224 DPRINTF("%s needs %s\n", m->dyn.soname, dep_name); 223 dm = module_find( dep_name);225 dm = module_find(m->rtld, dep_name); 224 226 if (!dm) { 225 dm = module_load( dep_name);227 dm = module_load(m->rtld, dep_name); 226 228 module_load_deps(dm); 227 229 } … … 241 243 * @param start The module where to start from. 242 244 */ 243 void modules_process_relocs( module_t *start)244 { 245 list_foreach(r untime_env->modules, modules_link, module_t, m) {246 /* Skip rtld , since it has already been processed */247 if (m != &r untime_env->rtld) {245 void modules_process_relocs(rtld_t *rtld, module_t *start) 246 { 247 list_foreach(rtld->modules, modules_link, module_t, m) { 248 /* Skip rtld module, since it has already been processed */ 249 if (m != &rtld->rtld) { 248 250 module_process_relocs(m); 249 251 } … … 253 255 /** Clear BFS tags of all modules. 254 256 */ 255 void modules_untag( void)256 { 257 list_foreach(r untime_env->modules, modules_link, module_t, m) {257 void modules_untag(rtld_t *rtld) 258 { 259 list_foreach(rtld->modules, modules_link, module_t, m) { 258 260 m->bfs_tag = false; 259 261 } -
uspace/lib/c/generic/rtld/rtld.c
r13dfa3f9 r17341d4 35 35 */ 36 36 37 #include <errno.h> 38 #include <rtld/module.h> 37 39 #include <rtld/rtld.h> 40 #include <rtld/rtld_debug.h> 41 #include <stdlib.h> 38 42 39 runtime_env_t *runtime_env; 40 static runtime_env_t rt_env_static; 43 rtld_t *runtime_env; 44 static rtld_t rt_env_static; 45 static module_t prog_mod; 41 46 42 /** Initialize the loder for use in a statically-linked binary. */47 /** Initialize the runtime linker for use in a statically-linked executable. */ 43 48 void rtld_init_static(void) 44 49 { … … 49 54 } 50 55 56 /** Initialize and process a dynamically linked executable. 57 * 58 * @param p_info Program info 59 * @return EOK on success or non-zero error code 60 */ 61 int rtld_prog_process(elf_finfo_t *p_info, rtld_t **rre) 62 { 63 rtld_t *env; 64 65 DPRINTF("Load dynamically linked program.\n"); 66 67 /* Allocate new RTLD environment to pass to the loaded program */ 68 env = calloc(1, sizeof(rtld_t)); 69 if (env == NULL) 70 return ENOMEM; 71 72 /* 73 * First we need to process dynamic sections of the executable 74 * program and insert it into the module graph. 75 */ 76 77 DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic); 78 dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn); 79 prog_mod.bias = 0; 80 prog_mod.dyn.soname = "[program]"; 81 prog_mod.rtld = env; 82 83 /* Initialize list of loaded modules */ 84 list_initialize(&env->modules); 85 list_append(&prog_mod.modules_link, &env->modules); 86 87 /* Pointer to program module. Used as root of the module graph. */ 88 env->program = &prog_mod; 89 90 /* Work around non-existent memory space allocation. */ 91 env->next_bias = 0x1000000; 92 93 /* 94 * Now we can continue with loading all other modules. 95 */ 96 97 DPRINTF("Load all program dependencies\n"); 98 module_load_deps(&prog_mod); 99 100 /* 101 * Now relocate/link all modules together. 102 */ 103 104 /* Process relocations in all modules */ 105 DPRINTF("Relocate all modules\n"); 106 modules_process_relocs(env, &prog_mod); 107 108 *rre = env; 109 return EOK; 110 } 111 51 112 /** @} 52 113 */ -
uspace/lib/c/generic/rtld/symbol.c
r13dfa3f9 r17341d4 39 39 40 40 #include <elf/elf.h> 41 #include <rtld/module.h> 41 42 #include <rtld/rtld.h> 42 43 #include <rtld/rtld_debug.h> … … 132 133 133 134 /* Mark all vertices (modules) as unvisited */ 134 modules_untag( );135 modules_untag(start->rtld); 135 136 136 137 /* Insert root (the program) into the queue and tag it */ … … 219 220 /* Not DT_SYMBOLIC or no match. Now try other locations. */ 220 221 221 if ( runtime_env->program) {222 if (origin->rtld->program) { 222 223 /* Program is dynamic -- start with program as root. */ 223 return symbol_bfs_find(name, runtime_env->program, flags, mod);224 return symbol_bfs_find(name, origin->rtld->program, flags, mod); 224 225 } else { 225 226 /* Program is static -- start with @a origin as root. */
Note:
See TracChangeset
for help on using the changeset viewer.