Changeset 5035ba05 in mainline
- Timestamp:
- 2016-05-02T19:49:51Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32573ff, 9a08e6b
- Parents:
- 634e020
- Location:
- uspace/lib/c
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/ia32/src/rtld/reloc.c
r634e020 r5035ba05 144 144 145 145 sym_def = symbol_def_find(str_tab + sym->st_name, 146 m, ssf_no root, &dest);146 m, ssf_noexec, &dest); 147 147 148 148 if (sym_def) { -
uspace/lib/c/generic/dlfcn.c
r634e020 r5035ba05 60 60 if (m == NULL) { 61 61 printf("NULL. module_load('%s')\n", path); 62 m = module_load(runtime_env, path );62 m = module_load(runtime_env, path, mlf_local); 63 63 printf("module_load_deps(m)\n"); 64 module_load_deps(m );64 module_load_deps(m, mlf_local); 65 65 /* Now relocate. */ 66 66 printf("module_process_relocs(m)\n"); … … 82 82 83 83 printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name); 84 sd = symbol_bfs_find(sym_name, (module_t *) mod, ssf_none,&sm);84 sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm); 85 85 if (sd != NULL) { 86 86 return symbol_get_addr(sd, sm); -
uspace/lib/c/generic/rtld/module.c
r634e020 r5035ba05 117 117 } 118 118 } 119 119 120 120 return NULL; /* Not found */ 121 121 } … … 127 127 * Currently this trivially tries to load '/<name>'. 128 128 */ 129 module_t *module_load(rtld_t *rtld, const char *name )129 module_t *module_load(rtld_t *rtld, const char *name, mlflags_t flags) 130 130 { 131 131 elf_finfo_t info; … … 133 133 module_t *m; 134 134 int rc; 135 136 m = malloc(sizeof(module_t));135 136 m = calloc(1, sizeof(module_t)); 137 137 if (!m) { 138 138 printf("malloc failed\n"); … … 141 141 142 142 m->rtld = rtld; 143 if ((flags & mlf_local) != 0) 144 m->local = true; 143 145 144 146 if (str_size(name) > NAME_BUF_SIZE - 2) { … … 185 187 /** Load all modules on which m (transitively) depends. 186 188 */ 187 void module_load_deps(module_t *m )189 void module_load_deps(module_t *m, mlflags_t flags) 188 190 { 189 191 elf_dyn_t *dp; … … 230 232 dm = module_find(m->rtld, dep_name); 231 233 if (!dm) { 232 dm = module_load(m->rtld, dep_name );233 module_load_deps(dm );234 dm = module_load(m->rtld, dep_name, flags); 235 module_load_deps(dm, flags); 234 236 } 235 237 -
uspace/lib/c/generic/rtld/rtld.c
r634e020 r5035ba05 80 80 prog_mod.dyn.soname = "[program]"; 81 81 prog_mod.rtld = env; 82 prog_mod.exec = true; 83 prog_mod.local = false; 82 84 83 85 /* Initialize list of loaded modules */ … … 96 98 97 99 DPRINTF("Load all program dependencies\n"); 98 module_load_deps(&prog_mod );100 module_load_deps(&prog_mod, 0); 99 101 100 102 /* -
uspace/lib/c/generic/rtld/symbol.c
r634e020 r5035ba05 112 112 * @param name Name of the symbol to search for. 113 113 * @param start Module in which to start the search.. 114 * @param flags @c ssf_none or @c ssf_noroot to not look for the symbol115 * in @a start116 114 * @param mod (output) Will be filled with a pointer to the module 117 115 * that contains the symbol. 118 116 */ 119 117 elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, 120 symbol_search_flags_t flags,module_t **mod)118 module_t **mod) 121 119 { 122 120 module_t *m, *dm; … … 150 148 151 149 /* If ssf_noroot is specified, do not look in start module */ 152 if (m != start || (flags & ssf_noroot) == 0) { 153 s = def_find_in_module(name, m); 154 if (s != NULL) { 155 /* Symbol found */ 156 sym = s; 157 *mod = m; 158 break; 159 } 150 s = def_find_in_module(name, m); 151 if (s != NULL) { 152 /* Symbol found */ 153 sym = s; 154 *mod = m; 155 break; 160 156 } 161 157 … … 189 185 * 190 186 * By definition in System V ABI, if module origin has the flag DT_SYMBOLIC, 191 * origin is searched first. Otherwise, or if the symbol hasn't been found, 192 * the module dependency graph is searched breadth-first, beginning 193 * from the executable program. 187 * origin is searched first. Otherwise, search global modules in the default 188 * order. 194 189 * 195 190 * @param name Name of the symbol to search for. 196 191 * @param origin Module in which the dependency originates. 197 * @param flags @c ssf_none or @c ssf_no rootto not look for the symbol192 * @param flags @c ssf_none or @c ssf_noexec to not look for the symbol 198 193 * in the executable program. 199 194 * @param mod (output) Will be filled with a pointer to the module … … 205 200 elf_symbol_t *s; 206 201 207 if (origin->dyn.symbolic) { 208 /* 202 DPRINTF("symbol_def_find('%s', origin='%s'\n", 203 name, origin->dyn.soname); 204 if (origin->dyn.symbolic && (!origin->exec || (flags & ssf_noexec) == 0)) { 205 DPRINTF("symbolic->find '%s' in module '%s'\n", name, origin->dyn.soname); 206 /* 209 207 * Origin module has a DT_SYMBOLIC flag. 210 208 * Try this module first 211 209 */ 212 213 210 s = def_find_in_module(name, origin); 211 if (s != NULL) { 214 212 /* Found */ 215 213 *mod = origin; 216 214 return s; 217 215 } 218 216 } 219 217 220 218 /* Not DT_SYMBOLIC or no match. Now try other locations. */ 221 219 222 if (origin->rtld->program) { 223 /* Program is dynamic -- start with program as root. */ 224 return symbol_bfs_find(name, origin->rtld->program, flags, mod); 225 } else { 226 /* Program is static -- start with @a origin as root. */ 227 return symbol_bfs_find(name, origin, ssf_none, mod); 228 } 220 list_foreach(origin->rtld->modules, modules_link, module_t, m) { 221 DPRINTF("module '%s' local?\n", m->dyn.soname); 222 if (!m->local && (!m->exec || (flags & ssf_noexec) == 0)) { 223 DPRINTF("!local->find '%s' in module '%s'\n", name, m->dyn.soname); 224 s = def_find_in_module(name, m); 225 if (s != NULL) { 226 /* Found */ 227 *mod = m; 228 return s; 229 } 230 } 231 } 232 233 /* Finally, try origin. */ 234 235 DPRINTF("try finding '%s' in origin '%s'\n", name, 236 origin->dyn.soname); 237 238 if (!origin->exec || (flags & ssf_noexec) == 0) { 239 s = def_find_in_module(name, origin); 240 if (s != NULL) { 241 /* Found */ 242 *mod = origin; 243 return s; 244 } 245 } 246 247 DPRINTF("'%s' not found\n", name); 248 return NULL; 229 249 } 230 250 -
uspace/lib/c/include/rtld/module.h
r634e020 r5035ba05 44 44 extern void module_process_relocs(module_t *); 45 45 extern module_t *module_find(rtld_t *, const char *); 46 extern module_t *module_load(rtld_t *, const char * );47 extern void module_load_deps(module_t * );46 extern module_t *module_load(rtld_t *, const char *, mlflags_t); 47 extern void module_load_deps(module_t *, mlflags_t); 48 48 49 49 extern void modules_process_relocs(rtld_t *, module_t *); -
uspace/lib/c/include/rtld/symbol.h
r634e020 r5035ba05 43 43 /** No flags */ 44 44 ssf_none = 0, 45 /** Do not search tree root*/46 ssf_no root= 0x145 /** Do not search in the executable */ 46 ssf_noexec = 0x1 47 47 } symbol_search_flags_t; 48 48 49 extern elf_symbol_t *symbol_bfs_find(const char *, module_t *, 50 symbol_search_flags_t, module_t **); 49 extern elf_symbol_t *symbol_bfs_find(const char *, module_t *, module_t **); 51 50 extern elf_symbol_t *symbol_def_find(const char *, module_t *, 52 51 symbol_search_flags_t, module_t **); -
uspace/lib/c/include/types/rtld/module.h
r634e020 r5035ba05 39 39 #include <sys/types.h> 40 40 41 typedef enum { 42 /** Do not export symbols to global namespace */ 43 mlf_local = 0x1 44 } mlflags_t; 45 46 /** Dynamically linked module */ 41 47 typedef struct module { 42 48 dyn_info_t dyn; … … 60 66 /** Tag for modules already processed during a BFS */ 61 67 bool bfs_tag; 68 /** If @c true, does not export symbols to global namespace */ 69 bool local; 70 /** This is the dynamically linked executable */ 71 bool exec; 62 72 } module_t; 63 73
Note:
See TracChangeset
for help on using the changeset viewer.