aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--arm-asm.c2
-rwxr-xr-xconfigure2
-rw-r--r--lib/Makefile6
-rw-r--r--lib/alloca86-bt.S2
-rw-r--r--lib/alloca86.S2
-rw-r--r--lib/alloca86_64-bt.S2
-rw-r--r--lib/alloca86_64.S4
-rw-r--r--lib/bcheck.c20
-rw-r--r--lib/libtcc1.c6
-rw-r--r--lib/va_list.c2
-rw-r--r--libtcc.c6
-rw-r--r--tcc.c15
-rw-r--r--tcc.h59
-rw-r--r--tccgen.c15
-rw-r--r--tccpp.c23
-rw-r--r--tests/Makefile18
-rw-r--r--tests/tests2/95_bitfields.c9
-rw-r--r--tests/tests2/95_bitfields.expect149
-rw-r--r--tests/tests2/95_bitfields_ms.expect3
-rw-r--r--tests/tests2/96_nodata_wanted.c82
-rw-r--r--tests/tests2/96_nodata_wanted.expect21
-rw-r--r--tests/tests2/Makefile6
-rw-r--r--win32/build-tcc.bat50
-rw-r--r--win32/lib/chkstk.S4
25 files changed, 350 insertions, 163 deletions
diff --git a/Makefile b/Makefile
index 62b7372..3a5c000 100644
--- a/Makefile
+++ b/Makefile
@@ -173,11 +173,12 @@ ifeq ($(ONE_SOURCE),yes)
LIBTCC_OBJ = $(X)libtcc.o
LIBTCC_INC = $($T_FILES)
TCC_FILES = $(X)tcc.o
-$(X)libtcc.o $T-tcc$(EXESUF) : DEFINES += -DONE_SOURCE
+tcc.o : DEFINES += -DONE_SOURCE=0
else
LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
+$(TCC_FILES) : DEFINES += -DONE_SOURCE=0
endif
# target specific object rule
@@ -200,7 +201,7 @@ $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
# profiling version
tcc_p$(EXESUF): $($T_FILES)
- $(CC) -o $@ $< $(DEFINES) -DONE_SOURCE $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
+ $(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
# static libtcc library
libtcc.a: $(LIBTCC_OBJ)
diff --git a/arm-asm.c b/arm-asm.c
index 15253ab..3b5ae66 100644
--- a/arm-asm.c
+++ b/arm-asm.c
@@ -70,7 +70,6 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
uint8_t *clobber_regs,
int out_reg)
{
- asm_error();
}
ST_FUNC void asm_compute_constraints(ASMOperand *operands,
@@ -78,7 +77,6 @@ ST_FUNC void asm_compute_constraints(ASMOperand *operands,
const uint8_t *clobber_regs,
int *pout_reg)
{
- asm_error();
}
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
diff --git a/configure b/configure
index 4a337e7..78f2072 100755
--- a/configure
+++ b/configure
@@ -410,7 +410,7 @@ echo "Info directory $infodir"
echo "Doc directory $docdir"
fcho "Target root prefix " "$sysroot"
echo "Source path $source_path"
-echo "C compiler $cc"
+echo "C compiler $cc ($gcc_major.$gcc_minor)"
echo "Target OS $targetos"
echo "CPU $cpu"
fcho "Triplet " "$triplet"
diff --git a/lib/Makefile b/lib/Makefile
index 35046a4..3b582d4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -29,7 +29,7 @@ endif
# only for native compiler
$(X)BCHECK_O = bcheck.o
-ifeq ($(CONFIG_musl),yes)
+ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes)
BCHECK_O =
endif
@@ -61,10 +61,10 @@ $(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))
$(XAR) rcs $@ $^
$(X)%.o : %.c
- $(XCC) -c $< -o $@ $(DEFINES) $(XFLAGS)
+ $(XCC) -c $< -o $@ $(XFLAGS)
$(X)%.o : %.S
- $(XCC) -c $< -o $@ $(DEFINES) $(XFLAGS)
+ $(XCC) -c $< -o $@ $(XFLAGS)
$(X)crt1w.o : crt1.c
$(X)wincrt1w.o : wincrt1.c
diff --git a/lib/alloca86-bt.S b/lib/alloca86-bt.S
index 5215505..4f95cf1 100644
--- a/lib/alloca86-bt.S
+++ b/lib/alloca86-bt.S
@@ -11,7 +11,7 @@ __bound_alloca:
and $-4,%eax
jz p6
-#ifdef TCC_TARGET_PE
+#ifdef _WIN32
p4:
cmp $4096,%eax
jbe p5
diff --git a/lib/alloca86.S b/lib/alloca86.S
index ec1e185..bb7a2c2 100644
--- a/lib/alloca86.S
+++ b/lib/alloca86.S
@@ -10,7 +10,7 @@ alloca:
and $-4,%eax
jz p3
-#ifdef TCC_TARGET_PE
+#ifdef _WIN32
p1:
cmp $4096,%eax
jbe p2
diff --git a/lib/alloca86_64-bt.S b/lib/alloca86_64-bt.S
index 9b6c3c6..4cbad90 100644
--- a/lib/alloca86_64-bt.S
+++ b/lib/alloca86_64-bt.S
@@ -4,7 +4,7 @@
.globl __bound_alloca
__bound_alloca:
-#ifdef TCC_TARGET_PE
+#ifdef _WIN32
# bound checking is not implemented
pop %rdx
mov %rcx,%rax
diff --git a/lib/alloca86_64.S b/lib/alloca86_64.S
index 4f4dad7..ae3c97d 100644
--- a/lib/alloca86_64.S
+++ b/lib/alloca86_64.S
@@ -5,7 +5,7 @@
alloca:
pop %rdx
-#ifdef TCC_TARGET_PE
+#ifdef _WIN32
mov %rcx,%rax
#else
mov %rdi,%rax
@@ -14,7 +14,7 @@ alloca:
and $-16,%rax
jz p3
-#ifdef TCC_TARGET_PE
+#ifdef _WIN32
p1:
cmp $4096,%rax
jbe p2
diff --git a/lib/bcheck.c b/lib/bcheck.c
index 41c08aa..d0c1ae2 100644
--- a/lib/bcheck.c
+++ b/lib/bcheck.c
@@ -21,10 +21,15 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \
- && !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+
+#if !defined(__FreeBSD__) \
+ && !defined(__FreeBSD_kernel__) \
+ && !defined(__DragonFly__) \
+ && !defined(__OpenBSD__) \
+ && !defined(__NetBSD__)
#include <malloc.h>
#endif
+
#if !defined(_WIN32)
#include <unistd.h>
#endif
@@ -45,10 +50,13 @@
#define CONFIG_TCC_MALLOC_HOOKS
#define HAVE_MEMALIGN
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
- || defined(__DragonFly__) || defined(__dietlibc__) \
- || defined(__UCLIBC__) || defined(__OpenBSD__) || defined(__NetBSD__) \
- || defined(_WIN32) || defined(TCC_UCLIBC) || defined(TCC_MUSL)
+#if defined(__FreeBSD__) \
+ || defined(__FreeBSD_kernel__) \
+ || defined(__DragonFly__) \
+ || defined(__OpenBSD__) \
+ || defined(__NetBSD__) \
+ || defined(__dietlibc__) \
+ || defined(_WIN32)
//#warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS
#undef HAVE_MEMALIGN
diff --git a/lib/libtcc1.c b/lib/libtcc1.c
index 0702a59..0e46618 100644
--- a/lib/libtcc1.c
+++ b/lib/libtcc1.c
@@ -107,10 +107,10 @@ union float_long {
};
/* XXX: we don't support several builtin supports for now */
-#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
+#if !defined __x86_64__ && !defined __arm__
/* XXX: use gcc/tcc intrinsic ? */
-#if defined(TCC_TARGET_I386)
+#if defined __i386__
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
: "=r" ((USItype) (sh)), \
@@ -589,7 +589,7 @@ long long __fixdfdi (double a1)
return s ? ret : -ret;
}
-#ifndef TCC_TARGET_ARM
+#ifndef __arm__
unsigned long long __fixunsxfdi (long double a1)
{
register union ldouble_long dl1;
diff --git a/lib/va_list.c b/lib/va_list.c
index 57dce0d..8749f46 100644
--- a/lib/va_list.c
+++ b/lib/va_list.c
@@ -1,6 +1,6 @@
/* va_list.c - tinycc support for va_list on X86_64 */
-#if defined TCC_TARGET_X86_64
+#if defined __x86_64__
/* Avoid include files, they may not be available when cross compiling */
extern void *memset(void *s, int c, __SIZE_TYPE__ n);
diff --git a/libtcc.c b/libtcc.c
index c00a909..ec81992 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -36,7 +36,7 @@ static int nb_states;
/********************************************************/
-#ifdef ONE_SOURCE
+#if ONE_SOURCE
#include "tccpp.c"
#include "tccgen.c"
#include "tccelf.c"
@@ -58,6 +58,7 @@ static int nb_states;
#ifdef TCC_TARGET_C67
#include "c67-gen.c"
#include "c67-link.c"
+#include "tcccoff.c"
#endif
#ifdef TCC_TARGET_X86_64
#include "x86_64-gen.c"
@@ -67,9 +68,6 @@ static int nb_states;
#ifdef CONFIG_TCC_ASM
#include "tccasm.c"
#endif
-#ifdef TCC_TARGET_COFF
-#include "tcccoff.c"
-#endif
#ifdef TCC_TARGET_PE
#include "tccpe.c"
#endif
diff --git a/tcc.c b/tcc.c
index bef02e7..4c7235a 100644
--- a/tcc.c
+++ b/tcc.c
@@ -18,10 +18,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifdef ONE_SOURCE
-#include "libtcc.c"
-#else
#include "tcc.h"
+#if ONE_SOURCE
+# include "libtcc.c"
#endif
#include "tcctools.c"
@@ -335,12 +334,14 @@ redo:
}
s->filetype = 0;
s->alacarte_link = 1;
- if (ret || --n == 0
+ if (--n == 0 || ret
|| (s->output_type == TCC_OUTPUT_OBJ && !s->option_r))
break;
}
- if (s->output_type == TCC_OUTPUT_PREPROCESS) {
+ if (s->run_test) {
+ t = 0;
+ } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
;
} else if (0 == ret) {
if (s->output_type == TCC_OUTPUT_MEMORY) {
@@ -357,10 +358,6 @@ redo:
}
}
- if (t)
- ret = 0;
- if (s->run_test)
- t = 0;
if (s->do_bench && (n | t | ret) == 0)
tcc_print_stats(s, getclock_ms() - start_time);
tcc_delete(s);
diff --git a/tcc.h b/tcc.h
index 05371bd..bfe6ab4 100644
--- a/tcc.h
+++ b/tcc.h
@@ -81,6 +81,14 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define O_BINARY 0
#endif
+#ifndef offsetof
+#define offsetof(type, field) ((size_t) &((type *)0)->field)
+#endif
+
+#ifndef countof
+#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
+#endif
+
#ifdef _MSC_VER
# define NORETURN __declspec(noreturn)
# define ALIGNED(x) __declspec(align(x))
@@ -99,12 +107,6 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define PATHCMP strcmp
#endif
-#ifdef TCC_TARGET_PE
-#define PATHSEP ';'
-#else
-#define PATHSEP ':'
-#endif
-
/* -------------------------------------------- */
/* parser debug */
@@ -129,12 +131,20 @@ extern long double strtold (const char *__nptr, char **__endptr);
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
!defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
!defined(TCC_TARGET_X86_64)
-#define TCC_TARGET_I386
-#endif
-
-/* object format selection */
-#if defined(TCC_TARGET_C67)
-#define TCC_TARGET_COFF
+# if defined __x86_64__ || defined _AMD64_
+# define TCC_TARGET_X86_64
+# elif defined __arm__
+# define TCC_TARGET_ARM
+# define TCC_ARM_EABI
+# define TCC_ARM_HARDFLOAT
+# elif defined __aarch64__
+# define TCC_TARGET_ARM64
+# else
+# define TCC_TARGET_I386
+# endif
+# ifdef _WIN32
+# define TCC_TARGET_PE 1
+# endif
#endif
/* only native compiler supports -run */
@@ -164,7 +174,7 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define CONFIG_SYSROOT ""
#endif
#ifndef CONFIG_TCCDIR
-# define CONFIG_TCCDIR "."
+# define CONFIG_TCCDIR "/usr/local/lib/tcc"
#endif
#ifndef CONFIG_LDDIR
# define CONFIG_LDDIR "lib"
@@ -266,6 +276,12 @@ extern long double strtold (const char *__nptr, char **__endptr);
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
#endif
+#ifdef TCC_TARGET_PE
+#define PATHSEP ';'
+#else
+#define PATHSEP ':'
+#endif
+
/* -------------------------------------------- */
#include "libtcc.h"
@@ -278,7 +294,11 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define PUB_FUNC
#endif
-#ifdef ONE_SOURCE
+#ifndef ONE_SOURCE
+# define ONE_SOURCE 1
+#endif
+
+#if ONE_SOURCE
#define ST_INLN static inline
#define ST_FUNC static
#define ST_DATA static
@@ -314,6 +334,7 @@ extern long double strtold (const char *__nptr, char **__endptr);
# include "arm64-link.c"
#endif
#ifdef TCC_TARGET_C67
+# define TCC_TARGET_COFF
# include "coff.h"
# include "c67-gen.c"
# include "c67-link.c"
@@ -965,14 +986,6 @@ struct filespec {
#define TOK_A_SHL 0x81
#define TOK_A_SAR 0x82
-#ifndef offsetof
-#define offsetof(type, field) ((size_t) &((type *)0)->field)
-#endif
-
-#ifndef countof
-#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
-#endif
-
#define TOK_EOF (-1) /* end of file */
#define TOK_LINEFEED 10 /* line feed */
@@ -1641,7 +1654,7 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename)
/********************************************************/
#undef ST_DATA
-#ifdef ONE_SOURCE
+#if ONE_SOURCE
#define ST_DATA static
#else
#define ST_DATA
diff --git a/tccgen.c b/tccgen.c
index 2754192..0828820 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -1218,12 +1218,16 @@ ST_FUNC int gv(int rc)
} else {
if (is_float(vtop->type.t) &&
(vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ unsigned long offset;
/* CPUs usually cannot use float constants, so we store them
generically in data segment */
size = type_size(&vtop->type, &align);
- vpush_ref(&vtop->type, data_section, data_section->data_offset, size);
+ if (NODATA_WANTED)
+ size = 0, align = 1;
+ offset = section_add(data_section, size, align);
+ vpush_ref(&vtop->type, data_section, offset, size);
vswap();
- init_putv(&vtop->type, data_section, data_section->data_offset);
+ init_putv(&vtop->type, data_section, offset);
vtop->r |= VT_LVAL;
}
#ifdef CONFIG_TCC_BCHECK
@@ -3518,8 +3522,11 @@ static void struct_layout(CType *type, AttributeDef *ad)
/* In PCC layout named bit-fields influence the alignment
of the containing struct using the base types alignment,
except for packed fields (which here have correct align). */
- if (f->v & SYM_FIRST_ANOM)
+ if (f->v & SYM_FIRST_ANOM
+ // && bit_size // ??? gcc on ARM/rpi does that
+ )
align = 1;
+
} else {
bt = f->type.t & VT_BTYPE;
if ((bit_pos + bit_size > size * 8)
@@ -3610,7 +3617,7 @@ static void struct_layout(CType *type, AttributeDef *ad)
if (a < maxalign)
a = maxalign;
type->ref->r = a;
- if (pragma_pack && pragma_pack < maxalign) {
+ if (pragma_pack && pragma_pack < maxalign && 0 == pcc) {
/* can happen if individual align for some member was given. In
this case MSVC ignores maxalign when aligning the size */
a = pragma_pack;
diff --git a/tccpp.c b/tccpp.c
index 5209b39..4d5169e 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -49,6 +49,7 @@ static unsigned char isidnum_table[256 - CH_EOF];
static int pp_debug_tok, pp_debug_symv;
static int pp_once;
static int pp_expr;
+static int pp_counter;
static void tok_print(const char *msg, const int *str);
static struct TinyAlloc *toksym_alloc;
@@ -1409,7 +1410,7 @@ ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep)
}
/* fake the nth "#if defined test_..." for tcc -dt -run */
-static void maybe_run_test(TCCState *s, int *c)
+static void maybe_run_test(TCCState *s)
{
const char *p;
if (s->include_stack_ptr != s->include_stack)
@@ -1420,7 +1421,7 @@ static void maybe_run_test(TCCState *s, int *c)
if (0 != --s->run_test)
return;
fprintf(s->ppfp, "\n[%s]\n" + !(s->dflag & 32), p), fflush(s->ppfp);
- *c = 1;
+ define_push(tok, MACRO_OBJ, NULL, NULL);
}
/* eval an expression for #if/#elif */
@@ -1440,9 +1441,9 @@ static int expr_preprocess(void)
next_nomacro();
if (tok < TOK_IDENT)
expect("identifier");
- c = define_find(tok) != 0;
if (tcc_state->run_test)
- maybe_run_test(tcc_state, &c);
+ maybe_run_test(tcc_state);
+ c = define_find(tok) != 0;
if (t == '(') {
next_nomacro();
if (tok != ')')
@@ -3222,18 +3223,17 @@ static int macro_subst_tok(
Sym *s)
{
Sym *args, *sa, *sa1;
- int parlevel, *mstr, t, t1, spc;
+ int parlevel, t, t1, spc;
TokenString str;
char *cstrval;
CValue cval;
CString cstr;
char buf[32];
- static int counter;
-
+
/* if symbol is a macro, prepare substitution */
/* special macros */
if (tok == TOK___LINE__ || tok == TOK___COUNTER__) {
- t = tok == TOK___LINE__ ? file->line_num : counter++;
+ t = tok == TOK___LINE__ ? file->line_num : pp_counter++;
snprintf(buf, sizeof(buf), "%d", t);
cstrval = buf;
t1 = TOK_PPNUM;
@@ -3264,11 +3264,11 @@ static int macro_subst_tok(
cval.str.data = cstr.data;
tok_str_add2(tok_str, t1, &cval);
cstr_free(&cstr);
- } else {
+ } else if (s->d) {
int saved_parse_flags = parse_flags;
int *joined_str = NULL;
+ int *mstr = s->d;
- mstr = s->d;
if (s->type.t == MACRO_FUNC) {
/* whitespace between macro name and argument list */
TokenString ws_str;
@@ -3523,6 +3523,9 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
s1->include_stack_ptr = s1->include_stack;
s1->ifdef_stack_ptr = s1->ifdef_stack;
file->ifdef_stack_ptr = s1->ifdef_stack_ptr;
+ pp_expr = 0;
+ pp_counter = 0;
+ pp_debug_tok = pp_debug_symv = 0;
pp_once++;
pvtop = vtop = vstack - 1;
s1->pack_stack[0] = 0;
diff --git a/tests/Makefile b/tests/Makefile
index 00d2c9e..39dee7f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -55,7 +55,7 @@ ifdef CONFIG_WIN32
PATH := $(CURDIR)/$(TOP)$(SEP)$(PATH) # for libtcc_test to find libtcc.dll
endif
-RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)
+RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
DISAS = objdump -d
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
@@ -129,23 +129,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 $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
- $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
+ $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
+ $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(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 $(TOPSRC)/libtcc.c
+ $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
- $(TCC) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
+ $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(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 $(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
+ $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
+ ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
+ ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
# memory and bound check auto test
@@ -210,7 +210,7 @@ abitest-cc$(EXESUF): abitest.c $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
abitest-tcc$(EXESUF): abitest.c libtcc.c
- $(TCC) -o $@ $^ $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS)
+ $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
ABITESTS := abitest-cc$(EXESUF)
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
diff --git a/tests/tests2/95_bitfields.c b/tests/tests2/95_bitfields.c
index 7edbeed..683becf 100644
--- a/tests/tests2/95_bitfields.c
+++ b/tests/tests2/95_bitfields.c
@@ -87,8 +87,10 @@
# define P
#endif
+printf("\n\n" + 2*top);
#define TEST 1
#include SELF
+top = 0;
#define TEST 2
#include SELF
#define TEST 3
@@ -99,7 +101,6 @@
#include SELF
#define TEST 6
#include SELF
-printf("\n\n");
#if PACK
# pragma pack(pop)
@@ -174,7 +175,7 @@ void dump(void *p, int s)
#define TEST_STRUCT(v1,v2,v3,v4,v5) { \
struct __s _s, *s = & _s; \
- printf("---- TEST %d%s%s%s ----\n", \
+ printf("\n---- TEST %d%s%s%s ----\n" + top, \
TEST, MS_BF?" - MS-BITFIELDS":"", \
PACK?" - PACKED":"", \
ALIGN?" - WITH ALIGN":""); \
@@ -184,7 +185,7 @@ void dump(void *p, int s)
s->x = v1, s->y = v2, s->z = v3, s->a += v4, ++s->a, s->b = v5; \
printf("bits as set : "), dump(s, sizeof *s); \
printf("values :"), pv(x), pv(y), pv(z), pv(a), pv(b), printf("\n"); \
- printf("align/size : %d %d\n\n", alignof(struct __s),sizeof(struct __s)); \
+ printf("align/size : %d %d\n", alignof(struct __s),sizeof(struct __s)); \
}
#ifdef _MSC_VER
@@ -203,6 +204,8 @@ void dump(void *p, int s)
#define SELF "95_bitfields.c"
+int top = 1;
+
int main()
{
#define MS_BF MS_BITFIELDS
diff --git a/tests/tests2/95_bitfields.expect b/tests/tests2/95_bitfields.expect
new file mode 100644
index 0000000..6a8fd9a
--- /dev/null
+++ b/tests/tests2/95_bitfields.expect
@@ -0,0 +1,149 @@
+---- TEST 1 ----
+bits in use : 0000001FFFFFFFFF007F0FFF
+bits as set : 000000076055555500440333
+values : 333 44 555555 06 07
+align/size : 4 12
+
+---- TEST 2 ----
+bits in use : 000000000000003F7FFFFFFFFFFFFFFF00000000003F0FFF
+bits as set : 0000000000000025123456789ABCDEF000000000001E0003
+values : 03 1e 123456789abcdef0 05 fffffffe
+align/size : 8 24
+
+---- TEST 3 ----
+bits in use : 001F1F1F000003FF
+bits as set : 000E0619000002F5
+values : 15 17 19 06 0e
+align/size : 4 8
+
+---- TEST 4 ----
+bits in use : 0007FFFF00000027
+bits as set : 00078F0F00000023
+values : 03 ffffffff 0f fffffff8 78
+align/size : 4 8
+
+---- TEST 5 ----
+bits in use : FFFFFF3FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
+bits as set : 007744000000007800000000300000000000000123456789
+values : 0000000123456789 f0000000 0000000000000078 44 77
+align/size : 8 24
+
+---- TEST 6 ----
+bits in use : 0000007000FFFFFFFFFFFFFF
+bits as set : 00000030002001FD00000004
+values : 01 02 03 04 fffffffd
+align/size : 4 12
+
+
+
+---- TEST 1 - PACKED ----
+bits in use : FFFFFFFFFFFFFF
+bits as set : 3B02AAAAAC4333
+values : 333 44 555555 06 07
+align/size : 1 7
+
+---- TEST 2 - PACKED ----
+bits in use : 7FFFFFFFFFFFFFFFFFFFFF
+bits as set : 4A48D159E26AF37BC1E003
+values : 03 1e 123456789abcdef0 05 fffffffe
+align/size : 1 11
+
+---- TEST 3 - PACKED ----
+bits in use : 7FFF000003FF
+bits as set : 38D9000002F5
+values : 15 17 19 06 0e
+align/size : 1 6
+
+---- TEST 4 - PACKED ----
+bits in use : 07FFFF00000027
+bits as set : 078F0F00000023
+values : 03 ffffffff 0f fffffff8 78
+align/size : 1 7
+
+---- TEST 5 - PACKED ----
+bits in use : FFFFFF07FFFFFFFFFFFFFFFF9FFFFFFFFFFF
+bits as set : 007744000000000F18000000000123456789
+values : 0000000123456789 f0000000 0000000000000078 44 77
+align/size : 1 18
+
+---- TEST 6 - PACKED ----
+bits in use : 007000FFFFFFFFFFFFFF
+bits as set : 0030002001FD00000004
+values : 01 02 03 04 fffffffd
+align/size : 1 10
+
+
+
+---- TEST 1 - WITH ALIGN ----
+bits in use : 000000000000001FFFFFFFFF007F0FFF
+bits as set : 00000000000000076055555500440333
+values : 333 44 555555 06 07
+align/size : 16 16
+
+---- TEST 2 - WITH ALIGN ----
+bits in use : 0000000000000000000000000000003F7FFFFFFFFFFFFFFF00000000003F0FFF
+bits as set : 00000000000000000000000000000025123456789ABCDEF000000000001E0003
+values : 03 1e 123456789abcdef0 05 fffffffe
+align/size : 16 32
+
+---- TEST 3 - WITH ALIGN ----
+bits in use : 0000000000000000000000000000001F000000000000000000001F1F000003FF
+bits as set : 0000000000000000000000000000000E000000000000000000000619000002F5
+values : 15 17 19 06 0e
+align/size : 16 32
+
+---- TEST 4 - WITH ALIGN ----
+bits in use : 0007FFFF00000027
+bits as set : 00078F0F00000023
+values : 03 ffffffff 0f fffffff8 78
+align/size : 4 8
+
+---- TEST 5 - WITH ALIGN ----
+bits in use : FFFFFF3FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
+bits as set : 007744000000007800000000300000000000000123456789
+values : 0000000123456789 f0000000 0000000000000078 44 77
+align/size : 8 24
+
+---- TEST 6 - WITH ALIGN ----
+bits in use : 0000007000FFFFFFFFFFFFFF
+bits as set : 00000030002001FD00000004
+values : 01 02 03 04 fffffffd
+align/size : 4 12
+
+
+
+---- TEST 1 - PACKED - WITH ALIGN ----
+bits in use : 000000000000000000FFFFFFFFFFFFFF
+bits as set : 0000000000000000003B02AAAAAC4333
+values : 333 44 555555 06 07
+align/size : 16 16
+
+---- TEST 2 - PACKED - WITH ALIGN ----
+bits in use : 3F01FFFFFFFFFFFFFFFFFFFF
+bits as set : 250048D159E26AF37BC1E003
+values : 03 1e 123456789abcdef0 05 fffffffe
+align/size : 1 12
+
+---- TEST 3 - PACKED - WITH ALIGN ----
+bits in use : 1F03FF000003FF
+bits as set : 0E00D9000002F5
+values : 15 17 19 06 0e
+align/size : 1 7
+
+---- TEST 4 - PACKED - WITH ALIGN ----
+bits in use : 07FFFF00000027
+bits as set : 078F0F00000023
+values : 03 ffffffff 0f fffffff8 78
+align/size : 1 7
+
+---- TEST 5 - PACKED - WITH ALIGN ----
+bits in use : FFFFFF07FFFFFFFFFFFFFFFF9FFFFFFFFFFF
+bits as set : 007744000000000F18000000000123456789
+values : 0000000123456789 f0000000 0000000000000078 44 77
+align/size : 1 18
+
+---- TEST 6 - PACKED - WITH ALIGN ----
+bits in use : 007000FFFFFFFFFFFFFF
+bits as set : 0030002001FD00000004
+values : 01 02 03 04 fffffffd
+align/size : 1 10
diff --git a/tests/tests2/95_bitfields_ms.expect b/tests/tests2/95_bitfields_ms.expect
index 6b5c3f9..8ccafb7 100644
--- a/tests/tests2/95_bitfields_ms.expect
+++ b/tests/tests2/95_bitfields_ms.expect
@@ -147,6 +147,3 @@ bits in use : 00000000700000FFFFFFFFFFFFFF
bits as set : 000000003000002001FD00000004
values : 01 02 03 04 fffffffd
align/size : 1 14
-
-
-
diff --git a/tests/tests2/96_nodata_wanted.c b/tests/tests2/96_nodata_wanted.c
index 1f022c9..b594938 100644
--- a/tests/tests2/96_nodata_wanted.c
+++ b/tests/tests2/96_nodata_wanted.c
@@ -25,50 +25,60 @@ void foo() {
short w = &foo; /* 2 cast warnings */
}
-#elif defined test_data_suppression
-#include <stdio.h>
+#elif defined test_data_suppression_off || defined test_data_suppression_on
-#define ASMLABELS(s) \
- __asm__(".global d"#s",t"#s"\n.data\nd"#s":\n.text\nt"#s":\n")
+#if defined test_data_suppression_on
+# define SKIP 1
+#else
+# define SKIP 0
+#endif
-#define PROG \
- static void *p = (void*)&main;\
- static char cc[] = "static string";\
- static double d = 8.0;\
- static struct __attribute__((packed)) {\
- unsigned x : 12;\
- unsigned char y : 7;\
- unsigned z : 28, a: 4, b: 5;\
- } s = { 0x333,0x44,0x555555,6,7 };\
- printf(" static data: %d - %.1f - %.1f - %s - %s\n",\
- sizeof 8.0, 8.0, d, __FUNCTION__, cc);\
- printf(" static bitfields: %x %x %x %x %x\n", s.x, s.y, s.z, s.a, s.b);
+#include <stdio.h>
+/* some gcc headers #define __attribute__ to empty if it's not gcc */
+#undef __attribute__
int main()
{
- extern char ds1[],ts1[];
- extern char ds2[],ts2[];
- extern char de1[],te1[];
- extern char de2[],te2[];
+ __label__ ts0, te0, ts1, te1;
+ int tl, dl;
- printf("suppression off\n");
- if (1) {
- ASMLABELS(s1);
- PROG
- ASMLABELS(e1);
- }
- printf(" data length is %s\n", de1 - ds1 ? "not 0":"0");
- printf(" text length is %s\n", te1 - ts1 ? "not 0":"0");
+ static char ds0 = 0;
+ static char de0 = 0;
+ /* get reference size of empty jmp */
+ts0:;
+ if (!SKIP) {}
+te0:;
+ dl = -(&de0 - &ds0);
+ tl = -(&&te0 - &&ts0);
- printf("suppression on\n");
- if (0) {
- ASMLABELS(s2);
- PROG
- ASMLABELS(e2);
+ /* test data and code suppression */
+ static char ds1 = 0;
+ts1:;
+ if (!SKIP) {
+ static void *p = (void*)&main;
+ static char cc[] = "static string";
+ static double d = 8.0;
+
+ static struct __attribute__((packed)) {
+ unsigned x : 12;
+ unsigned char y : 7;
+ unsigned z : 28, a: 4, b: 5;
+ } s = { 0x333,0x44,0x555555,6,7 };
+
+ printf("data:\n");
+ printf(" %d - %.1f - %.1f - %s - %s\n",
+ sizeof 8.0, 8.0, d, __FUNCTION__, cc);
+ printf(" %x %x %x %x %x\n",
+ s.x, s.y, s.z, s.a, s.b);
}
- printf(" data length is %x\n", de2 - ds2);
- printf(" text length is %X\n", te2 - ts2);
- return 0;
+te1:;
+ static char de1 = 0;
+
+ dl += &de1 - &ds1;
+ tl += &&te1 - &&ts1;
+ printf("size of data/text:\n %s/%s\n",
+ dl ? "non-zero":"zero", tl ? "non-zero":"zero");
+ printf("# %d/%d\n", dl, tl);
}
#endif
diff --git a/tests/tests2/96_nodata_wanted.expect b/tests/tests2/96_nodata_wanted.expect
index 9fd35ca..6e54f24 100644
--- a/tests/tests2/96_nodata_wanted.expect
+++ b/tests/tests2/96_nodata_wanted.expect
@@ -11,12 +11,15 @@
96_nodata_wanted.c:25: warning: assignment makes integer from pointer without a cast
96_nodata_wanted.c:25: warning: nonportable conversion from pointer to char/short
-[test_data_suppression]
-suppression off
- static data: 8 - 8.0 - 8.0 - main - static string
- static bitfields: 333 44 555555 6 7
- data length is not 0
- text length is not 0
-suppression on
- data length is 0
- text length is 0
+[test_data_suppression_off]
+data:
+ 8 - 8.0 - 8.0 - main - static string
+ 333 44 555555 6 7
+size of data/text:
+ non-zero/non-zero
+# 111/193
+
+[test_data_suppression_on]
+size of data/text:
+ zero/zero
+# 0/0
diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
index 4dd1591..c75db8c 100644
--- a/tests/tests2/Makefile
+++ b/tests/tests2/Makefile
@@ -24,7 +24,7 @@ ifeq (-$(findstring gcc,$(CC))-,--)
SKIP += $(patsubst %.expect,%.test,$(GEN-ALWAYS))
endif
ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-)
- SKIP += 95_bitfields_ms.test # type_align is differnt on 32bit-non-windows
+ SKIP += 95_bitfields%.test # type_align is differnt on 32bit-non-windows
endif
# Some tests might need arguments
@@ -46,7 +46,7 @@ FLAGS =
# Always generate certain .expects (don't put these in the GIT),
GEN-ALWAYS =
-GEN-ALWAYS += 95_bitfields.expect
+# GEN-ALWAYS += 95_bitfields.expect # does not work
# using the ms compiler for the really ms-compatible bitfields
95_bitfields_ms.test : GEN = $(GEN-MSC)
@@ -67,7 +67,7 @@ all test tests2.all: $(filter-out $(SKIP),$(TESTS)) ;
T1 = $(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS)
T2 = $(TCC) $(FLAGS) -run $< $(ARGS)
T3 = $(FILTER) >$*.output 2>&1 || true \
- && diff -Nbu $(filter %.expect,$^) $*.output \
+ && diff -Nbu -I "^\#" $(filter %.expect,$^) $*.output \
&& rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
# run single test and update .expect file, e.g. "make tests2.37+"
diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat
index 9a9184b..b234178 100644
--- a/win32/build-tcc.bat
+++ b/win32/build-tcc.bat
@@ -111,10 +111,10 @@ echo>> ..\config.h #endif
for %%f in (*tcc.exe *tcc.dll) do @del %%f
:compiler
-%CC% -o libtcc.dll -shared ..\libtcc.c %D% -DONE_SOURCE -DLIBTCC_AS_DLL
+%CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
@if errorlevel 1 goto :the_end
-%CC% -o tcc.exe ..\tcc.c libtcc.dll %D%
-%CC% -o %PX%-tcc.exe ..\tcc.c %DX% -DONE_SOURCE
+%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE=0
+%CC% -o %PX%-tcc.exe ..\tcc.c %DX%
@if (%TCC_FILES%)==(no) goto :files-done
@@ -131,30 +131,30 @@ copy>nul tcc-win32.txt doc
:libtcc1.a
@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
-.\tcc -m32 %D32% -c ../lib/libtcc1.c
-.\tcc -m32 %D32% -c lib/crt1.c
-.\tcc -m32 %D32% -c lib/crt1w.c
-.\tcc -m32 %D32% -c lib/wincrt1.c
-.\tcc -m32 %D32% -c lib/wincrt1w.c
-.\tcc -m32 %D32% -c lib/dllcrt1.c
-.\tcc -m32 %D32% -c lib/dllmain.c
-.\tcc -m32 %D32% -c lib/chkstk.S
-.\tcc -m32 %D32% -w -c ../lib/bcheck.c
-.\tcc -m32 %D32% -c ../lib/alloca86.S
-.\tcc -m32 %D32% -c ../lib/alloca86-bt.S
+.\tcc -m32 -c ../lib/libtcc1.c
+.\tcc -m32 -c lib/crt1.c
+.\tcc -m32 -c lib/crt1w.c
+.\tcc -m32 -c lib/wincrt1.c
+.\tcc -m32 -c lib/wincrt1w.c
+.\tcc -m32 -c lib/dllcrt1.c
+.\tcc -m32 -c lib/dllmain.c
+.\tcc -m32 -c lib/chkstk.S
+.\tcc -m32 -w -c ../lib/bcheck.c
+.\tcc -m32 -c ../lib/alloca86.S
+.\tcc -m32 -c ../lib/alloca86-bt.S
.\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
@if errorlevel 1 goto :the_end
-.\tcc -m64 %D64% -c ../lib/libtcc1.c
-.\tcc -m64 %D64% -c lib/crt1.c
-.\tcc -m64 %D64% -c lib/crt1w.c
-.\tcc -m64 %D64% -c lib/wincrt1.c
-.\tcc -m64 %D64% -c lib/wincrt1w.c
-.\tcc -m64 %D64% -c lib/dllcrt1.c
-.\tcc -m64 %D64% -c lib/dllmain.c
-.\tcc -m64 %D64% -c lib/chkstk.S
-.\tcc -m64 %D64% -w -c ../lib/bcheck.c
-.\tcc -m64 %D64% -c ../lib/alloca86_64.S
-.\tcc -m64 %D64% -c ../lib/alloca86_64-bt.S
+.\tcc -m64 -c ../lib/libtcc1.c
+.\tcc -m64 -c lib/crt1.c
+.\tcc -m64 -c lib/crt1w.c
+.\tcc -m64 -c lib/wincrt1.c
+.\tcc -m64 -c lib/wincrt1w.c
+.\tcc -m64 -c lib/dllcrt1.c
+.\tcc -m64 -c lib/dllmain.c
+.\tcc -m64 -c lib/chkstk.S
+.\tcc -m64 -w -c ../lib/bcheck.c
+.\tcc -m64 -c ../lib/alloca86_64.S
+.\tcc -m64 -c ../lib/alloca86_64-bt.S
.\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
@if errorlevel 1 goto :the_end
diff --git a/win32/lib/chkstk.S b/win32/lib/chkstk.S
index 2726061..ec5c07f 100644
--- a/win32/lib/chkstk.S
+++ b/win32/lib/chkstk.S
@@ -2,7 +2,7 @@
/* chkstk86.s */
/* ---------------------------------------------- */
-#ifndef TCC_TARGET_X86_64
+#ifndef __x86_64__
/* ---------------------------------------------- */
.globl __chkstk
@@ -68,7 +68,7 @@ tinyc_getbp:
/* ---------------------------------------------- */
-#ifndef TCC_TARGET_X86_64
+#ifndef __x86_64__
/* ---------------------------------------------- */
/*