Hi, I'm currently developping a Lua binding for libtcc, and I came into two problems when building TCC.
The first is a symbol collision for the function error with my glibc. I use glibc-2.3.5 with gcc-3.3.6 on a Slackware Linux. The symbol error is defined in glibc, and tcc source code contain a function with the same name. GCC's linker can't figure which to use and messes up the final executable, with weird behaviour. It took me some time to figure it out, so I patched TCC makefile so that the symbol collision don't happen. Here is the patch, it would be nice to include it in next release : diff -ur tcc-0.9.23/Makefile tcc-0.9.23-luatcc/Makefile --- tcc-0.9.23/Makefile 2005-06-17 18:09:15.000000000 -0400 +++ tcc-0.9.23-luatcc/Makefile 2007-02-03 21:15:02.000000000 -0500 @@ -3,7 +3,7 @@ # include config.mak -CFLAGS=-O2 -g -Wall +CFLAGS=-O2 -g -Wall -Derror=tccerror ifndef CONFIG_WIN32 LIBS=-ldl BCHECK_O=bcheck.o The second problem I ran into is related to tcc_compile_string. I use it to compile files which I preprocess. But tcc_compile_string errors messages don't specify the original source file of the string it compiles, and uses "<string>" as the source name. So I added a function called tcc_compile_named_string which takes as an additionnal parameter a name for the source string to be shown in error messages. If NULL is passed it falls back to "<string>". Here is the patch : diff -ur tcc-0.9.23/libtcc.h tcc-0.9.23-luatcc/libtcc.h --- tcc-0.9.23/libtcc.h 2005-06-17 18:09:15.000000000 -0400 +++ tcc-0.9.23-luatcc/libtcc.h 2007-02-03 21:35:29.000000000 -0500 @@ -51,6 +51,10 @@ error. */ int tcc_compile_string(TCCState *s, const char *buf); +/* compile a string containing a C source. Return non zero if + error. Can associate a name with string for errors. */ +int tcc_compile_named_string(TCCState *s, const char *buf, const char *strname); + /*****************************/ /* linking commands */ diff -ur tcc-0.9.23/tcc.c tcc-0.9.23-luatcc/tcc.c --- tcc-0.9.23/tcc.c 2005-06-17 18:09:15.000000000 -0400 +++ tcc-0.9.23-luatcc/tcc.c 2007-02-03 21:53:59.000000000 -0500 @@ -9234,7 +9234,7 @@ } #ifdef LIBTCC -int tcc_compile_string(TCCState *s, const char *str) +int tcc_compile_named_string(TCCState *s, const char *str, const char *strname) { BufferedFile bf1, *bf = &bf1; int ret, len; @@ -9251,7 +9251,10 @@ buf[len] = CH_EOB; bf->buf_ptr = buf; bf->buf_end = buf + len; - pstrcpy(bf->filename, sizeof(bf->filename), "<string>"); + if (strname!=NULL) + pstrcpy(bf->filename, sizeof(bf->filename), strname); + else + pstrcpy(bf->filename, sizeof(bf->filename), "<string>"); bf->line_num = 1; file = bf; @@ -9262,6 +9265,11 @@ /* currently, no need to close */ return ret; } + +int tcc_compile_string(TCCState *s, const char *str) +{ + return tcc_compile_named_string(s, str, NULL); +} #endif /* define a preprocessor symbol. A value can also be provided with the '=' operator */ It would be nice to see the second patch in a future release of TCC, if any is planned, so that I don't have to distribute it with my Lua binding. If necessary I can resend the patch to another address in another format, just tell me :-) Jérôme.
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel