From ca38792df17fc5c8d2bb6757c512101610420f1e Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 1 Sep 2012 11:33:34 +0200 Subject: [PATCH] tccrun: another incompatible change to the tcc_relocate API 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. --- libtcc.h | 11 ++++++++--- tccrun.c | 8 ++++++-- tests/libtcc_test.c | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libtcc.h b/libtcc.h index 35a5889a..278dca30 100644 --- a/libtcc.h +++ b/libtcc.h @@ -91,9 +91,14 @@ LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename); tcc_relocate() before. */ LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv); -/* Do all relocations (needed before using tcc_get_symbol()) - Returns -1 on error. */ -LIBTCCAPI int tcc_relocate(TCCState *s1); +/* do all relocations (needed before using tcc_get_symbol()) + possible values for 'ptr': + - TCC_RELOCATE_AUTO : Allocate and manage memory internally + - NULL : return required memory size for the step below + - memory address : copy code to memory passed by the caller + returns -1 on error. */ +LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr); +#define TCC_RELOCATE_AUTO (void*)1 /* return symbol value or NULL if not found */ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); diff --git a/tccrun.c b/tccrun.c index 41081ccd..531f46a8 100644 --- a/tccrun.c +++ b/tccrun.c @@ -47,9 +47,13 @@ static void win64_add_function_table(TCCState *s1); /* Do all relocations (needed before using tcc_get_symbol()) Returns -1 on error. */ -LIBTCCAPI int tcc_relocate(TCCState *s1) +LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) { int ret; + + if (TCC_RELOCATE_AUTO != ptr) + return tcc_relocate_ex(s1, ptr); + #ifdef HAVE_SELINUX /* Use mmap instead of malloc for Selinux 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) int (*prog_main)(int, char **); int ret; - if (tcc_relocate(s1) < 0) + if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0) return -1; prog_main = tcc_get_symbol_err(s1, "main"); diff --git a/tests/libtcc_test.c b/tests/libtcc_test.c index 5a4c8003..bead0ff8 100644 --- a/tests/libtcc_test.c +++ b/tests/libtcc_test.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) tcc_add_symbol(s, "add", add); /* relocate the code */ - if (tcc_relocate(s) < 0) + if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) return 1; /* get entry symbol */ -- 2.11.4.GIT