Changeset 32573ff in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2016-05-02T20:58:16Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7c4b26c
Parents:
6adb775f (diff), 5035ba05 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline, which has dltest and fixes.

Location:
uspace/lib/c/generic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/dlfcn.c

    r6adb775f r32573ff  
    6060        if (m == NULL) {
    6161                printf("NULL. module_load('%s')\n", path);
    62                 m = module_load(runtime_env, path);
     62                m = module_load(runtime_env, path, mlf_local);
    6363                printf("module_load_deps(m)\n");
    64                 module_load_deps(m);
     64                module_load_deps(m, mlf_local);
    6565                /* Now relocate. */
    6666                printf("module_process_relocs(m)\n");
     
    8282
    8383        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);
    8585        if (sd != NULL) {
    8686                return symbol_get_addr(sd, sm);
  • uspace/lib/c/generic/rtld/module.c

    r6adb775f r32573ff  
    6363        module_process_pre_arch(m);
    6464
    65         if (m->dyn.plt_rel == DT_REL) {
    66                 DPRINTF("table type DT_REL\n");
    67                 if (m->dyn.rel != NULL) {
    68                         DPRINTF("non-empty\n");
    69                         rel_table_process(m, m->dyn.rel, m->dyn.rel_sz);
     65        /* jmp_rel table */
     66        if (m->dyn.jmp_rel != NULL) {
     67                DPRINTF("jmp_rel table\n");
     68                if (m->dyn.plt_rel == DT_REL) {
     69                        DPRINTF("jmp_rel table type DT_REL\n");
     70                        rel_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
     71                } else {
     72                        assert(m->dyn.plt_rel == DT_RELA);
     73                        DPRINTF("jmp_rel table type DT_RELA\n");
     74                        rela_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
    7075                }
    71                 /* FIXME: this seems wrong */
    72                 if (m->dyn.jmp_rel != NULL) {
    73                 DPRINTF("table type jmp-rel\n");
    74                         DPRINTF("non-empty\n");
    75                         rel_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
    76                 }
    77         } else { /* (m->dyn.plt_rel == DT_RELA) */
    78                 DPRINTF("table type DT_RELA\n");
    79                 if (m->dyn.rela != NULL) {
    80                         DPRINTF("non-empty\n");
    81                         rela_table_process(m, m->dyn.rela, m->dyn.rela_sz);
    82                 }
     76        }
     77
     78        /* rel table */
     79        if (m->dyn.rel != NULL) {
     80                DPRINTF("rel table\n");
     81                rel_table_process(m, m->dyn.rel, m->dyn.rel_sz);
     82        }
     83
     84        /* rela table */
     85        if (m->dyn.rela != NULL) {
     86                DPRINTF("rela table\n");
     87                rela_table_process(m, m->dyn.rela, m->dyn.rela_sz);
    8388        }
    8489
     
    113118                }
    114119        }
    115        
     120
    116121        return NULL; /* Not found */
    117122}
     
    123128 * Currently this trivially tries to load '/<name>'.
    124129 */
    125 module_t *module_load(rtld_t *rtld, const char *name)
     130module_t *module_load(rtld_t *rtld, const char *name, mlflags_t flags)
    126131{
    127132        elf_finfo_t info;
     
    129134        module_t *m;
    130135        int rc;
    131        
     136
    132137        m = calloc(1, sizeof(module_t));
    133138        if (m == NULL) {
     
    138143        m->rtld = rtld;
    139144        m->id = rtld_get_next_id(rtld);
     145
     146        if ((flags & mlf_local) != 0)
     147                m->local = true;
    140148
    141149        if (str_size(name) > NAME_BUF_SIZE - 2) {
     
    190198/** Load all modules on which m (transitively) depends.
    191199 */
    192 void module_load_deps(module_t *m)
     200void module_load_deps(module_t *m, mlflags_t flags)
    193201{
    194202        elf_dyn_t *dp;
     
    235243                        dm = module_find(m->rtld, dep_name);
    236244                        if (!dm) {
    237                                 dm = module_load(m->rtld, dep_name);
    238                                 module_load_deps(dm);
     245                                dm = module_load(m->rtld, dep_name, flags);
     246                                module_load_deps(dm, flags);
    239247                        }
    240248
  • uspace/lib/c/generic/rtld/rtld.c

    r6adb775f r32573ff  
    8989        prog->rtld = env;
    9090        prog->id = rtld_get_next_id(env);
     91        prog->exec = true;
     92        prog->local = false;
    9193
    9294        prog->tdata = p_info->tls.tdata;
     
    112114
    113115        DPRINTF("Load all program dependencies\n");
    114         module_load_deps(prog);
     116        module_load_deps(prog, 0);
    115117
    116118        /*
  • uspace/lib/c/generic/rtld/symbol.c

    r6adb775f r32573ff  
    112112 * @param name          Name of the symbol to search for.
    113113 * @param start         Module in which to start the search..
    114  * @param flags         @c ssf_none or @c ssf_noroot to not look for the symbol
    115  *                      in @a start
    116114 * @param mod           (output) Will be filled with a pointer to the module
    117115 *                      that contains the symbol.
    118116 */
    119117elf_symbol_t *symbol_bfs_find(const char *name, module_t *start,
    120     symbol_search_flags_t flags, module_t **mod)
     118    module_t **mod)
    121119{
    122120        module_t *m, *dm;
     
    150148
    151149                /* 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;
    160156                }
    161157
     
    189185 *
    190186 * 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.
    194189 *
    195190 * @param name          Name of the symbol to search for.
    196191 * @param origin        Module in which the dependency originates.
    197  * @param flags         @c ssf_none or @c ssf_noroot to not look for the symbol
     192 * @param flags         @c ssf_none or @c ssf_noexec to not look for the symbol
    198193 *                      in the executable program.
    199194 * @param mod           (output) Will be filled with a pointer to the module
     
    205200        elf_symbol_t *s;
    206201
    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                /*
    209207                 * Origin module has a DT_SYMBOLIC flag.
    210208                 * Try this module first
    211209                 */
    212                  s = def_find_in_module(name, origin);
    213                  if (s != NULL) {
     210                s = def_find_in_module(name, origin);
     211                if (s != NULL) {
    214212                        /* Found */
    215213                        *mod = origin;
    216214                        return s;
    217                  }
     215                }
    218216        }
    219217
    220218        /* Not DT_SYMBOLIC or no match. Now try other locations. */
    221219
    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;
    229249}
    230250
Note: See TracChangeset for help on using the changeset viewer.