some cleanups related to recent commits

- configure/Makefile : cleanup, really use CC_NAME
- tccasm.c : remove C99 construct that MSVC doesn't compile
- arm-gen.c, x86_64-gen.c, riscv64-gen.c, tccmacho.c : ditto
- arm64-gen.c: commit 383acf8eff wrote:
  "Instead of a cast, it would be better to pass the exact type."
  It is true that there are better solutions but it is not
  passing the exact type (I think).
- tcctest.c: revert "fix cast test for clang" 03646ad46f
  this obviously wants to test non-portable conversions
- 114_bound_signal.test: clock_nanosleep is too new for older
  linuxes, just use sleep() instead
This commit is contained in:
grischka 2020-06-27 17:22:04 +02:00
parent 0ee4989ed3
commit 72277967ff
16 changed files with 124 additions and 155 deletions

View file

@ -25,13 +25,14 @@ CFLAGS += $(CPPFLAGS)
VPATH = $(TOPSRC) VPATH = $(TOPSRC)
ifdef CONFIG_WIN32 ifdef CONFIG_WIN32
CFG = -win
ifneq ($(CONFIG_static),yes) ifneq ($(CONFIG_static),yes)
LIBTCC = libtcc$(DLLSUF) LIBTCC = libtcc$(DLLSUF)
LIBTCCDEF = libtcc.def LIBTCCDEF = libtcc.def
endif endif
CFGWIN = -win
NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
else else
CFG = -unx
LIBS=-lm -lpthread LIBS=-lm -lpthread
ifneq ($(CONFIG_ldl),no) ifneq ($(CONFIG_ldl),no)
LIBS+=-ldl LIBS+=-ldl
@ -44,21 +45,21 @@ else
LINK_LIBTCC += -Wl,-rpath,"$(libdir)" LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
endif endif
endif endif
CFGWIN =-unx
NATIVE_TARGET = $(ARCH) NATIVE_TARGET = $(ARCH)
ifdef CONFIG_OSX ifdef CONFIG_OSX
NATIVE_TARGET = $(ARCH)-osx NATIVE_TARGET = $(ARCH)-osx
ifneq ($(CC),tcc) ifneq ($(CC_NAME),tcc)
LDFLAGS += -flat_namespace -undefined warning LDFLAGS += -flat_namespace -undefined warning
endif endif
export MACOSX_DEPLOYMENT_TARGET := 10.6 export MACOSX_DEPLOYMENT_TARGET := 10.6
export DYLD_LIBRARY_PATH := $(CURDIR)/$(TOP)
endif endif
endif endif
# run local version of tcc with local libraries and includes # run local version of tcc with local libraries and includes
TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
TCCFLAGS = $(TCCFLAGS$(CFGWIN)) TCCFLAGS = $(TCCFLAGS$(CFG))
TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
# cross compiler targets to build # cross compiler targets to build
@ -110,9 +111,9 @@ cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
# build specific cross compiler & lib # build specific cross compiler & lib
cross-%: %-tcc$(EXESUF) %-libtcc1.a ; cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
install: ; @$(MAKE) --no-print-directory install$(CFGWIN) install: ; @$(MAKE) --no-print-directory install$(CFG)
install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes
uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN) uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG)
ifdef CONFIG_cross ifdef CONFIG_cross
all : cross all : cross
@ -228,11 +229,7 @@ tcc_p$(EXESUF): $($T_FILES)
# static libtcc library # static libtcc library
libtcc.a: $(LIBTCC_OBJ) libtcc.a: $(LIBTCC_OBJ)
ifeq ($(CC),tcc)
$(CC) -ar rcs $@ $^
else
$S$(AR) rcs $@ $^ $S$(AR) rcs $@ $^
endif
# dynamic libtcc library # dynamic libtcc library
libtcc.so: $(LIBTCC_OBJ) libtcc.so: $(LIBTCC_OBJ)

View file

