Subversion Repositories HelenOS

Rev

Rev 2998 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2998 Rev 2999
Line 101... Line 101...
101
    }
101
    }
102
 
102
 
103
    return sym; /* Found */
103
    return sym; /* Found */
104
}
104
}
105
 
105
 
-
 
106
/** Find the definition of a symbol.
-
 
107
 *
-
 
108
 * By definition in System V ABI, if module origin has the flag DT_SYMBOLIC,
-
 
109
 * origin is searched first. Otherwise, or if the symbol hasn't been found,
-
 
110
 * the module dependency graph is searched breadth-first, beginning
-
 
111
 * from the executable program.
106
 
112
 *
-
 
113
 * @param name      Name of the symbol to search for.
-
 
114
 * @param origin    Module in which the dependency originates.
-
 
115
 * @param mod       (output) Will be filled with a pointer to the module
-
 
116
 *          that contains the symbol.
-
 
117
 */
107
elf_symbol_t *symbol_def_find(char *name, module_t **m)
118
elf_symbol_t *symbol_def_find(char *name, module_t *origin, module_t **mod)
108
{
119
{
-
 
120
    module_t *m;
109
    elf_symbol_t *sym;
121
    elf_symbol_t *sym;
110
 
122
 
-
 
123
    /* FIXME: support DT_SYMBOLIC */
-
 
124
    //m = origin;
-
 
125
 
111
    sym = def_find_in_module(name, runtime_env.program);
126
    /* Start in the executable program */
112
    if (sym != NULL) { *m = runtime_env.program; return sym; } 
127
    m = runtime_env.program;
113
 
128
 
-
 
129
    while (true) {
114
    sym = def_find_in_module(name, runtime_env.libc);
130
        sym = def_find_in_module(name, m);
-
 
131
        if (sym != NULL) {
-
 
132
            *mod = m;
-
 
133
            return sym;
-
 
134
        }
-
 
135
 
-
 
136
        if (m->n_deps < 1) break;
-
 
137
 
-
 
138
        /* FIXME: support branching */
-
 
139
        if (m->n_deps > 1) {
115
    if (sym != NULL) { *m = runtime_env.libc; return sym; }
140
            printf("error: BFS unimplemented\n");
-
 
141
            exit(1);
-
 
142
        }
116
 
143
 
117
    sym = def_find_in_module(name, &runtime_env.rtld);
144
        m = m->deps[0];
118
    if (sym != NULL) { *m = &runtime_env.rtld; return sym; }
-
 
-
 
145
    }
119
 
146
 
120
    printf("symbol found nowhere\n");
147
    printf("Error, symbol '%s' not found anywhere\n", name);
121
    *m = NULL;
148
    exit(1);
122
    return NULL;
149
    return NULL; /* Not found */
123
}
150
}
124
 
151
 
125
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m)
152
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m)
126
{
153
{
127
    if (sym->st_shndx == SHN_ABS) {
154
    if (sym->st_shndx == SHN_ABS) {