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
1414 else
1515 TARGET = i386-win32
1616 endif
17− # using tcc
1817 else ifeq ($(ARCH),i386)
1918 TARGET = i386
20− XCC = $(CC) # using gcc
2119 else ifeq ($(ARCH),x86-64)
2220 TARGET = x86_64
23− XCC = $(CC) # using gcc
2421 else ifeq ($(ARCH),arm)
2522 TARGET = arm
26− XCC = $(CC) # using gcc
23+ # using gcc, need asm
24+ XCC = $(CC)
2725 else ifeq ($(ARCH),arm64)
2826 TARGET = arm64
2927 endif
@@ -44,22 +42,16 @@ ARM_O = libtcc1.o armeabi.o alloca-arm.o · 14 unmodified lines
4442 ARM64_O = lib-arm64.o
4543 WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
4644
47−# build TCC runtime library to contain PIC code, so it can be linked
48−# into shared libraries
49−PICFLAGS = -fPIC
50−
5145 ifeq "$(TARGET)" "i386-win32"
5246 OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
5347 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
5448 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
5549 XAR = $(DIR)/tiny_libmaker$(EXESUF)
56− XFLAGS = $(TGT)
5750 else ifeq "$(TARGET)" "x86_64-win32"
5851 OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
5952 TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
6053 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
6154 XAR = $(DIR)/tiny_libmaker$(EXESUF)
62− XFLAGS = $(TGT)
6355 else ifeq "$(TARGET)" "i386"
6456 OBJ = $(addprefix $(DIR)/,$(I386_O))
6557 TGT = -DTCC_TARGET_I386
@@ -80,7 +72,10 @@ else · 14 unmodified lines
8072 $(error libtcc1.a not supported on target '$(TARGET)')
8173 endif
8274
83−XFLAGS ?= $(CFLAGS) $(PICFLAGS) $(TGT)
75+XFLAGS = $(TGT)
76+ifeq "$(XCC)" "$(CC)"
77+ XFLAGS += $(CFLAGS)
78+endif
8479
8580 ifeq ($(TARGETOS),Darwin)
8681 XAR = $(DIR)/tiny_libmaker$(EXESUF)
libtcc.c+1−1
@@ -262,7 +262,7 @@ struct mem_debug_header { · 261 unmodified lines
262262 int line_num;
263263 char file_name[MEM_DEBUG_FILE_LEN + 1];
264264 unsigned magic2;
265− unsigned magic3;
265+ __attribute__((aligned(16))) unsigned magic3;
266266 };
267267
268268 typedef struct mem_debug_header mem_debug_header_t;
tcc.h+3−0
@@ -72,6 +72,9 @@ · 71 unmodified lines
7272 # pragma warning (disable : 4018) // signed/unsigned mismatch
7373 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
7474 # define ssize_t intptr_t
75+# define __attribute__(x) __declspec x
76+# define aligned align
77+# else
7578 # endif
7679 # undef CONFIG_TCC_STATIC
7780 #endif
tests/Makefile+9−9
@@ -134,23 +134,23 @@ test4: tcctest.c test.ref · 133 unmodified lines
134134 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
135135 dlltest:
136136 @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
140140 ifndef CONFIG_WIN32
141141 @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
143143 $(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
146146 endif
147147 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
148148
149149 memtest:
150150 @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
154154
155155
156156 # 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
1515 return a + b;
1616 }
1717
18+/* this strinc is referenced by the generated code */
1819 const char hello[] = "Hello World!";
1920
2021 char my_program[] =
2122 "#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */
2223 "extern int add(int a, int b);\n"
24+"#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */
25+" __attribute__((dllimport))\n"
26+"#endif\n"
2327 "extern const char hello[];\n"
2428 "int fib(int n)\n"
2529 "{\n"
tests/pp/Makefile+5−2
@@ -15,15 +15,18 @@ all test : $(sort $(TESTS)) · 14 unmodified lines
1515
1616 DIFF_OPTS = -Nu -b -B -I "^\#"
1717
18+# Filter source directory in warnings/errors (out-of-tree builds)
19+FILTER = 2>&1 | sed 's,$(SRC)/,,g'
20+
1821 %.test: %.c %.expect
1922 @echo PPTest $* ...
20− -@$(TCC) -E -P $< >$*.output 2>&1 ; \
23+ -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
2124 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
2225 && rm -f $*.output
2326
2427 %.test: %.S %.expect
2528 @echo PPTest $* ...
26− -@$(TCC) -E -P $< >$*.output 2>&1 ; \
29+ -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
2730 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
2831 && rm -f $*.output
2932
tests/tcctest.c+8−0
@@ -2667,6 +2667,9 @@ int reltab[3] = { 1, 2, 3 }; · 2666 unmodified lines
26672667 int *rel1 = &reltab[1];
26682668 int *rel2 = &reltab[2];
26692669
2670+#ifdef _WIN64
2671+void relocation_test(void) {}
2672+#else
26702673 void getmyaddress(void)
26712674 {
26722675 printf("in getmyaddress\n");
@@ -2695,6 +2698,7 @@ void relocation_test(void) · 22 unmodified lines
26952698 printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63);
26962699 #endif
26972700 }
2701+#endif
26982702
26992703 void old_style_f(a,b,c)
27002704 int a, b;
@@ -3127,8 +3131,10 @@ void other_constraints_test(void) · 426 unmodified lines
31273131 {
31283132 unsigned long ret;
31293133 int var;
3134+#ifndef _WIN64
31303135 __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));
31313136 printf ("oc1: %d\n", ret == (unsigned long)&var);
3137+#endif
31323138 }
31333139
31343140 #ifndef _WIN32
@@ -3203,9 +3209,11 @@ void test_high_clobbers(void) · 68 unmodified lines
32033209 correctly capture the data flow, but good enough for us. */
32043210 asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");
32053211 clobber_r12();
3212+#ifndef _WIN64
32063213 asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");
32073214 printf("asmhc: 0x%x\n", val2);
32083215 #endif
3216+#endif
32093217 }
32103218
32113219 static 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