History

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.

grischka committed 14 years ago

Commit ca387921 parent 56e23983 files · +15 −6Browse files

Unified · Split

3 files
  1. libtcc.h +8 −3
  2. tccrun.c +6 −2
  3. tests/libtcc_test.c +1 −1
libtcc.h+8−3
@@ -91,9 +91,14 @@ LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename); · 90 unmodified lines
9191 tcc_relocate() before. */
9292 LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
9393
94−/* Do all relocations (needed before using tcc_get_symbol())
95− Returns -1 on error. */
96−LIBTCCAPI int tcc_relocate(TCCState *s1);
94+/* do all relocations (needed before using tcc_get_symbol())
95+ possible values for 'ptr':
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
97102
98103 /* return symbol value or NULL if not found */
99104 LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
tccrun.c+6−2
@@ -47,9 +47,13 @@ static void win64_add_function_table(TCCState *s1); · 46 unmodified lines
4747 /* Do all relocations (needed before using tcc_get_symbol())
4848 Returns -1 on error. */
4949
50−LIBTCCAPI int tcc_relocate(TCCState *s1)
50+LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
5151 {
5252 int ret;
53+
54+ if (TCC_RELOCATE_AUTO != ptr)
55+ return tcc_relocate_ex(s1, ptr);
56+
5357 #ifdef HAVE_SELINUX
5458 /* Use mmap instead of malloc for Selinux
5559 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
8791 int (*prog_main)(int, char **);
8892 int ret;
8993
90− if (tcc_relocate(s1) < 0)
94+ if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
9195 return -1;
9296
9397 prog_main = tcc_get_symbol_err(s1, "main");
tests/libtcc_test.c+1−1
@@ -58,7 +58,7 @@ int main(int argc, char **argv) · 57 unmodified lines
5858 tcc_add_symbol(s, "add", add);
5959
6060 /* relocate the code */
61− if (tcc_relocate(s) < 0)
61+ if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
6262 return 1;
6363
6464 /* get entry symbol */

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