changeset 283:5bd410aefdc4

[project @ 2003-07-20 19:19:58 by bellard] changed tcc_get_symbol() prototype
author bellard
date Sun, 20 Jul 2003 19:19:59 +0000
parents 950acf85e8ac
children 8ab5c15040ff
files libtcc.h libtcc_test.c tcc.c tccelf.c
diffstat 4 files changed, 24 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libtcc.h	Sun Jul 20 18:44:29 2003 +0000
+++ b/libtcc.h	Sun Jul 20 19:19:59 2003 +0000
@@ -83,8 +83,8 @@
    non zero if link error. */
 int tcc_relocate(TCCState *s);
 
-/* return symbol value or error */
-void *tcc_get_symbol(TCCState *s, const char *name);
+/* return symbol value. return 0 if OK, -1 if symbol not found */
+int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name);
 
 #ifdef __cplusplus
 }
--- a/libtcc_test.c	Sun Jul 20 18:44:29 2003 +0000
+++ b/libtcc_test.c	Sun Jul 20 19:19:59 2003 +0000
@@ -35,7 +35,8 @@
 {
     TCCState *s;
     int (*func)(int);
-
+    unsigned long val;
+    
     s = tcc_new();
     if (!s) {
         fprintf(stderr, "Could not create tcc state\n");
@@ -54,8 +55,9 @@
     
     tcc_relocate(s);
 
-    func = tcc_get_symbol(s, "foo");
-    
+    tcc_get_symbol(s, &val, "foo");
+    func = (void *)val;
+
     func(32);
 
     tcc_delete(s);
--- a/tcc.c	Sun Jul 20 18:44:29 2003 +0000
+++ b/tcc.c	Sun Jul 20 19:19:59 2003 +0000
@@ -9115,7 +9115,7 @@
     if (tcc_relocate(s1) < 0)
         return -1;
 
-    prog_main = tcc_get_symbol(s1, "main");
+    prog_main = tcc_get_symbol_err(s1, "main");
     
     if (do_debug) {
 #ifdef WIN32
@@ -9140,10 +9140,11 @@
         void (*bound_init)(void);
 
         /* set error function */
-        rt_bound_error_msg = (void *)tcc_get_symbol(s1, "__bound_error_msg");
+        rt_bound_error_msg = (void *)tcc_get_symbol_err(s1, 
+                                                        "__bound_error_msg");
 
         /* XXX: use .init section so that it also work in binary ? */
-        bound_init = (void *)tcc_get_symbol(s1, "__bound_init");
+        bound_init = (void *)tcc_get_symbol_err(s1, "__bound_init");
         bound_init();
     }
 #endif
--- a/tccelf.c	Sun Jul 20 18:44:29 2003 +0000
+++ b/tccelf.c	Sun Jul 20 19:19:59 2003 +0000
@@ -154,16 +154,25 @@
 }
 
 /* return elf symbol value or error */
-void *tcc_get_symbol(TCCState *s, const char *name)
+int tcc_get_symbol(TCCState *s, unsigned long *pval, const char *name)
 {
     int sym_index;
     Elf32_Sym *sym;
     
     sym_index = find_elf_sym(symtab_section, name);
     if (!sym_index)
-        error("%s not defined", name);
+        return -1;
     sym = &((Elf32_Sym *)symtab_section->data)[sym_index];
-    return (void *)sym->st_value;
+    *pval = sym->st_value;
+    return 0;
+}
+
+void *tcc_get_symbol_err(TCCState *s, const char *name)
+{
+    unsigned long val;
+    if (tcc_get_symbol(s, &val, name) < 0)
+        error("%s not defined", name);
+    return (void *)val;
 }
 
 /* add an elf symbol : check if it is already defined and patch
@@ -1383,7 +1392,7 @@
 
         /* get entry point address */
         if (file_type == TCC_OUTPUT_EXE)
-            ehdr.e_entry = (unsigned long)tcc_get_symbol(s1, "_start");
+            ehdr.e_entry = (unsigned long)tcc_get_symbol_err(s1, "_start");
         else
             ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */
     }