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
8383 non zero if link error. */
8484 int tcc_relocate(TCCState *s);
8585
86−/* return symbol value or error */
87−void *tcc_get_symbol(TCCState *s, const char *name);
86+/* return symbol value. return 0 if OK, -1 if symbol not found */
87+int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name);
8888
8989 #ifdef __cplusplus
9090 }
libtcc_test.c+5−3
@@ -35,7 +35,8 @@ int main(int argc, char **argv) · 34 unmodified lines
3535 {
3636 TCCState *s;
3737 int (*func)(int);
38−
38+ unsigned long val;
39+
3940 s = tcc_new();
4041 if (!s) {
4142 fprintf(stderr, "Could not create tcc state\n");
@@ -54,8 +55,9 @@ int main(int argc, char **argv) · 12 unmodified lines
5455
5556 tcc_relocate(s);
5657
57− func = tcc_get_symbol(s, "foo");
58−
58+ tcc_get_symbol(s, &val, "foo");
59+ func = (void *)val;
60+
5961 func(32);
6062
6163 tcc_delete(s);
tcc.c+4−3
@@ -9115,7 +9115,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 9114 unmodified lines
91159115 if (tcc_relocate(s1) < 0)
91169116 return -1;
91179117
9118− prog_main = tcc_get_symbol(s1, "main");
9118+ prog_main = tcc_get_symbol_err(s1, "main");
91199119
91209120 if (do_debug) {
91219121 #ifdef WIN32
@@ -9140,10 +9140,11 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 18 unmodified lines
91409140 void (*bound_init)(void);
91419141
91429142 /* 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");
91449145
91459146 /* 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");
91479148 bound_init();
91489149 }
91499150 #endif
tccelf.c+13−4
@@ -154,16 +154,25 @@ static int find_elf_sym(Section *s, const char *name) · 153 unmodified lines
154154 }
155155
156156 /* return elf symbol value or error */
157−void *tcc_get_symbol(TCCState *s, const char *name)
157+int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name)
158158 {
159159 int sym_index;
160160 Elf32_Sym *sym;
161161
162162 sym_index = find_elf_sym(symtab_section, name);
163163 if (!sym_index)
164− error("%s not defined", name);
164+ return -1;
165165 sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
166− return (void *)sym->st_value;
166+ *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;
167176 }
168177
169178 /* 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
13831392
13841393 /* get entry point address */
13851394 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");
13871396 else
13881397 ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
13891398 }

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