Changeset 0f792c28 in mainline


Ignore:
Timestamp:
2016-04-12T16:59:41Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2e9a8a
Parents:
3b0f1b9a
Message:

Source for R_*_COPY relocations must be searched for everywhere except for the executable itself (Thanks Jakub)

Location:
uspace/lib/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/ia32/src/rtld/reloc.c

    r3b0f1b9a r0f792c28  
    6969        uint32_t sym_size;
    7070        char *str_tab;
    71        
     71
    7272        elf_symbol_t *sym_def;
    7373        module_t *dest;
     
    8080
    8181        DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
    82        
     82
    8383        for (i = 0; i < rt_entries; ++i) {
    8484//              DPRINTF("symbol %d: ", i);
     
    100100//                      DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
    101101                        sym_def = symbol_def_find(str_tab + sym->st_name,
    102                             m, &dest);
     102                            m, ssf_none, &dest);
    103103//                      DPRINTF("dest name: '%s'\n", dest->dyn.soname);
    104104//                      DPRINTF("dest bias: 0x%x\n", dest->bias);
     
    137137                        /*
    138138                         * Copy symbol data from shared object to specified
    139                          * location.
     139                         * location. Need to find the 'source', i.e. the
     140                         * other instance of the object than the one in the
     141                         * executable program.
    140142                         */
    141143                        DPRINTF("fixup R_386_COPY (s)\n");
     144
     145                        sym_def = symbol_def_find(str_tab + sym->st_name,
     146                            m, ssf_noroot, &dest);
     147
     148                        if (sym_def) {
     149                                sym_addr = (uint32_t)
     150                                    symbol_get_addr(sym_def, dest);
     151                        } else {
     152                                printf("Source definition of '%s' not found.\n",
     153                                    str_tab + sym->st_name);
     154                                continue;
     155                        }
     156
    142157                        sym_size = sym->st_size;
    143158                        if (sym_size != sym_def->st_size) {
     
    147162                                        sym_size = sym_def->st_size;
    148163                        }
     164
    149165                        memcpy(r_ptr, (const void *)sym_addr, sym_size);
    150166                        break;
    151                        
     167
    152168                case R_386_RELATIVE:
    153169                        DPRINTF("fixup R_386_RELATIVE (b+a)\n");
  • uspace/lib/c/generic/dlfcn.c

    r3b0f1b9a r0f792c28  
    8181
    8282        printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
    83         sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
     83        sd = symbol_bfs_find(sym_name, (module_t *) mod, ssf_none, &sm);
    8484        if (sd != NULL) {
    8585                return symbol_get_addr(sd, sm);
  • uspace/lib/c/generic/rtld/symbol.c

    r3b0f1b9a r0f792c28  
    111111 * @param name          Name of the symbol to search for.
    112112 * @param start         Module in which to start the search..
     113 * @param flags         @c ssf_none or @c ssf_noroot to not look for the symbol
     114 *                      in @a start
    113115 * @param mod           (output) Will be filled with a pointer to the module
    114116 *                      that contains the symbol.
    115117 */
    116 elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod)
     118elf_symbol_t *symbol_bfs_find(const char *name, module_t *start,
     119    symbol_search_flags_t flags, module_t **mod)
    117120{
    118121        module_t *m, *dm;
     
    145148                list_remove(&m->queue_link);
    146149
    147                 s = def_find_in_module(name, m);
    148                 if (s != NULL) {
    149                         /* Symbol found */
    150                         sym = s;
    151                         *mod = m;
    152                         break;
     150                /* If ssf_noroot is specified, do not look in start module */
     151                if (m != start || (flags & ssf_noroot) == 0) {
     152                        s = def_find_in_module(name, m);
     153                        if (s != NULL) {
     154                                /* Symbol found */
     155                                sym = s;
     156                                *mod = m;
     157                                break;
     158                        }
    153159                }
    154160
     
    179185
    180186
    181 /** Find the definition of a symbol..
     187/** Find the definition of a symbol.
    182188 *
    183189 * By definition in System V ABI, if module origin has the flag DT_SYMBOLIC,
     
    188194 * @param name          Name of the symbol to search for.
    189195 * @param origin        Module in which the dependency originates.
     196 * @param flags         @c ssf_none or @c ssf_noroot to not look for the symbol
     197 *                      in the executable program.
    190198 * @param mod           (output) Will be filled with a pointer to the module
    191199 *                      that contains the symbol.
    192200 */
    193 elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod)
     201elf_symbol_t *symbol_def_find(const char *name, module_t *origin,
     202    symbol_search_flags_t flags, module_t **mod)
    194203{
    195204        elf_symbol_t *s;
     
    212221        if (runtime_env->program) {
    213222                /* Program is dynamic -- start with program as root. */
    214                 return symbol_bfs_find(name, runtime_env->program, mod);
     223                return symbol_bfs_find(name, runtime_env->program, flags, mod);
    215224        } else {
    216225                /* Program is static -- start with @a origin as root. */
    217                 return symbol_bfs_find(name, origin, mod);
     226                return symbol_bfs_find(name, origin, ssf_none, mod);
    218227        }
    219228}
  • uspace/lib/c/include/rtld/symbol.h

    r3b0f1b9a r0f792c28  
    3939#include <rtld/rtld.h>
    4040
    41 elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod);
    42 elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod);
    43 void *symbol_get_addr(elf_symbol_t *sym, module_t *m);
     41/** Symbol search flags */
     42typedef enum {
     43        /** No flags */
     44        ssf_none = 0,
     45        /** Do not search tree root */
     46        ssf_noroot = 0x1
     47} symbol_search_flags_t;
     48
     49extern elf_symbol_t *symbol_bfs_find(const char *, module_t *,
     50    symbol_search_flags_t, module_t **);
     51extern elf_symbol_t *symbol_def_find(const char *, module_t *,
     52    symbol_search_flags_t, module_t **);
     53extern void *symbol_get_addr(elf_symbol_t *, module_t *);
    4454
    4555#endif
Note: See TracChangeset for help on using the changeset viewer.