tests/Makefile: fix out-of-tree build issues Also: - win64: align(16) MEM_DEBUG user memory on win64 the struct jmp_buf in the TCCState structure which we allocate by tcc_malloc needs alignment 16 because the msvcrt setjmp uses MMX instructions. - libtcc_test.c: win32/64 need __attribute__((dllimport)) for extern data objects - tcctest.c: exclude stuff that gcc does not compile except for relocation_test() the other issues are mostly ASM related. We should probably check GCC versions but I have no idea which mingw/gcc versions support what and which don't. - lib/Makefile: use tcc to compile libtcc1.a (except on arm which needs arm-asm
Unified · Split
| @@ -14,16 +14,14 @@ ifndef TARGET · 13 unmodified lines | ||
| 14 | 14 | else |
| 15 | 15 | TARGET = i386-win32 |
| 16 | 16 | endif |
| 17 | − # using tcc | |
| 18 | 17 | else ifeq ($(ARCH),i386) |
| 19 | 18 | TARGET = i386 |
| 20 | − XCC = $(CC) # using gcc | |
| 21 | 19 | else ifeq ($(ARCH),x86-64) |
| 22 | 20 | TARGET = x86_64 |
| 23 | − XCC = $(CC) # using gcc | |
| 24 | 21 | else ifeq ($(ARCH),arm) |
| 25 | 22 | TARGET = arm |
| 26 | − XCC = $(CC) # using gcc | |
| 23 | + # using gcc, need asm | |
| 24 | + XCC = $(CC) | |
| 27 | 25 | else ifeq ($(ARCH),arm64) |
| 28 | 26 | TARGET = arm64 |
| 29 | 27 | endif |
| @@ -44,22 +42,16 @@ ARM_O = libtcc1.o armeabi.o alloca-arm.o · 14 unmodified lines | ||
| 44 | 42 | ARM64_O = lib-arm64.o |
| 45 | 43 | WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o |
| 46 | 44 | |
| 47 | −# build TCC runtime library to contain PIC code, so it can be linked | |
| 48 | −# into shared libraries | |
| 49 | −PICFLAGS = -fPIC | |
| 50 | − | |
| 51 | 45 | ifeq "$(TARGET)" "i386-win32" |
| 52 | 46 | OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O)) |
| 53 | 47 | TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE |
| 54 | 48 | XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include |
| 55 | 49 | XAR = $(DIR)/tiny_libmaker$(EXESUF) |
| 56 | − XFLAGS = $(TGT) | |
| 57 | 50 | else ifeq "$(TARGET)" "x86_64-win32" |
| 58 | 51 | OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O)) |
| 59 | 52 | TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE |
| 60 | 53 | XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include |
| 61 | 54 | XAR = $(DIR)/tiny_libmaker$(EXESUF) |
| 62 | − XFLAGS = $(TGT) | |
| 63 | 55 | else ifeq "$(TARGET)" "i386" |
| 64 | 56 | OBJ = $(addprefix $(DIR)/,$(I386_O)) |
| 65 | 57 | TGT = -DTCC_TARGET_I386 |
| @@ -80,7 +72,10 @@ else · 14 unmodified lines | ||
| 80 | 72 | $(error libtcc1.a not supported on target '$(TARGET)') |
| 81 | 73 | endif |
| 82 | 74 | |
| 83 | −XFLAGS ?= $(CFLAGS) $(PICFLAGS) $(TGT) | |
| 75 | +XFLAGS = $(TGT) | |
| 76 | +ifeq "$(XCC)" "$(CC)" | |
| 77 | + XFLAGS += $(CFLAGS) | |
| 78 | +endif | |
| 84 | 79 | |
| 85 | 80 | ifeq ($(TARGETOS),Darwin) |
| 86 | 81 | XAR = $(DIR)/tiny_libmaker$(EXESUF) |
| @@ -262,7 +262,7 @@ struct mem_debug_header { · 261 unmodified lines | ||
| 262 | 262 | int line_num; |
| 263 | 263 | char file_name[MEM_DEBUG_FILE_LEN + 1]; |
| 264 | 264 | unsigned magic2; |
| 265 | − unsigned magic3; | |
| 265 | + __attribute__((aligned(16))) unsigned magic3; | |
| 266 | 266 | }; |
| 267 | 267 | |
| 268 | 268 | typedef struct mem_debug_header mem_debug_header_t; |
| @@ -72,6 +72,9 @@ · 71 unmodified lines | ||
| 72 | 72 | # pragma warning (disable : 4018) // signed/unsigned mismatch |
| 73 | 73 | # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned |
| 74 | 74 | # define ssize_t intptr_t |
| 75 | +# define __attribute__(x) __declspec x | |
| 76 | +# define aligned align | |
| 77 | +# else | |
| 75 | 78 | # endif |
| 76 | 79 | # undef CONFIG_TCC_STATIC |
| 77 | 80 | #endif |
| @@ -134,23 +134,23 @@ test4: tcctest.c test.ref · 133 unmodified lines | ||
| 134 | 134 | # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them |
| 135 | 135 | dlltest: |
| 136 | 136 | @echo ------------ $@ ------------ |
| 137 | − $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL ../libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF) | |
| 138 | − $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) | |
| 139 | − ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c | |
| 137 | + $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF) | |
| 138 | + $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) | |
| 139 | + ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c | |
| 140 | 140 | ifndef CONFIG_WIN32 |
| 141 | 141 | @echo ------------ $@ with PIC ------------ |
| 142 | − $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c ../libtcc.c | |
| 142 | + $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c | |
| 143 | 143 | $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF) |
| 144 | − $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) | |
| 145 | − ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c | |
| 144 | + $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) | |
| 145 | + ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c | |
| 146 | 146 | endif |
| 147 | 147 | @rm tcc2$(EXESUF) libtcc2$(DLLSUF) |
| 148 | 148 | |
| 149 | 149 | memtest: |
| 150 | 150 | @echo ------------ $@ ------------ |
| 151 | − $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 ../tcc.c $(LIBS) -o memtest-tcc$(EXESUF) | |
| 152 | − ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE ../tcc.c $(LIBS) | |
| 153 | − ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run ../tcc.c $(TCCFLAGS) tcctest.c | |
| 151 | + $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF) | |
| 152 | + ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(TOPSRC)/tcc.c $(LIBS) | |
| 153 | + ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c | |
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | # memory and bound check auto test |
| @@ -15,11 +15,15 @@ int add(int a, int b) · 14 unmodified lines | ||
| 15 | 15 | return a + b; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | +/* this strinc is referenced by the generated code */ | |
| 18 | 19 | const char hello[] = "Hello World!"; |
| 19 | 20 | |
| 20 | 21 | char my_program[] = |
| 21 | 22 | "#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */ |
| 22 | 23 | "extern int add(int a, int b);\n" |
| 24 | +"#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */ | |
| 25 | +" __attribute__((dllimport))\n" | |
| 26 | +"#endif\n" | |
| 23 | 27 | "extern const char hello[];\n" |
| 24 | 28 | "int fib(int n)\n" |
| 25 | 29 | "{\n" |
| @@ -15,15 +15,18 @@ all test : $(sort $(TESTS)) · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | DIFF_OPTS = -Nu -b -B -I "^\#" |
| 17 | 17 | |
| 18 | +# Filter source directory in warnings/errors (out-of-tree builds) | |
| 19 | +FILTER = 2>&1 | sed 's,$(SRC)/,,g' | |
| 20 | + | |
| 18 | 21 | %.test: %.c %.expect |
| 19 | 22 | @echo PPTest $* ... |
| 20 | − -@$(TCC) -E -P $< >$*.output 2>&1 ; \ | |
| 23 | + -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ | |
| 21 | 24 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ |
| 22 | 25 | && rm -f $*.output |
| 23 | 26 | |
| 24 | 27 | %.test: %.S %.expect |
| 25 | 28 | @echo PPTest $* ... |
| 26 | − -@$(TCC) -E -P $< >$*.output 2>&1 ; \ | |
| 29 | + -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \ | |
| 27 | 30 | diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ |
| 28 | 31 | && rm -f $*.output |
| 29 | 32 | |
| @@ -2667,6 +2667,9 @@ int reltab[3] = { 1, 2, 3 }; · 2666 unmodified lines | ||
| 2667 | 2667 | int *rel1 = &reltab[1]; |
| 2668 | 2668 | int *rel2 = &reltab[2]; |
| 2669 | 2669 | |
| 2670 | +#ifdef _WIN64 | |
| 2671 | +void relocation_test(void) {} | |
| 2672 | +#else | |
| 2670 | 2673 | void getmyaddress(void) |
| 2671 | 2674 | { |
| 2672 | 2675 | printf("in getmyaddress\n"); |
| @@ -2695,6 +2698,7 @@ void relocation_test(void) · 22 unmodified lines | ||
| 2695 | 2698 | printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63); |
| 2696 | 2699 | #endif |
| 2697 | 2700 | } |
| 2701 | +#endif | |
| 2698 | 2702 | |
| 2699 | 2703 | void old_style_f(a,b,c) |
| 2700 | 2704 | int a, b; |
| @@ -3127,8 +3131,10 @@ void other_constraints_test(void) · 426 unmodified lines | ||
| 3127 | 3131 | { |
| 3128 | 3132 | unsigned long ret; |
| 3129 | 3133 | int var; |
| 3134 | +#ifndef _WIN64 | |
| 3130 | 3135 | __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var)); |
| 3131 | 3136 | printf ("oc1: %d\n", ret == (unsigned long)&var); |
| 3137 | +#endif | |
| 3132 | 3138 | } |
| 3133 | 3139 | |
| 3134 | 3140 | #ifndef _WIN32 |
| @@ -3203,9 +3209,11 @@ void test_high_clobbers(void) · 68 unmodified lines | ||
| 3203 | 3209 | correctly capture the data flow, but good enough for us. */ |
| 3204 | 3210 | asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory"); |
| 3205 | 3211 | clobber_r12(); |
| 3212 | +#ifndef _WIN64 | |
| 3206 | 3213 | asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory"); |
| 3207 | 3214 | printf("asmhc: 0x%x\n", val2); |
| 3208 | 3215 | #endif |
| 3216 | +#endif | |
| 3209 | 3217 | } |
| 3210 | 3218 | |
| 3211 | 3219 | static long cpu_number; |