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
This commit is contained in:
grischka
2016-12-20 18:05:33 +01:00
parent 4beb469c91
commit 71c5ce5ced
7 changed files with 36 additions and 23 deletions

View File

@@ -14,16 +14,14 @@ ifndef TARGET
else else
TARGET = i386-win32 TARGET = i386-win32
endif endif
# using tcc
else ifeq ($(ARCH),i386) else ifeq ($(ARCH),i386)
TARGET = i386 TARGET = i386
XCC = $(CC) # using gcc
else ifeq ($(ARCH),x86-64) else ifeq ($(ARCH),x86-64)
TARGET = x86_64 TARGET = x86_64
XCC = $(CC) # using gcc
else ifeq ($(ARCH),arm) else ifeq ($(ARCH),arm)
TARGET = arm TARGET = arm
XCC = $(CC) # using gcc # using gcc, need asm
XCC = $(CC)
else ifeq ($(ARCH),arm64) else ifeq ($(ARCH),arm64)
TARGET = arm64 TARGET = arm64
endif endif
@@ -44,22 +42,16 @@ ARM_O = libtcc1.o armeabi.o alloca-arm.o
ARM64_O = lib-arm64.o ARM64_O = lib-arm64.o
WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
# build TCC runtime library to contain PIC code, so it can be linked
# into shared libraries
PICFLAGS = -fPIC
ifeq "$(TARGET)" "i386-win32" ifeq "$(TARGET)" "i386-win32"
OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O)) OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
XAR = $(DIR)/tiny_libmaker$(EXESUF) XAR = $(DIR)/tiny_libmaker$(EXESUF)
XFLAGS = $(TGT)
else ifeq "$(TARGET)" "x86_64-win32" else ifeq "$(TARGET)" "x86_64-win32"
OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O)) OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
XAR = $(DIR)/tiny_libmaker$(EXESUF) XAR = $(DIR)/tiny_libmaker$(EXESUF)
XFLAGS = $(TGT)
else ifeq "$(TARGET)" "i386" else ifeq "$(TARGET)" "i386"
OBJ = $(addprefix $(DIR)/,$(I386_O)) OBJ = $(addprefix $(DIR)/,$(I386_O))
TGT = -DTCC_TARGET_I386 TGT = -DTCC_TARGET_I386
@@ -80,7 +72,10 @@ else
$(error libtcc1.a not supported on target '$(TARGET)') $(error libtcc1.a not supported on target '$(TARGET)')
endif endif
XFLAGS ?= $(CFLAGS) $(PICFLAGS) $(TGT) XFLAGS = $(TGT)
ifeq "$(XCC)" "$(CC)"
XFLAGS += $(CFLAGS)
endif
ifeq ($(TARGETOS),Darwin) ifeq ($(TARGETOS),Darwin)
XAR = $(DIR)/tiny_libmaker$(EXESUF) XAR = $(DIR)/tiny_libmaker$(EXESUF)

View File

@@ -262,7 +262,7 @@ struct mem_debug_header {
int line_num; int line_num;
char file_name[MEM_DEBUG_FILE_LEN + 1]; char file_name[MEM_DEBUG_FILE_LEN + 1];
unsigned magic2; unsigned magic2;
unsigned magic3; __attribute__((aligned(16))) unsigned magic3;
}; };
typedef struct mem_debug_header mem_debug_header_t; typedef struct mem_debug_header mem_debug_header_t;

3
tcc.h
View File

@@ -72,6 +72,9 @@
# pragma warning (disable : 4018) // signed/unsigned mismatch # pragma warning (disable : 4018) // signed/unsigned mismatch
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
# define ssize_t intptr_t # define ssize_t intptr_t
# define __attribute__(x) __declspec x
# define aligned align
# else
# endif # endif
# undef CONFIG_TCC_STATIC # undef CONFIG_TCC_STATIC
#endif #endif

View File

