tinycc/tests/Makefile

321 lines
9.4 KiB
Makefile
Raw Normal View History

2009-04-18 20:31:35 +08:00
#
# Tiny C Compiler Makefile - tests
#
TOP = ..
include $(TOP)/Makefile
2016-10-02 03:06:53 +08:00
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
2009-04-18 20:31:35 +08:00
# what tests to run
TESTS = \
hello-exe \
hello-run \
libtest \
libtest_mt \
test3 \
memtest \
dlltest \
abitest \
asm-c-connect-test \
vla_test-run \
cross-test \
tests2-dir \
pp-dir
BTESTS = btest test1b
# test4_static -- Not all relocation types are implemented yet.
# asmtest / asmtest2 -- minor differences with gcc
2009-04-18 20:31:35 +08:00
# bounds-checking is supported on i386 and x86_64 on linux and windows
ifeq (-$(CONFIG_musl)-, --)
ifeq ($(ARCH),i386)
TESTS += $(BTESTS)
endif
ifeq ($(ARCH),x86_64)
TESTS += $(BTESTS)
endif
Add bound checking to arm, arm64 and riscv64 Checked on: - i386/x86_64 (linux/windows) - arm/arm64 (rapberry pi) - riscv64 (simulator) Not tested for arm softfloat because raspberry pi does not support it. Modifications: Makefile: add arm-asm.c to arm64_FILES add riscv64-asm.c (new file) to riscv64_FILES lib/Makefile: add fetch_and_add_arm.o(new file) to ARM_O add fetch_and_add_arm64.o(new file) to ARM64_O add fetch_and_add_riscv64.o(new file) to RISCV64_O add $(BCHECK_O) to OBJ-arm/OBJ-arm64/OBJ-riscv64 tcc.h: Enable CONFIG_TCC_BCHECK for arm32/arm64/riscv64 Add arm-asm.c, riscv64-asm.c tcctok.h: for arm use memmove4 instead of memcpy4 for arm use memmove8 instead of memcpy8 tccgen.c: put_extern_sym2: for arm check memcpy/memmove/memset/memmove4/memmove8 only use alloca for i386/x86_64 for arm use memmove4 instead of memcpy4 for arm use memmove8 instead of memcpy8 fix builtin_frame_address/builtin_return_address for arm/riscv64 tccrun.c: Add riscv64 support fix rt_getcontext/rt_get_caller_pc for arm tccelf.c: tcc_load_dll: Print filename for bad architecture libtcc.c: add arm-asm.c/riscv64-asm.c tcc-doc.texi: Add arm, arm64, riscv64 support for bound checking lib/bcheck.c: add __bound___aeabi_memcpy/__bound___aeabi_memmove __bound___aeabi_memmove4/__bound___aeabi_memmove8 __bound___aeabi_memset for arm call fetch_and_add_arm/fetch_and_add_arm64/fetch_and_add_riscv64 __bound_init: Fix type for start/end/ad __bound_malloc/__bound_memalign/__bound_realloc/__bound_calloc: Use size + 1 arm-gen.c: add bound checking code like i386/x86_64 assign_regs: only malloc if nb_args != 0 gen_opi/gen_opf: Fix reload problems arm-link.c: relocate_plt: Fix address calculating arm64-gen.c: add bound checking code like i386/x86_64 load/store: remove VT_BOUNDED from sv->r arm64_hfa_aux/arm64_hfa_aux: Fix array code gfunc_prolog: only malloc if n != 0 arm64-link.c: code_reloc/gotplt_entry_type/relocate: add R_AARCH64_LDST64_ABS_LO12_NC relocate: Use addXXle instead of writeXXle riscv64-gen.c: add bound checking code like i386/x86_64 add NB_ASM_REGS/CONFIG_TCC_ASM riscv64-link.c: relocate: Use addXXle instead of writeXXle i386-gen.c/x86_64-gen.c gen_bounds_epilog: Fix code (unrelated) tests/Makefile: add $(BTESTS) for arm/arm64/riscv64 tests/tests2/Makefile: Use 85 only on i386/x86_64 because of asm code Use 113 only on i386/x86_64 because of DLL code Add 112/114/115/116 for arm/arm64/riscv64 Fix FILTER (failed on riscv64) tests/boundtest.c: Only use alloca for i386/x86_64
2020-06-16 13:39:48 +08:00
ifeq ($(ARCH),arm)
TESTS += $(BTESTS)
endif
ifeq ($(ARCH),arm64)
TESTS += $(BTESTS)
endif
ifeq ($(ARCH),riscv64)
TESTS += $(BTESTS)
endif
endif
ifdef CONFIG_OSX # some don't work yet
TESTS := $(filter-out dlltest, $(TESTS))
endif
ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
TESTS := $(filter-out vla_test-run,$(TESTS))
endif
ifeq ($(CONFIG_arm_eabi),yes)
TESTS := $(filter-out test3,$(TESTS))
endif
ifeq (,$(filter i386 x86_64,$(ARCH)))
TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
endif
2009-04-18 20:31:35 +08:00
ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH)
endif
ifdef CONFIG_OSX
LIBS += $(LINK_LIBTCC)
endif
ifeq ($(ARCH),arm)
# tcctest refers to the alignment of functions, and with thumb mode
# the low bit of code addresses selects the mode, so the "alignment"
# of functions via bit masking comes out as 1. Just disable thumb.
test.ref: CFLAGS+=-marm
endif
ifeq ($(ARCH),i386)
# tcctest.c:get_asm_string uses a construct that is checked too strictly
# by GCC in 32bit mode when PIC is enabled.
test.ref: CFLAGS+=-fno-PIC -fno-PIE
endif
ifeq ($(CC_NAME),msvc)
test.ref abitest : CC = gcc
endif
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
DISAS = objdump -d
ifdef CONFIG_OSX
DUMPTCC = (set -x; $(TOP)/tcc -vv; otool -L $(TOP)/tcc; exit 1)
else
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
endif
all test :
@$(MAKE) --no-print-directory -s clean
@$(MAKE) --no-print-directory -s -r $(TESTS)
hello-exe: ../examples/ex1.c
@echo ------------ $@ ------------
$(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
hello-run: ../examples/ex1.c
@echo ------------ $@ ------------
$(TCC) -run $< || $(DUMPTCC)
libtes%: libtcc_tes%$(EXESUF)
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
2020-01-18 05:58:39 +08:00
./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES)
2009-04-18 20:31:35 +08:00
libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
libtcc_test_mt$(EXESUF): libtcc_test_mt.c $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
2009-04-18 20:31:35 +08:00
%-dir:
@echo ------------ $@ ------------
$(MAKE) -k -C $*
2014-03-09 22:54:48 +08:00
# test.ref - generate using cc
2009-04-18 20:31:35 +08:00
test.ref: tcctest.c
$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
./tcctest.gcc > $@
2009-04-18 20:31:35 +08:00
# auto test
test1 test1b: tcctest.c test.ref
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) -w -run $< > test.out1
2020-01-18 05:58:39 +08:00
@diff -u test.ref test.out1 && echo "$(AUTO_TEST) OK"
2009-04-18 20:31:35 +08:00
# iterated test2 (compile tcc then compile tcctest.c !)
test2 test2b: tcctest.c test.ref
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out2
2020-01-18 05:58:39 +08:00
@diff -u test.ref test.out2 && echo "$(AUTO_TEST)2 OK"
2009-04-18 20:31:35 +08:00
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
test3 test3b: tcctest.c test.ref
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -w -run $< > test.out3
2020-01-18 05:58:39 +08:00
@diff -u test.ref test.out3 && echo "$(AUTO_TEST)3 OK"
2020-01-18 05:58:39 +08:00
AUTO_TEST = Auto Test
test%b : TCCFLAGS += -b -bt1
test%b : AUTO_TEST = Auto Bound-Test
2009-04-18 20:31:35 +08:00
# binary output test
test4: tcctest.c test.ref
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
# object + link output
$(TCC) -c -o tcctest3.o $<
2009-04-18 20:31:35 +08:00
$(TCC) -o tcctest3 tcctest3.o
./tcctest3 > test3.out
2020-01-18 05:58:39 +08:00
@if diff -u test.ref test3.out ; then echo "Object $(AUTO_TEST) OK"; fi
# dynamic output
$(TCC) -o tcctest1 $<
./tcctest1 > test1.out
2020-01-18 05:58:39 +08:00
@if diff -u test.ref test1.out ; then echo "Dynamic $(AUTO_TEST) OK"; fi
2009-04-18 20:31:35 +08:00
# dynamic output + bound check
bcheck cleanup - revert Makefiles to state before last bcheck additions Instead, just load bcheck.o explicitly if that is what is wanted. - move tcc_add_bcheck() to the <target>-link.c files and remove revently added arguments. This function is to support tccelf.c with linking, not for tccgen.c to support compilation. - remove -ba option: It said: "-ba Enable better address checking with bounds checker" Okay, if it is better then to have it is not an option. - remove va_copy. It is C99 and we try to stay C89 in tinycc when possible. For example, MS compilers do not have va_copy. - win64: revert any 'fixes' to alloca It was correct as it was before, except for bound_checking where it was not implemented. This should now work too. - remove parasitic filename:linenum features Such feature is already present with rt_printline in tccrun.c. If it doesn't work it can be fixed. - revert changes to gen_bounded_ptr_add() gen_bounded_ptr_add() was working as it should before (mostly). For the sake of simplicity I switched it to CDECL. Anyway, FASTCALL means SLOWCALL with tinycc. In exchange you get one addition which is required for bounds_cnecking function arguments. The important thing is to check them *BEFORE* they are loaded into registers. New function gbound_args() does that. In any case, code instrumentation with the bounds-check functions as such now seems to work flawlessly again, which means when they are inserted as NOPs, any code that tcc can compile, seems to behave just the same as without them. What these functions then do when fully enabled, is a differnt story. I did not touch this.
2019-12-12 22:45:45 +08:00
$(TCC) -b -o tcctest4 $<
2009-04-18 20:31:35 +08:00
./tcctest4 > test4.out
2020-01-18 05:58:39 +08:00
@if diff -u test.ref test4.out ; then echo "BCheck $(AUTO_TEST) OK"; fi
test4_static: tcctest.c test.ref
@echo ------------ $@ ------------
# static output.
$(TCC) -static -o tcctest2 $<
./tcctest2 > test2.out
2020-01-18 05:58:39 +08:00
@if diff -u test.ref test2.out ; then echo "Static $(AUTO_TEST) OK"; fi
2009-04-18 20:31:35 +08:00
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
dlltest:
@echo ------------ $@ ------------
$(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
ifndef CONFIG_WIN32
@echo ------------ $@ with PIC ------------
$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
endif
@rm tcc2$(EXESUF) libtcc2$(DLLSUF)
memtest:
@echo ------------ $@ ------------
$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
2020-01-18 05:58:39 +08:00
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
@echo OK
2009-04-18 20:31:35 +08:00
# memory and bound check auto test
2020-01-18 05:58:39 +08:00
BOUNDS_OK = 1 4 8 10 14 16
BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17 18
2009-04-18 20:31:35 +08:00
btest: boundtest.c
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
bcheck cleanup - revert Makefiles to state before last bcheck additions Instead, just load bcheck.o explicitly if that is what is wanted. - move tcc_add_bcheck() to the <target>-link.c files and remove revently added arguments. This function is to support tccelf.c with linking, not for tccgen.c to support compilation. - remove -ba option: It said: "-ba Enable better address checking with bounds checker" Okay, if it is better then to have it is not an option. - remove va_copy. It is C99 and we try to stay C89 in tinycc when possible. For example, MS compilers do not have va_copy. - win64: revert any 'fixes' to alloca It was correct as it was before, except for bound_checking where it was not implemented. This should now work too. - remove parasitic filename:linenum features Such feature is already present with rt_printline in tccrun.c. If it doesn't work it can be fixed. - revert changes to gen_bounded_ptr_add() gen_bounded_ptr_add() was working as it should before (mostly). For the sake of simplicity I switched it to CDECL. Anyway, FASTCALL means SLOWCALL with tinycc. In exchange you get one addition which is required for bounds_cnecking function arguments. The important thing is to check them *BEFORE* they are loaded into registers. New function gbound_args() does that. In any case, code instrumentation with the bounds-check functions as such now seems to work flawlessly again, which means when they are inserted as NOPs, any code that tcc can compile, seems to behave just the same as without them. What these functions then do when fully enabled, is a differnt story. I did not touch this.
2019-12-12 22:45:45 +08:00
@for i in $(BOUNDS_OK); do \
if $(TCC) -b -run $< $$i >/dev/null 2>&1 ; then \
echo "Test $$i succeeded as expected" ; \
2009-04-18 20:31:35 +08:00
else\
echo "Failed positive test $$i" ; exit 1 ; \
2009-04-18 20:31:35 +08:00
fi ;\
done ;\
for i in $(BOUNDS_FAIL); do \
if $(TCC) -b -bt1 -run $< $$i >/dev/null 2>&1 ; then \
echo "Failed negative test $$i" ; exit 1 ;\
2009-04-18 20:31:35 +08:00
else\
echo "Test $$i failed as expected" ; \
2009-04-18 20:31:35 +08:00
fi ;\
done ;\
2020-01-18 05:58:39 +08:00
echo Bound test OK
2009-04-18 20:31:35 +08:00
# speed test
speedtest: ex2 ex3
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
time ./ex2 1238 2 3 4 10 13 4
2016-10-02 03:06:53 +08:00
time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
2009-04-18 20:31:35 +08:00
time ./ex3 35
2016-10-02 03:06:53 +08:00
time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
2009-04-18 20:31:35 +08:00
weaktest: tcctest.c test.ref
@echo ------------ $@ ------------
$(TCC) -c $< -o weaktest.tcc.o
$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
2016-10-02 03:06:53 +08:00
ex%: $(TOPSRC)/examples/ex%.c
$(CC) -o $@ $< $(CFLAGS)
2009-04-18 20:31:35 +08:00
# tiny assembler testing
asmtest.ref: asmtest.S
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
objdump -D asmtest.ref.o > asmtest.ref
2009-04-18 20:31:35 +08:00
asmtest asmtest2: asmtest.ref
2009-04-18 20:31:35 +08:00
@echo ------------ $@ ------------
$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
objdump -D asmtest.o > asmtest.out
2009-04-18 20:31:35 +08:00
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
# test assembler with tcc compiled by itself
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
# Check that code generated by libtcc is binary compatible with
# that generated by CC
abitest-cc.exe: abitest.c $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
abitest-tcc.exe: abitest.c libtcc.c
$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
abitest-% : abitest-%.exe
@echo ------------ $@ ------------
./$< $(TCCFLAGS)
abitest: abitest-cc
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
abitest: abitest-tcc
endif
vla_test$(EXESUF): vla_test.c
$(TCC) -o $@ $^
vla_test-run: vla_test$(EXESUF)
@echo ------------ $@ ------------
./vla_test$(EXESUF)
asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
$(TCC) -o $@ $^
asm-c-connect-%.o: asm-c-connect-%.c
$(TCC) -c -o $@ $<
asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
$(TCC) -o $@ $^
asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
@echo ------------ $@ ------------
./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
@diff -u asm-c-connect.out1 asm-c-connect.out2 || (echo "error"; exit 1)
TCC_YY = $(foreach T,$(TCC_X),$(if $(wildcard $(TOP)/$T-tcc$(EXESUF)),$T))
cross-test :
$(if $(strip $(TCC_YY)),\
$(MAKE) $(foreach T,$(TCC_YY),cross-$T.test) --no-print-directory,:)
cross-%.test :
@echo ------------ $@ ------------
$(TOP)/$*-tcc$(EXESUF) -v $(TCCFLAGS-$(if $(findstring win,$*),win,unx))\
-c $(TOPSRC)/examples/ex3.c
2009-04-18 20:31:35 +08:00
# targets for development
%.bin: %.c tcc
$(TCC) -g -o $@ $<
$(DISAS) $@
instr: instr.o
objdump -d instr.o
instr.o: instr.S
$(CC) -o $@ -c $< -O2 -Wall -g
cache: tcc_g
cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
vg_annotate tcc.c > /tmp/linpack.cache.log
# clean
clean:
rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt
@$(MAKE) -C tests2 $@
@$(MAKE) -C pp $@