@ -943,8 +943,6 @@ struct avail_regs {
int first_free_reg; /* next free register in the sequence, hole excluded */ int first_free_reg; /* next free register in the sequence, hole excluded */
}; };
#define AVAIL_REGS_INITIALIZER (struct avail_regs) { { 0, 0, 0}, 0, 0, 0 }
/* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC /* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC
param) according to the rules described in the procedure call standard for param) according to the rules described in the procedure call standard for
the ARM architecture (AAPCS). If found, the registers are assigned to this the ARM architecture (AAPCS). If found, the registers are assigned to this
@ -1060,14 +1058,16 @@ struct param_plan {
struct plan { struct plan {
struct param_plan *pplans; /* array of all the param plans */ struct param_plan *pplans; /* array of all the param plans */
struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */ struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */
int nb_plans;
}; };
#define add_param_plan(plan,pplan,class) \ static void add_param_plan(struct plan* plan, int cls, int start, int end, SValue *v)
do { \ {
pplan.prev = plan->clsplans[class]; \ struct param_plan *p = &plan->pplans[plan->nb_plans++];
plan->pplans[plan ## _nb] = pplan; \ p->prev = plan->clsplans[cls];
plan->clsplans[class] = &plan->pplans[plan ## _nb++]; \ plan->clsplans[cls] = p;
} while(0) p->start = start, p->end = end, p->sval = v;
}
/* Assign parameters to registers and stack with alignment according to the /* Assign parameters to registers and stack with alignment according to the
rules in the procedure call standard for the ARM architecture (AAPCS). rules in the procedure call standard for the ARM architecture (AAPCS).
@ -1090,14 +1090,11 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
{ {
int i, size, align; int i, size, align;
int ncrn /* next core register number */, nsaa /* next stacked argument address*/; int ncrn /* next core register number */, nsaa /* next stacked argument address*/;
int plan_nb = 0; struct avail_regs avregs = {{0}};
struct param_plan pplan;
struct avail_regs avregs = AVAIL_REGS_INITIALIZER;
ncrn = nsaa = 0; ncrn = nsaa = 0;
*todo = 0; *todo = 0;
plan->pplans = nb_args ? tcc_malloc(nb_args * sizeof(*plan->pplans)) : NULL;
memset(plan->clsplans, 0, sizeof(plan->clsplans));
for(i = nb_args; i-- ;) { for(i = nb_args; i-- ;) {
int j, start_vfpreg = 0; int j, start_vfpreg = 0;
CType type = vtop[-i].type; CType type = vtop[-i].type;
@ -1120,11 +1117,8 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
start_vfpreg = assign_vfpreg(&avregs, align, size); start_vfpreg = assign_vfpreg(&avregs, align, size);
end_vfpreg = start_vfpreg + ((size - 1) >> 2); end_vfpreg = start_vfpreg + ((size - 1) >> 2);
if (start_vfpreg >= 0) { if (start_vfpreg >= 0) {
pplan = (struct param_plan) {start_vfpreg, end_vfpreg, &vtop[-i]}; add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS,
if (is_hfa) start_vfpreg, end_vfpreg, &vtop[-i]);
add_param_plan(plan, pplan, VFP_STRUCT_CLASS);
else
add_param_plan(plan, pplan, VFP_CLASS);
continue; continue;
} else } else
break; break;
@ -1137,8 +1131,7 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
* CORE_STRUCT_CLASS or the first of STACK_CLASS. */ * CORE_STRUCT_CLASS or the first of STACK_CLASS. */
for (j = ncrn; j < 4 && j < ncrn + size / 4; j++) for (j = ncrn; j < 4 && j < ncrn + size / 4; j++)
*todo|=(1<<j); *todo|=(1<<j);
pplan = (struct param_plan) {ncrn, j, &vtop[-i]}; add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &vtop[-i]);
add_param_plan(plan, pplan, CORE_STRUCT_CLASS);
ncrn += size/4; ncrn += size/4;
if (ncrn > 4) if (ncrn > 4)
nsaa = (ncrn - 4) * 4; nsaa = (ncrn - 4) * 4;
@ -1156,24 +1149,18 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
if (ncrn == 4) if (ncrn == 4)
break; break;
} }
pplan = (struct param_plan) {ncrn, ncrn, &vtop[-i]}; add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]);
ncrn++; ncrn += 1 + is_long;
if (is_long)
pplan.end = ncrn++;
add_param_plan(plan, pplan, CORE_CLASS);
continue; continue;
} }
} }
nsaa = (nsaa + (align - 1)) & ~(align - 1); nsaa = (nsaa + (align - 1)) & ~(align - 1);
pplan = (struct param_plan) {nsaa, nsaa + size, &vtop[-i]}; add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]);
add_param_plan(plan, pplan, STACK_CLASS);
nsaa += size; /* size already rounded up before */ nsaa += size; /* size already rounded up before */
} }
return nsaa; return nsaa;
} }
#undef add_param_plan
/* Copy parameters to their final destination (core reg, VFP reg or stack) for /* Copy parameters to their final destination (core reg, VFP reg or stack) for
function call. function call.
@ -1378,6 +1365,10 @@ void gfunc_call(int nb_args)
if (r == VT_CMP || (r & ~1) == VT_JMP) if (r == VT_CMP || (r & ~1) == VT_JMP)
gv(RC_INT); gv(RC_INT);
memset(&plan, 0, sizeof plan);
if (nb_args)
plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans));
args_size = assign_regs(nb_args, float_abi, &plan, &todo); args_size = assign_regs(nb_args, float_abi, &plan, &todo);
#ifdef TCC_ARM_EABI #ifdef TCC_ARM_EABI
@ -1420,7 +1411,7 @@ void gfunc_prolog(Sym *func_sym)
CType ret_type; CType ret_type;
#ifdef TCC_ARM_EABI #ifdef TCC_ARM_EABI
struct avail_regs avregs = AVAIL_REGS_INITIALIZER; struct avail_regs avregs = {{0}};
#endif #endif
sym = func_type->ref; sym = func_type->ref;
@ -1471,7 +1462,7 @@ void gfunc_prolog(Sym *func_sym)
#ifdef TCC_ARM_EABI #ifdef TCC_ARM_EABI
if (float_abi == ARM_HARD_FLOAT) { if (float_abi == ARM_HARD_FLOAT) {
func_vc += nf * 4; func_vc += nf * 4;
avregs = AVAIL_REGS_INITIALIZER; memset(&avregs, 0, sizeof avregs);
} }
#endif #endif
pn = struct_ret, sn = 0; pn = struct_ret, sn = 0;

View file

@ -98,6 +98,7 @@ int gotplt_entry_type (int reloc_type)
return -1; return -1;
} }
#ifndef TCC_TARGET_PE
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{ {
Section *plt = s1->plt; Section *plt = s1->plt;
@ -160,6 +161,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
} }
} }
} }
#endif
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{ {

View file

@ -802,7 +802,7 @@ static int arm64_hfa_aux(CType *type, int *fsize, int num)
return -1; return -1;
} }
static int arm64_hfa(CType *type, int *fsize) static int arm64_hfa(CType *type, unsigned *fsize)
{ {
if ((type->t & VT_BTYPE) == VT_STRUCT || if ((type->t & VT_BTYPE) == VT_STRUCT ||
((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR))) { ((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR))) {
@ -1086,7 +1086,7 @@ ST_FUNC void gfunc_call(int nb_args)
else if (a[i] < 32) { else if (a[i] < 32) {
// value in floating-point registers // value in floating-point registers
if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz); uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
vtop->type.t = VT_PTR; vtop->type.t = VT_PTR;
gaddrof(); gaddrof();
gv(RC_R30); gv(RC_R30);
@ -1137,7 +1137,7 @@ ST_FUNC void gfunc_call(int nb_args)
} }
else if (a[0] == 16) { else if (a[0] == 16) {
uint32_t j, sz, n = arm64_hfa(return_type, (int *)&sz); uint32_t j, sz, n = arm64_hfa(return_type, &sz);
for (j = 0; j < n; j++) for (j = 0; j < n; j++)
o(0x3d000100 | o(0x3d000100 |
(sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
@ -1213,7 +1213,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
// HFAs of float and double need to be written differently: // HFAs of float and double need to be written differently:
if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) { if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) {
uint32_t j, sz, k = arm64_hfa(&sym->type, (int *)&sz); uint32_t j, sz, k = arm64_hfa(&sym->type, &sz);
if (sz < 16) if (sz < 16)
for (j = 0; j < k; j++) { for (j = 0; j < k; j++) {
o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 | o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
@ -1277,7 +1277,7 @@ ST_FUNC void gen_va_start(void)
ST_FUNC void gen_va_arg(CType *t) ST_FUNC void gen_va_arg(CType *t)
{ {
int align, size = type_size(t, &align); int align, size = type_size(t, &align);
int fsize, hfa = arm64_hfa(t, (int *)&fsize); unsigned fsize, hfa = arm64_hfa(t, &fsize);
uint32_t r0, r1; uint32_t r0, r1;
if (is_float(t->t)) { if (is_float(t->t)) {
@ -1387,7 +1387,7 @@ ST_FUNC void gfunc_return(CType *func_type)
} }
case 16: case 16:
if ((func_type->t & VT_BTYPE) == VT_STRUCT) { if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz); uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
gaddrof(); gaddrof();
gv(RC_R(0)); gv(RC_R(0));
for (j = 0; j < n; j++) for (j = 0; j < n; j++)

31
configure vendored
View file

@ -48,7 +48,8 @@ cpu=
cpuver= cpuver=
gcc_major=0 gcc_major=0
gcc_minor=0 gcc_minor=0
gcc_name="gcc" cc_name="gcc"
ar_set=
# OS specific # OS specific
targetos=`uname` targetos=`uname`
@ -110,7 +111,7 @@ for opt do
;; ;;
--cc=*) cc=`echo $opt | cut -d '=' -f 2` --cc=*) cc=`echo $opt | cut -d '=' -f 2`
;; ;;
--ar=*) ar=`echo $opt | cut -d '=' -f 2` --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes"
;; ;;
--extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
;; ;;
@ -226,9 +227,6 @@ if test "$mingw32" = "yes" ; then
if test "$source_path_used" = "no"; then if test "$source_path_used" = "no"; then
source_path="." source_path="."
fi fi
if test "${cc%% *}" = "gcc"; then
test -z "$LDFLAGS" && LDFLAGS="-static"
fi
test -z "$prefix" && prefix="C:/Program Files/tcc" test -z "$prefix" && prefix="C:/Program Files/tcc"
test -z "$tccdir" && tccdir="${prefix}" test -z "$tccdir" && tccdir="${prefix}"
test -z "$bindir" && bindir="${tccdir}" test -z "$bindir" && bindir="${tccdir}"
@ -323,17 +321,17 @@ if test -z "$cross_prefix" ; then
if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
echo "configure: error: '$cc' failed to compile conftest.c." echo "configure: error: '$cc' failed to compile conftest.c."
else else
cc_name="$($CONFTEST compiler)"
gcc_major="$($CONFTEST version)" gcc_major="$($CONFTEST version)"
gcc_minor="$($CONFTEST minor)" gcc_minor="$($CONFTEST minor)"
gcc_name="$($CONFTEST compiler)" bigendian="$($CONFTEST bigendian)"
_triplet="$($CONFTEST triplet)"
fi fi
bigendian="$($CONFTEST bigendian)"
if test "$mingw32" = "no" ; then if test "$mingw32" = "no" ; then
if test -z "$triplet"; then if test -z "$triplet"; then
tt="$($CONFTEST triplet)" if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then triplet="$_triplet"
triplet="$tt"
fi fi
fi fi
@ -364,6 +362,11 @@ if test -z "$cross_prefix" ; then
echo "Perhaps you want ./configure --config-musl" echo "Perhaps you want ./configure --config-musl"
fi fi
fi fi
else # mingw32 = yes
if test "$cc_name" = "gcc"; then
# avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
test -z "$LDFLAGS" && LDFLAGS="-static"
fi
fi fi
else else
# if cross compiling, cannot launch a program, so make a static guess # if cross compiling, cannot launch a program, so make a static guess
@ -377,11 +380,11 @@ if test "$bigendian" = "yes" ; then
fi fi
# a final configuration tuning # a final configuration tuning
if ! echo "$cc" | grep -q "tcc"; then if test "$cc_name" != "tcc"; then
OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
# we want -Wno- but gcc does not always reject unknown -Wno- options # we want -Wno- but gcc does not always reject unknown -Wno- options
OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation" OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
if $cc --version 2>&1 | grep -q "clang"; then if test "$cc_name" = "clang"; then
OPT1="$OPT1 -fheinous-gnu-extensions" OPT1="$OPT1 -fheinous-gnu-extensions"
OPT2="$OPT2 -Wstring-plus-int" OPT2="$OPT2 -Wstring-plus-int"
fi fi
@ -395,6 +398,8 @@ if ! echo "$cc" | grep -q "tcc"; then
# cat cc_msg.txt # cat cc_msg.txt
# echo $CFLAGS # echo $CFLAGS
rm -f cc_msg.txt a.out rm -f cc_msg.txt a.out
else # cc is tcc
test "$ar_set" || ar="$cc -ar"
fi fi
fcho() { if test -n "$2"; then echo "$1$2"; fi } fcho() { if test -n "$2"; then echo "$1$2"; fi }
@ -427,6 +432,7 @@ mandir=\$(DESTDIR)$mandir
infodir=\$(DESTDIR)$infodir infodir=\$(DESTDIR)$infodir
docdir=\$(DESTDIR)$docdir docdir=\$(DESTDIR)$docdir
CC=$cc CC=$cc
CC_NAME=$cc_name
GCC_MAJOR=$gcc_major GCC_MAJOR=$gcc_major
GCC_MINOR=$gcc_minor GCC_MINOR=$gcc_minor
AR=$ar AR=$ar
@ -502,6 +508,7 @@ fi
cat >>$TMPH <<EOF cat >>$TMPH <<EOF
#define GCC_MAJOR $gcc_major #define GCC_MAJOR $gcc_major
#define GCC_MINOR $gcc_minor #define GCC_MINOR $gcc_minor
#define CC_NAME CC_${cc_name}
EOF EOF
diff $TMPH config.h >/dev/null 2>&1 diff $TMPH config.h >/dev/null 2>&1

View file

@ -61,48 +61,57 @@ int main(int argc, char *argv[])
_setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */ _setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */
#endif #endif
switch(argc == 2 ? argv[1][0] : 0) { switch(argc == 2 ? argv[1][0] : 0) {
case 'b': case 'b'://igendian
{ {
volatile unsigned foo = 0x01234567; volatile unsigned foo = 0x01234567;
puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
break; break;
} }
#if defined(__clang__) #if defined(__clang__)
case 'm': case 'm'://inor
printf("%d\n", __clang_minor__); printf("%d\n", __clang_minor__);
break; break;
case 'v': case 'v'://ersion
printf("%d\n", __clang_major__); printf("%d\n", __clang_major__);
break; break;
#elif defined(__TINYC__) #elif defined(__TINYC__)
case 'v': case 'v'://ersion
puts("0"); puts("0");
break; break;
case 'm': case 'm'://inor
printf("%d\n", __TINYC__); printf("%d\n", __TINYC__);
break; break;
#elif defined(_MSC_VER)
case 'v'://ersion
puts("0");
break;
case 'm'://inor
printf("%d\n", _MSC_VER);
break;
#elif defined(__GNUC__) && defined(__GNUC_MINOR__) #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
/* GNU comes last as other compilers may add 'GNU' compatibility */ /* GNU comes last as other compilers may add 'GNU' compatibility */
case 'm': case 'm'://inor
printf("%d\n", __GNUC_MINOR__); printf("%d\n", __GNUC_MINOR__);
break; break;
case 'v': case 'v'://ersion
printf("%d\n", __GNUC__); printf("%d\n", __GNUC__);
break; break;
#else #else
case 'm': case 'm'://inor
case 'v': case 'v'://ersion
puts("0"); puts("0");
break; break;
#endif #endif
case 't': case 't'://riplet
puts(TRIPLET); puts(TRIPLET);
break; break;
case 'c': case 'c'://ompiler
#if defined(__clang__) #if defined(__clang__)
puts("clang"); puts("clang");
#elif defined(__TINYC__) #elif defined(__TINYC__)
puts("tcc"); puts("tcc");
#elif defined(_MSC_VER)
puts("msvc");
#elif defined(__GNUC__) #elif defined(__GNUC__)
puts("gcc"); puts("gcc");
#else #else

View file

@ -8,11 +8,7 @@ VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
ifdef CONFIG_OSX
XTCC ?= DYLD_LIBRARY_PATH=$(TOP) $(TOP)/$(X)tcc$(EXESUF)
else
XTCC ?= $(TOP)/$(X)tcc$(EXESUF) XTCC ?= $(TOP)/$(X)tcc$(EXESUF)
endif
XCC = $(XTCC) XCC = $(XTCC)
XAR = $(XTCC) -ar XAR = $(XTCC) -ar
XFLAGS-unx = -B$(TOPSRC) XFLAGS-unx = -B$(TOPSRC)

View file

@ -578,7 +578,7 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named)
ST_FUNC void gfunc_call(int nb_args) ST_FUNC void gfunc_call(int nb_args)
{ {
int i, align, size, areg[2]; int i, align, size, areg[2];
int info[nb_args ? nb_args : 1]; int *info = tcc_malloc((nb_args + 1) * sizeof (int));
int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0; int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0;
SValue *sv; SValue *sv;
Sym *sa; Sym *sa;
@ -775,6 +775,7 @@ ST_FUNC void gfunc_call(int nb_args)
else else
EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
} }
tcc_free(info);
} }
static int func_sub_sp_offset, num_va_regs, func_va_list_ofs; static int func_sub_sp_offset, num_va_regs, func_va_list_ofs;

View file

@ -57,8 +57,8 @@ static int asm2cname(int v, int *addeddot)
v = tok_alloc(name + 1, strlen(name) - 1)->tok; v = tok_alloc(name + 1, strlen(name) - 1)->tok;
} else if (!strchr(name, '.')) { } else if (!strchr(name, '.')) {
int n = strlen(name) + 2; int n = strlen(name) + 2;
char newname[n]; char newname[256];
snprintf(newname, n, ".%s", name); snprintf(newname, sizeof newname, ".%s", name);
v = tok_alloc(newname, n - 1)->tok; v = tok_alloc(newname, n - 1)->tok;
*addeddot = 1; *addeddot = 1;
} }

View file

@ -4978,7 +4978,7 @@ the_end:
bt = t & (VT_BTYPE|VT_LONG); bt = t & (VT_BTYPE|VT_LONG);
if (bt == VT_LONG) if (bt == VT_LONG)
t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT;
#ifdef TCC_TARGET_PE #if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER)
if (bt == VT_LDOUBLE) if (bt == VT_LDOUBLE)
t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG); t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG);
#endif #endif

View file

@ -530,15 +530,20 @@ struct {
uint32_t flags; uint32_t flags;
char *name; char *name;
} skinfo[sk_last] = { } skinfo[sk_last] = {
[sk_text] = { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS /*[sk_unknown] =*/ { 0 },
/*[sk_discard] =*/ { 0 },
/*[sk_text] =*/ { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS
| S_ATTR_SOME_INSTRUCTIONS, "__text" }, | S_ATTR_SOME_INSTRUCTIONS, "__text" },
[sk_ro_data] = { 1, S_REGULAR, "__rodata" }, /*[sk_stubs] =*/ { 0 },
[sk_nl_ptr] = { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" }, /*[sk_ro_data] =*/ { 1, S_REGULAR, "__rodata" },
[sk_init] = { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" }, /*[sk_uw_info] =*/ { 0 },
[sk_fini] = { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" }, /*[sk_nl_ptr] =*/ { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" },
[sk_rw_data] = { 2, S_REGULAR, "__data" }, /*[sk_la_ptr] =*/ { 0 },
[sk_bss] = { 2, S_ZEROFILL, "__bss" }, /*[sk_init] =*/ { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" },
[sk_linkedit] = { 3, S_REGULAR, NULL }, /*[sk_fini] =*/ { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" },
/*[sk_rw_data] =*/ { 2, S_REGULAR, "__data" },
/*[sk_bss] =*/ { 2, S_ZEROFILL, "__bss" },
/*[sk_linkedit] =*/ { 3, S_REGULAR, NULL },
}; };
static void collect_sections(TCCState *s1, struct macho *mo) static void collect_sections(TCCState *s1, struct macho *mo)
@ -663,7 +668,7 @@ static void collect_sections(TCCState *s1, struct macho *mo)
} }
if (sec) if (sec)
sec->align = al; sec->align = al;
al = 1U << al; al = 1ULL << al;
if (al > 4096) if (al > 4096)
tcc_warning("alignment > 4096"), sec->align = 12, al = 4096; tcc_warning("alignment > 4096"), sec->align = 12, al = 4096;
curaddr = (curaddr + al - 1) & -al; curaddr = (curaddr + al - 1) & -al;
@ -779,7 +784,7 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename)
int fd, mode, file_type; int fd, mode, file_type;
FILE *fp; FILE *fp;
int i, ret = -1; int i, ret = -1;
struct macho mo = {}; struct macho mo = {0};
file_type = s1->output_type; file_type = s1->output_type;
if (file_type == TCC_OUTPUT_OBJ) if (file_type == TCC_OUTPUT_OBJ)
@ -912,8 +917,8 @@ ST_FUNC int macho_load_dll(TCCState *s1, int fd, const char *filename, int lev)
{ {
struct dylib_command *dc = (struct dylib_command*)lc; struct dylib_command *dc = (struct dylib_command*)lc;
char *name = (char*)lc + dc->name; char *name = (char*)lc + dc->name;
dprintf(" REEXPORT %s\n", name);
int subfd = open(name, O_RDONLY | O_BINARY); int subfd = open(name, O_RDONLY | O_BINARY);
dprintf(" REEXPORT %s\n", name);
if (subfd < 0) if (subfd < 0)
tcc_warning("can't open %s (reexported from %s)", name, filename); tcc_warning("can't open %s (reexported from %s)", name, filename);
else { else {

View file

@ -73,6 +73,9 @@ ifeq ($(ARCH),i386)
# by GCC in 32bit mode when PIC is enabled. # by GCC in 32bit mode when PIC is enabled.
test.ref: CFLAGS+=-fno-PIC -fno-PIE test.ref: CFLAGS+=-fno-PIC -fno-PIE
endif endif
ifeq ($(CC_NAME),msvc)
test.ref abitest : CC = gcc
endif
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
DISAS = objdump -d DISAS = objdump -d
@ -302,7 +305,7 @@ clean:
rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF) rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
rm -f ex? tcc_g weaktest.*.txt *.def libtcc_test_mt rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt
@$(MAKE) -C tests2 $@ @$(MAKE) -C tests2 $@
@$(MAKE) -C pp $@ @$(MAKE) -C pp $@

View file

@ -2,6 +2,10 @@
* TCC auto test program * TCC auto test program
*/ */
#include "config.h" #include "config.h"
#define CC_gcc 1
#define CC_clang 2
#define CC_tcc 3
#define CC_msvc 4 /* cannot compile this file */
/* Unfortunately, gcc version < 3 does not handle that! */ /* Unfortunately, gcc version < 3 does not handle that! */
#define ALL_ISOC99 #define ALL_ISOC99
@ -1829,11 +1833,13 @@ void cast_test()
printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a')); printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a')); printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
#if CC_NAME != CC_clang /* doesn't like non-portable conversions */
/* from pointer to integer types */ /* from pointer to integer types */
printf("%d %d %ld %ld %lld %lld\n", printf("%d %d %ld %ld %lld %lld\n",
(int)(long)p, (unsigned int)(long)p, (int)p, (unsigned int)p,
(long)p, (unsigned long)p, (long)p, (unsigned long)p,
(long long)(long)p, (unsigned long long)(long)p); (long long)p, (unsigned long long)p);
#endif
/* from integers to pointers */ /* from integers to pointers */
printf("%p %p %p %p\n", printf("%p %p %p %p\n",

View file

@ -8,52 +8,6 @@
#include <errno.h> #include <errno.h>
#include <setjmp.h> #include <setjmp.h>
#if defined(__APPLE__)
/*
* clock_nanosleep is missing on all macOS version, add emulation.
*/
/* scale factors */
#define TIMING_GIGA 1000000000
#define TIMER_ABSTIME 0 /* not used */
/* timespec difference (monotonic) right - left */
static inline void
timespec_monodiff_rml(struct timespec *ts_out, const struct timespec *ts_in) {
/*
* out = in - out,
* where in > out
*/
ts_out->tv_sec = ts_in->tv_sec - ts_out->tv_sec;
ts_out->tv_nsec = ts_in->tv_nsec - ts_out->tv_nsec;
if (ts_out->tv_sec < 0) {
ts_out->tv_sec = 0;
ts_out->tv_nsec = 0;
} else if (ts_out->tv_nsec < 0) {
if (ts_out->tv_sec == 0) {
ts_out->tv_sec = 0;
ts_out->tv_nsec = 0;
} else {
ts_out->tv_sec = ts_out->tv_sec - 1;
ts_out->tv_nsec = ts_out->tv_nsec + TIMING_GIGA;
}
}
}
static inline int
clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, struct timespec *remain) {
struct timespec ts_delta;
int retval = clock_gettime(clock_id, &ts_delta);
(void)remain;
(void)flags;
if (retval == 0) {
timespec_monodiff_rml(&ts_delta, req);
retval = nanosleep(&ts_delta, NULL);
}
return retval;
}
#endif
static volatile int run = 1; static volatile int run = 1;
static int dummy[10]; static int dummy[10];
static sem_t sem; static sem_t sem;
@ -116,7 +70,6 @@ main (void)
int i; int i;
pthread_t id1, id2; pthread_t id1, id2;
struct sigaction act; struct sigaction act;
struct timespec request;
sigjmp_buf sj; sigjmp_buf sj;
sigset_t m; sigset_t m;
@ -125,17 +78,16 @@ main (void)
act.sa_flags = 0; act.sa_flags = 0;
sigemptyset (&act.sa_mask); sigemptyset (&act.sa_mask);
sigaction (SIGUSR1, &act, NULL); sigaction (SIGUSR1, &act, NULL);
sem_init (&sem, 1, 0); sem_init (&sem, 1, 0);
pthread_create(&id1, NULL, high_load, NULL); pthread_create(&id1, NULL, high_load, NULL);
pthread_create(&id2, NULL, do_signal, NULL); pthread_create(&id2, NULL, do_signal, NULL);
clock_gettime (CLOCK_MONOTONIC, &request);
request.tv_sec += 1;
request.tv_nsec += 0;
printf ("start\n"); printf ("start\n");
while (clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &request, NULL)) { sleep(1);
}
printf ("end\n");
run = 0; run = 0;
printf ("end\n");
pthread_join(id1, NULL); pthread_join(id1, NULL);
pthread_join(id2, NULL); pthread_join(id2, NULL);
sem_destroy (&sem); sem_destroy (&sem);

View file

@ -43,9 +43,7 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-)
endif endif
ifeq (-$(CONFIG_WIN32)-,-yes-) ifeq (-$(CONFIG_WIN32)-,-yes-)
SKIP += 106_pthread.test # No pthread support SKIP += 106_pthread.test # No pthread support
endif SKIP += 114_bound_signal.test # No pthread support
ifneq (-$(CONFIG_WIN32)-$(findstring $(GCC_MAJOR),3 4)-,---)
SKIP += 114_bound_signal.test # not on windows or older linuxes
endif endif
# Some tests might need arguments # Some tests might need arguments

