We are now compatible with the 0.9,25 version though. A special value for the second (ptr) argument is used to get the simple behavior as with the 0.9.24 version.
Unified · Split
| @@ -91,9 +91,14 @@ LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename); · 90 unmodified lines | |||
| 91 | tcc_relocate() before. */ | 91 | tcc_relocate() before. */ |
| 92 | LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv); | 92 | LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv); |
| 93 | 93 | ||
| 94 | /* Do all relocations (needed before using tcc_get_symbol()) | 94 | /* do all relocations (needed before using tcc_get_symbol()) |
| 95 | Returns -1 on error. */ | 95 | possible values for 'ptr': |
| 96 | LIBTCCAPI int tcc_relocate(TCCState *s1); | 96 | - TCC_RELOCATE_AUTO : Allocate and manage memory internally |
| 97 | - NULL : return required memory size for the step below | ||
| 98 | - memory address : copy code to memory passed by the caller | ||
| 99 | returns -1 on error. */ | ||
| 100 | LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr); | ||
| 101 | #define TCC_RELOCATE_AUTO (void*)1 | ||
| 97 | 102 | ||
| 98 | /* return symbol value or NULL if not found */ | 103 | /* return symbol value or NULL if not found */ |
| 99 | LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); | 104 | LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); |
| @@ -47,9 +47,13 @@ static void win64_add_function_table(TCCState *s1); · 46 unmodified lines | |||
| 47 | /* Do all relocations (needed before using tcc_get_symbol()) | 47 | /* Do all relocations (needed before using tcc_get_symbol()) |
| 48 | Returns -1 on error. */ | 48 | Returns -1 on error. */ |
| 49 | 49 | ||
| 50 | LIBTCCAPI int tcc_relocate(TCCState *s1) | 50 | LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) |
| 51 | { | 51 | { |
| 52 | int ret; | 52 | int ret; |
| 53 | |||
| 54 | if (TCC_RELOCATE_AUTO != ptr) | ||
| 55 | return tcc_relocate_ex(s1, ptr); | ||
| 56 | |||
| 53 | #ifdef HAVE_SELINUX | 57 | #ifdef HAVE_SELINUX |
| 54 | /* Use mmap instead of malloc for Selinux | 58 | /* Use mmap instead of malloc for Selinux |
| 55 | Ref http://www.gnu.org/s/libc/manual/html_node/File-Size.html */ | 59 | Ref http://www.gnu.org/s/libc/manual/html_node/File-Size.html */ |
| @@ -87,7 +91,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 31 unmodified lines | |||
| 87 | int (*prog_main)(int, char **); | 91 | int (*prog_main)(int, char **); |
| 88 | int ret; | 92 | int ret; |
| 89 | 93 | ||
| 90 | if (tcc_relocate(s1) < 0) | 94 | if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0) |
| 91 | return -1; | 95 | return -1; |
| 92 | 96 | ||
| 93 | prog_main = tcc_get_symbol_err(s1, "main"); | 97 | prog_main = tcc_get_symbol_err(s1, "main"); |
| @@ -58,7 +58,7 @@ int main(int argc, char **argv) · 57 unmodified lines | |||
| 58 | tcc_add_symbol(s, "add", add); | 58 | tcc_add_symbol(s, "add", add); |
| 59 | 59 | ||
| 60 | /* relocate the code */ | 60 | /* relocate the code */ |
| 61 | if (tcc_relocate(s) < 0) | 61 | if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) |
| 62 | return 1; | 62 | return 1; |
| 63 | 63 | ||
| 64 | /* get entry symbol */ | 64 | /* get entry symbol */ |