154 |
} |
} |
155 |
|
|
156 |
/* return elf symbol value or error */ |
/* return elf symbol value or error */ |
157 |
void *tcc_get_symbol(TCCState *s, const char *name) |
int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name) |
158 |
{ |
{ |
159 |
int sym_index; |
int sym_index; |
160 |
Elf32_Sym *sym; |
Elf32_Sym *sym; |
161 |
|
|
162 |
sym_index = find_elf_sym(symtab_section, name); |
sym_index = find_elf_sym(symtab_section, name); |
163 |
if (!sym_index) |
if (!sym_index) |
164 |
error("%s not defined", name); |
return -1; |
165 |
sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; |
sym = &((Elf32_Sym *)symtab_section->data)[sym_index]; |
166 |
return (void *)sym->st_value; |
*pval = sym->st_value; |
167 |
|
return 0; |
168 |
|
} |
169 |
|
|
170 |
|
void *tcc_get_symbol_err(TCCState *s, const char *name) |
171 |
|
{ |
172 |
|
unsigned long val; |
173 |
|
if (tcc_get_symbol(s, &val, name) < 0) |
174 |
|
error("%s not defined", name); |
175 |
|
return (void *)val; |
176 |
} |
} |
177 |
|
|
178 |
/* add an elf symbol : check if it is already defined and patch |
/* add an elf symbol : check if it is already defined and patch |
1392 |
|
|
1393 |
/* get entry point address */ |
/* get entry point address */ |
1394 |
if (file_type == TCC_OUTPUT_EXE) |
if (file_type == TCC_OUTPUT_EXE) |
1395 |
ehdr.e_entry = (unsigned long)tcc_get_symbol(s1, "_start"); |
ehdr.e_entry = (unsigned long)tcc_get_symbol_err(s1, "_start"); |
1396 |
else |
else |
1397 |
ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */ |
ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */ |
1398 |
} |
} |