View file

@ -1289,11 +1289,11 @@ void gfunc_call(int nb_args)
{ {
X86_64_Mode mode; X86_64_Mode mode;
CType type; CType type;
int size, align, r, args_size, stack_adjust, i, reg_count; int size, align, r, args_size, stack_adjust, i, reg_count, k;
int nb_reg_args = 0; int nb_reg_args = 0;
int nb_sse_args = 0; int nb_sse_args = 0;
int sse_reg, gen_reg; int sse_reg, gen_reg;
char _onstack[nb_args ? nb_args : 1], *onstack = _onstack; char *onstack = tcc_malloc((nb_args + 1) * sizeof (char));
#ifdef CONFIG_TCC_BCHECK #ifdef CONFIG_TCC_BCHECK
if (tcc_state->do_bounds_check) if (tcc_state->do_bounds_check)
@ -1339,9 +1339,9 @@ void gfunc_call(int nb_args)
sse_reg = nb_sse_args; sse_reg = nb_sse_args;
args_size = 0; args_size = 0;
stack_adjust &= 15; stack_adjust &= 15;
for (i = 0; i < nb_args;) { for (i = k = 0; i < nb_args;) {
mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, &reg_count); mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, &reg_count);
if (!onstack[i]) { if (!onstack[i + k]) {
++i; ++i;
continue; continue;
} }
@ -1354,7 +1354,7 @@ void gfunc_call(int nb_args)
args_size += 8; args_size += 8;
stack_adjust = 0; stack_adjust = 0;
} }
if (onstack[i] == 2) if (onstack[i + k] == 2)
stack_adjust = 1; stack_adjust = 1;
vrotb(i+1); vrotb(i+1);
@ -1404,9 +1404,11 @@ void gfunc_call(int nb_args)
vpop(); vpop();
--nb_args; --nb_args;
onstack++; k++;
} }
tcc_free(onstack);
/* XXX This should be superfluous. */ /* XXX This should be superfluous. */
save_regs(0); /* save used temporary registers */ save_regs(0); /* save used temporary registers */