History

tests: OOT build fixes etc.

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

grischka committed 9 years ago

Commit 71c5ce51 parent 4beb4697 files · +36 −23Browse files

Unified · Split

7 files
  1. lib/Makefile +6 −11
  2. libtcc.c +1 −1
  3. tcc.h +3 −0
  4. tests/Makefile +9 −9
  5. tests/libtcc_test.c +4 −0
  6. tests/pp/Makefile +5 −2
  7. tests/tcctest.c +8 −0
lib/Makefile+6−11
@@ -14,16 +14,14 @@ ifndef TARGET · 13 unmodified lines
14 else14 else
15 TARGET = i386-win3215 TARGET = i386-win32
16 endif16 endif
17 # using tcc
18 else ifeq ($(ARCH),i386)17 else ifeq ($(ARCH),i386)
19 TARGET = i38618 TARGET = i386
20 XCC = $(CC) # using gcc
21 else ifeq ($(ARCH),x86-64)19 else ifeq ($(ARCH),x86-64)
22 TARGET = x86_6420 TARGET = x86_64
23 XCC = $(CC) # using gcc
24 else ifeq ($(ARCH),arm)21 else ifeq ($(ARCH),arm)
25 TARGET = arm22 TARGET = arm
26 XCC = $(CC) # using gcc23 # using gcc, need asm
24 XCC = $(CC)
27 else ifeq ($(ARCH),arm64)25 else ifeq ($(ARCH),arm64)
28 TARGET = arm6426 TARGET = arm64
29 endif27 endif
@@ -44,22 +42,16 @@ ARM_O = libtcc1.o armeabi.o alloca-arm.o · 14 unmodified lines
44ARM64_O = lib-arm64.o42ARM64_O = lib-arm64.o
45WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o43WIN32_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
49PICFLAGS = -fPIC
50
51ifeq "$(TARGET)" "i386-win32"45ifeq "$(TARGET)" "i386-win32"
52 OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))46 OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
53 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE47 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
54 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include48 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
55 XAR = $(DIR)/tiny_libmaker$(EXESUF)49 XAR = $(DIR)/tiny_libmaker$(EXESUF)
56 XFLAGS = $(TGT)
57else ifeq "$(TARGET)" "x86_64-win32"50else ifeq "$(TARGET)" "x86_64-win32"
58 OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))51 OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
59 TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE52 TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
60 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include53 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
61 XAR = $(DIR)/tiny_libmaker$(EXESUF)54 XAR = $(DIR)/tiny_libmaker$(EXESUF)
62 XFLAGS = $(TGT)
63else ifeq "$(TARGET)" "i386"55else ifeq "$(TARGET)" "i386"
64 OBJ = $(addprefix $(DIR)/,$(I386_O))56 OBJ = $(addprefix $(DIR)/,$(I386_O))
65 TGT = -DTCC_TARGET_I38657 TGT = -DTCC_TARGET_I386
@@ -80,7 +72,10 @@ else · 14 unmodified lines
80 $(error libtcc1.a not supported on target '$(TARGET)')72 $(error libtcc1.a not supported on target '$(TARGET)')
81endif73endif
82 74
83XFLAGS ?= $(CFLAGS) $(PICFLAGS) $(TGT)75XFLAGS = $(TGT)
76ifeq "$(XCC)" "$(CC)"
77 XFLAGS += $(CFLAGS)
78endif
84 79
85ifeq ($(TARGETOS),Darwin)80ifeq ($(TARGETOS),Darwin)
86 XAR = $(DIR)/tiny_libmaker$(EXESUF)81 XAR = $(DIR)/tiny_libmaker$(EXESUF)
libtcc.c+1−1
@@ -262,7 +262,7 @@ struct mem_debug_header { · 261 unmodified lines
262 int line_num;262 int line_num;
263 char file_name[MEM_DEBUG_FILE_LEN + 1];263 char file_name[MEM_DEBUG_FILE_LEN + 1];
264 unsigned magic2;264 unsigned magic2;
265 unsigned magic3;265 __attribute__((aligned(16))) unsigned magic3;
266};266};
267 267
268typedef struct mem_debug_header mem_debug_header_t;268typedef struct mem_debug_header mem_debug_header_t;
tcc.h+3−0
@@ -72,6 +72,9 @@ · 71 unmodified lines
72# pragma warning (disable : 4018) // signed/unsigned mismatch72# pragma warning (disable : 4018) // signed/unsigned mismatch
73# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned73# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
74# define ssize_t intptr_t74# define ssize_t intptr_t
75# define __attribute__(x) __declspec x
76# define aligned align
77# else
75# endif78# endif
76# undef CONFIG_TCC_STATIC79# undef CONFIG_TCC_STATIC
77#endif80#endif
tests/Makefile+9−9
@@ -134,23 +134,23 @@ test4: tcctest.c test.ref · 133 unmodified lines
134# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them134# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
135dlltest:135dlltest:
136 @echo ------------ $@ ------------136 @echo ------------ $@ ------------
137 $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL ../libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)137 $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
138 $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)138 $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
139 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c139 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
140ifndef CONFIG_WIN32140ifndef CONFIG_WIN32
141 @echo ------------ $@ with PIC ------------141 @echo ------------ $@ with PIC ------------
142 $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c ../libtcc.c142 $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
143 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)143 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
144 $(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)144 $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
145 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c145 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
146endif146endif
147 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)147 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
148 148
149memtest:149memtest:
150 @echo ------------ $@ ------------150 @echo ------------ $@ ------------
151 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 ../tcc.c $(LIBS) -o memtest-tcc$(EXESUF)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 ../tcc.c $(LIBS)152 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(TOPSRC)/tcc.c $(LIBS)
153 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run ../tcc.c $(TCCFLAGS) tcctest.c153 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
154 154
155 155
156# memory and bound check auto test156# memory and bound check auto test
tests/libtcc_test.c+4−0
@@ -15,11 +15,15 @@ int add(int a, int b) · 14 unmodified lines
15 return a + b;15 return a + b;
16}16}
17 17
18/* this strinc is referenced by the generated code */
18const char hello[] = "Hello World!";19const char hello[] = "Hello World!";
19 20
20char my_program[] =21char my_program[] =
21"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */22"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */
22"extern int add(int a, int b);\n"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"extern const char hello[];\n"27"extern const char hello[];\n"
24"int fib(int n)\n"28"int fib(int n)\n"
25"{\n"29"{\n"
tests/pp/Makefile+5−2
@@ -15,15 +15,18 @@ all test : $(sort $(TESTS)) · 14 unmodified lines
15 15
16DIFF_OPTS = -Nu -b -B -I "^\#"16DIFF_OPTS = -Nu -b -B -I "^\#"
17 17
18# Filter source directory in warnings/errors (out-of-tree builds)
19FILTER = 2>&1 | sed 's,$(SRC)/,,g'
20
18%.test: %.c %.expect21%.test: %.c %.expect
19 @echo PPTest $* ...22 @echo PPTest $* ...
20 -@$(TCC) -E -P $< >$*.output 2>&1 ; \23 -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
21 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \24 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
22 && rm -f $*.output25 && rm -f $*.output
23 26
24%.test: %.S %.expect27%.test: %.S %.expect
25 @echo PPTest $* ...28 @echo PPTest $* ...
26 -@$(TCC) -E -P $< >$*.output 2>&1 ; \29 -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
27 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \30 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
28 && rm -f $*.output31 && rm -f $*.output
29 32
tests/tcctest.c+8−0
@@ -2667,6 +2667,9 @@ int reltab[3] = { 1, 2, 3 }; · 2666 unmodified lines
2667int *rel1 = &reltab[1];2667int *rel1 = &reltab[1];
2668int *rel2 = &reltab[2];2668int *rel2 = &reltab[2];
2669 2669
2670#ifdef _WIN64
2671void relocation_test(void) {}
2672#else
2670void getmyaddress(void)2673void getmyaddress(void)
2671{2674{
2672 printf("in getmyaddress\n");2675 printf("in getmyaddress\n");
@@ -2695,6 +2698,7 @@ void relocation_test(void) · 22 unmodified lines
2695 printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63);2698 printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63);
2696#endif2699#endif
2697}2700}
2701#endif
2698 2702
2699void old_style_f(a,b,c)2703void old_style_f(a,b,c)
2700 int a, b;2704 int a, b;
@@ -3127,8 +3131,10 @@ void other_constraints_test(void) · 426 unmodified lines
3127{3131{
3128 unsigned long ret;3132 unsigned long ret;
3129 int var;3133 int var;
3134#ifndef _WIN64
3130 __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));3135 __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));
3131 printf ("oc1: %d\n", ret == (unsigned long)&var);3136 printf ("oc1: %d\n", ret == (unsigned long)&var);
3137#endif
3132}3138}
3133 3139
3134#ifndef _WIN323140#ifndef _WIN32
@@ -3203,9 +3209,11 @@ void test_high_clobbers(void) · 68 unmodified lines
3203 correctly capture the data flow, but good enough for us. */3209 correctly capture the data flow, but good enough for us. */
3204 asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");3210 asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");
3205 clobber_r12();3211 clobber_r12();
3212#ifndef _WIN64
3206 asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");3213 asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");
3207 printf("asmhc: 0x%x\n", val2);3214 printf("asmhc: 0x%x\n", val2);
3208#endif3215#endif
3216#endif
3209}3217}
3210 3218
3211static long cpu_number;3219static long cpu_number;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t