History

changed tcc_get_symbol() prototype

bellard committed 23 years ago

Commit f8d02411 parent c5959b74 files · +24 −12Browse files

Unified · Split

4 files
  1. libtcc.h +2 −2
  2. libtcc_test.c +5 −3
  3. tcc.c +4 −3
  4. tccelf.c +13 −4
libtcc.h+2−2
@@ -83,8 +83,8 @@ int tcc_run(TCCState *s, int argc, char **argv); · 82 unmodified lines
83 non zero if link error. */83 non zero if link error. */
84int tcc_relocate(TCCState *s);84int tcc_relocate(TCCState *s);
85 85
86/* return symbol value or error */86/* return symbol value. return 0 if OK, -1 if symbol not found */
87void *tcc_get_symbol(TCCState *s, const char *name);87int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name);
88 88
89#ifdef __cplusplus89#ifdef __cplusplus
90}90}
libtcc_test.c+5−3
@@ -35,7 +35,8 @@ int main(int argc, char **argv) · 34 unmodified lines
35{35{
36 TCCState *s;36 TCCState *s;
37 int (*func)(int);37 int (*func)(int);
38 38 unsigned long val;
39
39 s = tcc_new();40 s = tcc_new();
40 if (!s) {41 if (!s) {
41 fprintf(stderr, "Could not create tcc state\n");42 fprintf(stderr, "Could not create tcc state\n");
@@ -54,8 +55,9 @@ int main(int argc, char **argv) · 12 unmodified lines
54 55
55 tcc_relocate(s);56 tcc_relocate(s);
56 57
57 func = tcc_get_symbol(s, "foo");58 tcc_get_symbol(s, &val, "foo");
58 59 func = (void *)val;
60
59 func(32);61 func(32);
60 62
61 tcc_delete(s);63 tcc_delete(s);
tcc.c+4−3
@@ -9115,7 +9115,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 9114 unmodified lines
9115 if (tcc_relocate(s1) < 0)9115 if (tcc_relocate(s1) < 0)
9116 return -1;9116 return -1;
9117 9117
9118 prog_main = tcc_get_symbol(s1, "main");9118 prog_main = tcc_get_symbol_err(s1, "main");
9119 9119
9120 if (do_debug) {9120 if (do_debug) {
9121#ifdef WIN329121#ifdef WIN32
@@ -9140,10 +9140,11 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 18 unmodified lines
9140 void (*bound_init)(void);9140 void (*bound_init)(void);
9141 9141
9142 /* set error function */9142 /* set error function */
9143 rt_bound_error_msg = (void *)tcc_get_symbol(s1, "__bound_error_msg");9143 rt_bound_error_msg = (void *)tcc_get_symbol_err(s1,
9144 "__bound_error_msg");
9144 9145
9145 /* XXX: use .init section so that it also work in binary ? */9146 /* XXX: use .init section so that it also work in binary ? */
9146 bound_init = (void *)tcc_get_symbol(s1, "__bound_init");9147 bound_init = (void *)tcc_get_symbol_err(s1, "__bound_init");
9147 bound_init();9148 bound_init();
9148 }9149 }
9149#endif9150#endif
tccelf.c+13−4
@@ -154,16 +154,25 @@ static int find_elf_sym(Section *s, const char *name) · 153 unmodified lines
154}154}
155 155
156/* return elf symbol value or error */156/* return elf symbol value or error */
157void *tcc_get_symbol(TCCState *s, const char *name)157int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name)
158{158{
159 int sym_index;159 int sym_index;
160 Elf32_Sym *sym;160 Elf32_Sym *sym;
161 161
162 sym_index = find_elf_sym(symtab_section, name);162 sym_index = find_elf_sym(symtab_section, name);
163 if (!sym_index)163 if (!sym_index)
164 error("%s not defined", name);164 return -1;
165 sym = &((Elf32_Sym *)symtab_section->data)[sym_index];165 sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
166 return (void *)sym->st_value;166 *pval = sym->st_value;
167 return 0;
168}
169
170void *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;
167}176}
168 177
169/* add an elf symbol : check if it is already defined and patch178/* add an elf symbol : check if it is already defined and patch
@@ -1383,7 +1392,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 1213 unmodified lines
1383 1392
1384 /* get entry point address */1393 /* get entry point address */
1385 if (file_type == TCC_OUTPUT_EXE)1394 if (file_type == TCC_OUTPUT_EXE)
1386 ehdr.e_entry = (unsigned long)tcc_get_symbol(s1, "_start");1395 ehdr.e_entry = (unsigned long)tcc_get_symbol_err(s1, "_start");
1387 else1396 else
1388 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */1397 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
1389 }1398 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t