mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
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:
parent
4beb469c91
commit
71c5ce5ced
17
lib/Makefile
17
lib/Makefile
@ -14,16 +14,14 @@ ifndef TARGET
|
||||
else
|
||||
TARGET = i386-win32
|
||||
endif
|
||||
# using tcc
|
||||
else ifeq ($(ARCH),i386)
|
||||
TARGET = i386
|
||||
XCC = $(CC) # using gcc
|
||||
else ifeq ($(ARCH),x86-64)
|
||||
TARGET = x86_64
|
||||
XCC = $(CC) # using gcc
|
||||
else ifeq ($(ARCH),arm)
|
||||
TARGET = arm
|
||||
XCC = $(CC) # using gcc
|
||||
# using gcc, need asm
|
||||
XCC = $(CC)
|
||||
else ifeq ($(ARCH),arm64)
|
||||
TARGET = arm64
|
||||
endif
|
||||
@ -44,22 +42,16 @@ ARM_O = libtcc1.o armeabi.o alloca-arm.o
|
||||
ARM64_O = lib-arm64.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"
|
||||
OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
|
||||
TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
|
||||
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
|
||||
XAR = $(DIR)/tiny_libmaker$(EXESUF)
|
||||
XFLAGS = $(TGT)
|
||||
else ifeq "$(TARGET)" "x86_64-win32"
|
||||
OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
|
||||
TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
|
||||
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
|
||||
XAR = $(DIR)/tiny_libmaker$(EXESUF)
|
||||
XFLAGS = $(TGT)
|
||||
else ifeq "$(TARGET)" "i386"
|
||||
OBJ = $(addprefix $(DIR)/,$(I386_O))
|
||||
TGT = -DTCC_TARGET_I386
|
||||
@ -80,7 +72,10 @@ else
|
||||
$(error libtcc1.a not supported on target '$(TARGET)')
|
||||
endif
|
||||
|
||||
XFLAGS ?= $(CFLAGS) $(PICFLAGS) $(TGT)
|
||||
XFLAGS = $(TGT)
|
||||
ifeq "$(XCC)" "$(CC)"
|
||||
XFLAGS += $(CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(TARGETOS),Darwin)
|
||||
XAR = $(DIR)/tiny_libmaker$(EXESUF)
|
||||
|
2
libtcc.c
2
libtcc.c
@ -262,7 +262,7 @@ struct mem_debug_header {
|
||||
int line_num;
|
||||
char file_name[MEM_DEBUG_FILE_LEN + 1];
|
||||
unsigned magic2;
|
||||
unsigned magic3;
|
||||
__attribute__((aligned(16))) unsigned magic3;
|
||||
};
|
||||
|
||||
typedef struct mem_debug_header mem_debug_header_t;
|
||||
|
3
tcc.h
3
tcc.h
@ -72,6 +72,9 @@
|
||||
# pragma warning (disable : 4018) // signed/unsigned mismatch
|
||||
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
# define ssize_t intptr_t
|
||||
# define __attribute__(x) __declspec x
|
||||
# define aligned align
|
||||
# else
|
||||
# endif
|
||||
# undef CONFIG_TCC_STATIC
|
||||
#endif
|
||||
|
@ -134,23 +134,23 @@ test4: tcctest.c test.ref
|
||||
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
|
||||
dlltest:
|
||||
@echo ------------ $@ ------------
|
||||
$(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL ../libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
|
||||
$(TCC) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c
|
||||
$(TCC) -DONE_SOURCE $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
|
||||
$(TCC) $(NATIVE_DEFINES) $(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 -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) $(NATIVE_DEFINES) ../tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
|
||||
./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run ../examples/ex1.c
|
||||
$(TCC) $(NATIVE_DEFINES) $(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) -DONE_SOURCE -DMEM_DEBUG=2 ../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 -run ../tcc.c $(TCCFLAGS) tcctest.c
|
||||
$(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 $(TOPSRC)/tcc.c $(LIBS)
|
||||
./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
|
||||
|
||||
|
||||
# memory and bound check auto test
|
||||
|
@ -15,11 +15,15 @@ int add(int a, int b)
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/* this strinc is referenced by the generated code */
|
||||
const char hello[] = "Hello World!";
|
||||
|
||||
char my_program[] =
|
||||
"#include <tcclib.h>\n" /* include the "Simple libc header for TCC" */
|
||||
"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"
|
||||
"int fib(int n)\n"
|
||||
"{\n"
|
||||
|
@ -15,15 +15,18 @@ all test : $(sort $(TESTS))
|
||||
|
||||
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
|
||||
@echo PPTest $* ...
|
||||
-@$(TCC) -E -P $< >$*.output 2>&1 ; \
|
||||
-@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
|
||||
diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
|
||||
&& rm -f $*.output
|
||||
|
||||
%.test: %.S %.expect
|
||||
@echo PPTest $* ...
|
||||
-@$(TCC) -E -P $< >$*.output 2>&1 ; \
|
||||
-@$(TCC) -E -P $< $(FILTER) >$*.output 2>&1 ; \
|
||||
diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
|
||||
&& rm -f $*.output
|
||||
|
||||
|
@ -2667,6 +2667,9 @@ int reltab[3] = { 1, 2, 3 };
|
||||
int *rel1 = &reltab[1];
|
||||
int *rel2 = &reltab[2];
|
||||
|
||||
#ifdef _WIN64
|
||||
void relocation_test(void) {}
|
||||
#else
|
||||
void getmyaddress(void)
|
||||
{
|
||||
printf("in getmyaddress\n");
|
||||
@ -2695,6 +2698,7 @@ void relocation_test(void)
|
||||
printf("pa_symbol=0x%lx\n", __pa_symbol() >> 63);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void old_style_f(a,b,c)
|
||||
int a, b;
|
||||
@ -3127,8 +3131,10 @@ void other_constraints_test(void)
|
||||
{
|
||||
unsigned long ret;
|
||||
int var;
|
||||
#ifndef _WIN64
|
||||
__asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));
|
||||
printf ("oc1: %d\n", ret == (unsigned long)&var);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
@ -3203,9 +3209,11 @@ void test_high_clobbers(void)
|
||||
correctly capture the data flow, but good enough for us. */
|
||||
asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");
|
||||
clobber_r12();
|
||||
#ifndef _WIN64
|
||||
asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");
|
||||
printf("asmhc: 0x%x\n", val2);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static long cpu_number;
|
||||
|
Loading…
Reference in New Issue
Block a user