sljit
sljit copied to clipboard
TCC compiler fails
Hi,
I just found the project, so I am not very familiar with it. However, I tried to compile it with the Tiny C Compiler and it fails. TCC is not a large and powerful compiler, but I have been able to use it quite successfully in a few large programs.
Since you mention in the README that it should compile with any capable C compiler (TCC is quite capable and fast) I decided to create this issue. Here is the actual error:
CC=/home/fernando/Builds/tcc-0.9.27-master/tcc make
/home/fernando/Builds/tcc-0.9.27-master/tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -c -o bin/sljitMain.o test_src/sljitMain.c
/home/fernando/Builds/tcc-0.9.27-master/tcc -Isljit_src -DSLJIT_HAVE_CONFIG_PRE=1 -Itest_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror bin/sljitMain.o test_src/sljitTest.c sljit_src/sljitLir.c -o bin/sljit_test -lm -lpthread
In file included from sljit_src/sljitLir.c:2250:
sljit_src/sljitNativeX86_common.c:364: error: '(' expected (got "{")
make: *** [Makefile:67: bin/sljit_test] Fehler 1
I did not dig much deeper into it since I am not familiar with the source code and I currently do not have much time. I still wanted to bring this to your attention. I used the latest release 0.9.27, which is quite old, and the master version, which has see a lot of development in recent years. Both fail with the same error.
Thank you for the cool project! Best regards, Fer
That is the get_cpu_features
, and it uses __asm
to run a cpuid
instruction on windows. If you have an intrinsic for this instruction, then you can port the compiler, or use some way to static detection of cpu features.
Thank you for your work @minipli-oss!
Hi @minipli-oss and @zherczeg,
I tested the new code to test for myself if TCC actually works but I could not get it running. I am using the latest TCC (git, mob branch, compiled today).
On x86_64
I get the following error:
make CC=tcc
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -c -o bin/sljitMain.o test_src/sljitMain.c
tcc -Isljit_src -DSLJIT_HAVE_CONFIG_PRE=1 -Itest_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror bin/sljitMain.o test_src/sljitTest.c sljit_src/sljitLir.c -o bin/sljit_test -lm -lpthread
In file included from sljit_src/sljitLir.c:2403:
sljit_src/sljitNativeX86_common.c:372: error: unknown opcode 'lzcnt'
make: *** [Makefile:67: bin/sljit_test] Fehler 1
There seems to be some instructions for x86
that TCC is just not able to recognise. In this case lzcnt
.
I tried the same on RISC-V running Debian 64-bit. Here is the error:
make CC=tcc
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -c -o bin/sljitMain.o test_src/sljitMain.c
tcc -Isljit_src -DSLJIT_HAVE_CONFIG_PRE=1 -Itest_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror bin/sljitMain.o test_src/sljitTest.c sljit_src/sljitLir.c -o bin/sljit_test -lm -lpthread
In file included from sljit_src/sljitLir.c:2417:
sljit_src/sljitNativeRISCV_common.c:525: error: implicit declaration of function '__clear_cache'
make: *** [Makefile:67: bin/sljit_test] Error 1
If I have time I may debug the issue in RISC-V. But my x86
ASM knowledge is very limited.
I am sorry for the bad news. Nonetheless, thank you for your work! Though I am intrigued that it actually worked for you @minipli-oss
Best regards, Fer
'lzcnt/tzcnt' is implemented as rep bsr/bsf
. The support can be detected by checking the zero flag for zero input. You can also do it by cpuid
, but you cannot detect that the amd defined 0x80000001
is supported by cpuid or not. So this way the check is safer. On windows we use the cpuid, because the intrinsic does not provide the zero flag result, hence the minimum cpu requirement is higher there.
The __clear_cache
is a gcc built-in for instruction cache flush. If it is not always available, we might need to do it by ourselves.
https://elixir.bootlin.com/linux/v4.15.5/source/arch/riscv/include/asm/cacheflush.h Well, the instruction cache flush is not too efficient there.
Thank you for clearing up the issues. I currently do not have much time to patch things out, but I will try to test any solution that is proposed.
Ahh, too bad. @zherczeg added this code after my initial attempt to add tcc support. And yes, this new code adds inline ASM with x86 instructions, tcc doesn't recognize.
I've added support for these to tcc via https://repo.or.cz/tinycc.git/commit/9cfc8f60. Please give it another try. x86 should work now, at least is does so for me (again).
I can't test RISC-V, though.
Thanks @minipli-oss! I rebuilt TCC mob branch and it now compiles on x86_64
!
fernando@localhost:~/Builds/sljit> make CC=tcc
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -c -o bin/sljitMain.o test_src/sljitMain.c
tcc -Isljit_src -DSLJIT_HAVE_CONFIG_PRE=1 -Itest_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror bin/sljitMain.o test_src/sljitTest.c sljit_src/sljitLir.c -o bin/sljit_test -lm -lpthread
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -fshort-wchar -c -o bin/regexMain.o regex_src/regexMain.c
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -fshort-wchar -c -o bin/regexJIT.o regex_src/regexJIT.c
tcc -Isljit_src -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror -c -o bin/sljitLir.o sljit_src/sljitLir.c
tcc -O2 -Wall -Wextra -Wconversion -Wsign-compare -Werror bin/regexMain.o bin/regexJIT.o bin/sljitLir.o -o bin/regex_test -lm -lpthread
fernando@localhost:~/Builds/sljit>
Thank you once again.