@@ -134,23 +134,23 @@ test4: tcctest.c test.ref
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
dlltest: dlltest:
@echo ------------ $@ ------------ @echo ------------ $@ ------------
$(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL ../libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF) $(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
$(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
ifndef CONFIG_WIN32 ifndef CONFIG_WIN32
@echo ------------ $@ with PIC ------------ @echo ------------ $@ with PIC ------------
$(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c ../libtcc.c $(CC) $(CFLAGS) -fPIC -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF) $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
$(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF) $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
endif endif
@rm tcc2$(EXESUF) libtcc2$(DLLSUF) @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
memtest: memtest:
@echo ------------ $@ ------------ @echo ------------ $@ ------------
$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 ../tcc.c $(LIBS) -o memtest-tcc$(EXESUF) $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE ../tcc.c $(LIBS) ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(TOPSRC)/tcc.c $(LIBS)
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run ../tcc.c $(TCCFLAGS) tcctest.c ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
# memory and bound check auto test # memory and bound check auto test

View File

@@ -15,11 +15,15 @@ int add(int a, int b)
return a + b; return a + b;
} }
/* this strinc is referenced by the generated code */
const char hello[] = "Hello World!"; const char hello[] = "Hello World!";
char my_program[] = char my_program[] =
"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */ "#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */
"extern int add(int a, int b);\n" "extern int add(int a, int b);\n"
"#ifdef _WIN32\n" /* dynamically linked data needs 'dllimport' */
" __attribute__((dllimport))\n"
"#endif\n"
"extern const char hello[];\n" "extern const char hello[];\n"
"int fib(int n)\n" "int fib(int n)\n"
"{\n" "{\n"

View File

@@ -15,15 +15,18 @@ all test : $(sort $(TESTS))
DIFF_OPTS = -Nu -b -B -I "^\#" DIFF_OPTS = -Nu -b -B -I "^\#"
# Filter source directory in warnings/errors (out-of-tree builds)
FILTER = 2>&1 | sed 's,$(SRC)/,,g'
%.test: %.c %.expect %.test: %.c %.expect
@echo PPTest $* ... @echo PPTest $* ...
-@$(TCC) -E -P $< >$*.output 2>&1 ; \ -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
&& rm -f $*.output && rm -f $*.output
%.test: %.S %.expect %.test: %.S %.expect
@echo PPTest $* ... @echo PPTest $* ...
-@$(TCC) -E -P $< >$*.output 2>&1 ; \ -@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \ diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
&& rm -f $*.output && rm -f $*.output

View File

@@ -2667,6 +2667,9 @@ int reltab[3] = { 1, 2, 3 };
int reltab[3] = { 1, 2, 3 }; int reltab[3] = { 1, 2, 3 };
int *rel1 = &reltab[1]; int *rel1 = &reltab[1];
int *rel2 = &reltab[2];
#ifdef _WIN64
void relocation_test(void) {} void relocation_test(void) {}
#else #else
void getmyaddress(void) void getmyaddress(void)
@@ -2695,6 +2698,7 @@ void relocation_test(void)
fptr(); fptr();
#ifdef __LP64__ #ifdef __LP64__
printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63); printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63);
#endif
} }
#endif #endif
@@ -3127,8 +3131,10 @@ void other_constraints_test(void)
void other_constraints_test(void) void other_constraints_test(void)
{ {
unsigned long ret;
int var; int var;
#ifndef _WIN64 #ifndef _WIN64
__asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));
printf ("oc1: %d\n", ret == (unsigned long)&var); printf ("oc1: %d\n", ret == (unsigned long)&var);
#endif #endif
} }
@@ -3203,9 +3209,11 @@ void test_high_clobbers(void)
registers if they are clobbered and if it's the high 8 x86-64 registers if they are clobbered and if it's the high 8 x86-64
registers. This is fragile for GCC as the constraints do not registers. This is fragile for GCC as the constraints do not
correctly capture the data flow, but good enough for us. */ correctly capture the data flow, but good enough for us. */
asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");
clobber_r12(); clobber_r12();
#ifndef _WIN64 #ifndef _WIN64
asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory"); asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");
printf("asmhc: 0x%x\n", val2);
#endif #endif
#endif #endif
} }