allow libtcc states to be used concurrently

This allows creation of TCCStates and operation with API
calls independently from each other, even from threads.

Frontend (option parsing/libtcc.c) and backend (linker/tccelf.c)
now depend only on the TCCState (s1) argument.

Compilation per se (tccpp.c, tccgen.c) is still using
globals for convenience.  There is only one entry point
to this section which is tcc_compile() which is protected
by a semaphore.

There are some hacks involved to avoid too many changes,
as well as some changes in order to avoid too many hacks ;)

The test libtcc_test_mt.c shows the feature.  Except this
new file the patch adds 87 lines overall.
This commit is contained in:
grischka
2019-12-11 00:37:18 +01:00
parent 6082dd62bb
commit 72729d8e36
29 changed files with 805 additions and 418 deletions

View File

@@ -430,7 +430,7 @@ the_end:
#if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64
ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option)
ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int option)
{
tcc_error("-m%d not implemented.", option);
}
@@ -479,7 +479,7 @@ static int execvp_win32(const char *prog, char **argv)
#define execvp execvp_win32
#endif /* _WIN32 */
ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int target)
ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int target)
{
char program[4096];
char *a0 = argv[0];
@@ -515,7 +515,7 @@ int _dowildcard = 1;
/* -------------------------------------------------------------- */
/* generate xxx.d file */
ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename)
ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename)
{
FILE *depout;
char buf[1024];
@@ -528,7 +528,7 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename)
filename = buf;
}
if (s->verbose)
if (s1->verbose)
printf("<- %s\n", filename);
/* XXX return err codes instead of error() ? */
@@ -537,8 +537,8 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename)
tcc_error("could not open '%s'", filename);
fprintf(depout, "%s: \\\n", target);
for (i=0; i<s->nb_target_deps; ++i)
fprintf(depout, " %s \\\n", s->target_deps[i]);
for (i=0; i<s1->nb_target_deps; ++i)
fprintf(depout, " %s \\\n", s1->target_deps[i]);
fprintf(depout, "\n");
fclose(depout);
}