History

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 383acf8eff2818f8f0c5 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" 03646ad46ff5d9a6d946 this obviously wants to test non-portable conversions - 114_bound_signal.test: clock_nanosleep is too new for older linuxes, just use sleep() instead

grischka committed 6 years ago

Commit 72277961 parent 0ee498916 files · +124 −155Browse files

Unified · Split

16 files
  1. Makefile +8 −11
  2. arm-gen.c +22 −31
  3. arm-link.c +2 −0
  4. arm64-gen.c +6 −6
  5. configure +19 −12
  6. conftest.c +20 −11
  7. lib/Makefile +0 −4
  8. riscv64-gen.c +2 −1
  9. tccasm.c +2 −2
  10. tccgen.c +1 −1
  11. tccmacho.c +16 −11
  12. tests/Makefile +4 −1
  13. tests/tcctest.c +8 −2
  14. tests/tests2/114_bound_signal.c +5 −53
  15. tests/tests2/Makefile +1 −3
  16. x86_64-gen.c +8 −6
Makefile+8−11
@@ -25,13 +25,14 @@ CFLAGS += $(CPPFLAGS) · 24 unmodified lines
2525 VPATH = $(TOPSRC)
2626
2727 ifdef CONFIG_WIN32
28+ CFG = -win
2829 ifneq ($(CONFIG_static),yes)
2930 LIBTCC = libtcc$(DLLSUF)
3031 LIBTCCDEF = libtcc.def
3132 endif
32− CFGWIN = -win
3333 NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
3434 else
35+ CFG = -unx
3536 LIBS=-lm -lpthread
3637 ifneq ($(CONFIG_ldl),no)
3738 LIBS+=-ldl
@@ -44,21 +45,21 @@ else · 6 unmodified lines
4445 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
4546 endif
4647 endif
47− CFGWIN =-unx
4848 NATIVE_TARGET = $(ARCH)
4949 ifdef CONFIG_OSX
5050 NATIVE_TARGET = $(ARCH)-osx
51− ifneq ($(CC),tcc)
51+ ifneq ($(CC_NAME),tcc)
5252 LDFLAGS += -flat_namespace -undefined warning
5353 endif
5454 export MACOSX_DEPLOYMENT_TARGET := 10.6
55+ export DYLD_LIBRARY_PATH := $(CURDIR)/$(TOP)
5556 endif
5657 endif
5758
5859 # run local version of tcc with local libraries and includes
5960 TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
6061 TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
61−TCCFLAGS = $(TCCFLAGS$(CFGWIN))
62+TCCFLAGS = $(TCCFLAGS$(CFG))
6263 TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
6364
6465 # cross compiler targets to build
@@ -110,9 +111,9 @@ cross: $(LIBTCC1_CROSS) $(PROGS_CROSS) · 45 unmodified lines
110111 # build specific cross compiler & lib
111112 cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
112113
113−install: ; @$(MAKE) --no-print-directory install$(CFGWIN)
114−install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes
115−uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN)
114+install: ; @$(MAKE) --no-print-directory install$(CFG)
115+install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes
116+uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG)
116117
117118 ifdef CONFIG_cross
118119 all : cross
@@ -228,11 +229,7 @@ tcc_p$(EXESUF): $($T_FILES) · 109 unmodified lines
228229
229230 # static libtcc library
230231 libtcc.a: $(LIBTCC_OBJ)
231−ifeq ($(CC),tcc)
232− $(CC) -ar rcs $@ $^
233−else
234232 $S$(AR) rcs $@ $^
235−endif
236233
237234 # dynamic libtcc library
238235 libtcc.so: $(LIBTCC_OBJ)
arm-gen.c+22−31
@@ -943,8 +943,6 @@ struct avail_regs { · 942 unmodified lines
943943 int first_free_reg; /* next free register in the sequence, hole excluded */
944944 };
945945
946−#define AVAIL_REGS_INITIALIZER (struct avail_regs) { { 0, 0, 0}, 0, 0, 0 }
947−
948946 /* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC
949947 param) according to the rules described in the procedure call standard for
950948 the ARM architecture (AAPCS). If found, the registers are assigned to this
@@ -1060,14 +1058,16 @@ struct param_plan { · 109 unmodified lines
10601058 struct plan {
10611059 struct param_plan *pplans; /* array of all the param plans */
10621060 struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */
1061+ int nb_plans;
10631062 };
10641063
1065−#define add_param_plan(plan,pplan,class) \
1066− do { \
1067− pplan.prev = plan->clsplans[class]; \
1068− plan->pplans[plan ## _nb] = pplan; \
1069− plan->clsplans[class] = &plan->pplans[plan ## _nb++]; \
1070− } while(0)
1064+static void add_param_plan(struct plan* plan, int cls, int start, int end, SValue *v)
1065+{
1066+ struct param_plan *p = &plan->pplans[plan->nb_plans++];
1067+ p->prev = plan->clsplans[cls];
1068+ plan->clsplans[cls] = p;
1069+ p->start = start, p->end = end, p->sval = v;
1070+}
10711071
10721072 /* Assign parameters to registers and stack with alignment according to the
10731073 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) · 16 unmodified lines
10901090 {
10911091 int i, size, align;
10921092 int ncrn /* next core register number */, nsaa /* next stacked argument address*/;
1093− int plan_nb = 0;
1094− struct param_plan pplan;
1095− struct avail_regs avregs = AVAIL_REGS_INITIALIZER;
1093+ struct avail_regs avregs = {{0}};
10961094
10971095 ncrn = nsaa = 0;
10981096 *todo = 0;
1099− plan->pplans = nb_args ? tcc_malloc(nb_args * sizeof(*plan->pplans)) : NULL;
1100− memset(plan->clsplans, 0, sizeof(plan->clsplans));
1097+
11011098 for(i = nb_args; i-- ;) {
11021099 int j, start_vfpreg = 0;
11031100 CType type = vtop[-i].type;
@@ -1120,11 +1117,8 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) · 16 unmodified lines
11201117 start_vfpreg = assign_vfpreg(&avregs, align, size);
11211118 end_vfpreg = start_vfpreg + ((size - 1) >> 2);
11221119 if (start_vfpreg >= 0) {
1123− pplan = (struct param_plan) {start_vfpreg, end_vfpreg, &vtop[-i]};
1124− if (is_hfa)
1125− add_param_plan(plan, pplan, VFP_STRUCT_CLASS);
1126− else
1127− add_param_plan(plan, pplan, VFP_CLASS);
1120+ add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS,
1121+ start_vfpreg, end_vfpreg, &vtop[-i]);
11281122 continue;
11291123 } else
11301124 break;
@@ -1137,8 +1131,7 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) · 6 unmodified lines
11371131 * CORE_STRUCT_CLASS or the first of STACK_CLASS. */
11381132 for (j = ncrn; j < 4 && j < ncrn + size / 4; j++)
11391133 *todo|=(1<<j);
1140− pplan = (struct param_plan) {ncrn, j, &vtop[-i]};
1141− add_param_plan(plan, pplan, CORE_STRUCT_CLASS);
1134+ add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &vtop[-i]);
11421135 ncrn += size/4;
11431136 if (ncrn > 4)
11441137 nsaa = (ncrn - 4) * 4;
@@ -1156,24 +1149,18 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) · 11 unmodified lines
11561149 if (ncrn == 4)
11571150 break;
11581151 }
1159− pplan = (struct param_plan) {ncrn, ncrn, &vtop[-i]};
1160− ncrn++;
1161− if (is_long)
1162− pplan.end = ncrn++;
1163− add_param_plan(plan, pplan, CORE_CLASS);
1152+ add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]);
1153+ ncrn += 1 + is_long;
11641154 continue;
11651155 }
11661156 }
11671157 nsaa = (nsaa + (align - 1)) & ~(align - 1);
1168− pplan = (struct param_plan) {nsaa, nsaa + size, &vtop[-i]};
1169− add_param_plan(plan, pplan, STACK_CLASS);
1158+ add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]);
11701159 nsaa += size; /* size already rounded up before */
11711160 }
11721161 return nsaa;
11731162 }
11741163
1175−#undef add_param_plan
1176−
11771164 /* Copy parameters to their final destination (core reg, VFP reg or stack) for
11781165 function call.
11791166
@@ -1378,6 +1365,10 @@ void gfunc_call(int nb_args) · 198 unmodified lines
13781365 if (r == VT_CMP || (r & ~1) == VT_JMP)
13791366 gv(RC_INT);
13801367
1368+ memset(&plan, 0, sizeof plan);
1369+ if (nb_args)
1370+ plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans));
1371+
13811372 args_size = assign_regs(nb_args, float_abi, &plan, &todo);
13821373
13831374 #ifdef TCC_ARM_EABI
@@ -1420,7 +1411,7 @@ void gfunc_prolog(Sym *func_sym) · 36 unmodified lines
14201411 CType ret_type;
14211412
14221413 #ifdef TCC_ARM_EABI
1423− struct avail_regs avregs = AVAIL_REGS_INITIALIZER;
1414+ struct avail_regs avregs = {{0}};
14241415 #endif
14251416
14261417 sym = func_type->ref;
@@ -1471,7 +1462,7 @@ void gfunc_prolog(Sym *func_sym) · 44 unmodified lines
14711462 #ifdef TCC_ARM_EABI
14721463 if (float_abi == ARM_HARD_FLOAT) {
14731464 func_vc += nf * 4;
1474− avregs = AVAIL_REGS_INITIALIZER;
1465+ memset(&avregs, 0, sizeof avregs);
14751466 }
14761467 #endif
14771468 pn = struct_ret, sn = 0;
arm-link.c+2−0
@@ -98,6 +98,7 @@ int gotplt_entry_type (int reloc_type) · 97 unmodified lines
9898 return -1;
9999 }
100100
101+#ifndef TCC_TARGET_PE
101102 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
102103 {
103104 Section *plt = s1->plt;
@@ -160,6 +161,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 56 unmodified lines
160161 }
161162 }
162163 }
164+#endif
163165
164166 void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
165167 {
arm64-gen.c+6−6
@@ -802,7 +802,7 @@ static int arm64_hfa_aux(CType *type, int *fsize, int num) · 801 unmodified lines
802802 return -1;
803803 }
804804
805−static int arm64_hfa(CType *type, int *fsize)
805+static int arm64_hfa(CType *type, unsigned *fsize)
806806 {
807807 if ((type->t & VT_BTYPE) == VT_STRUCT ||
808808 ((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR))) {
@@ -1086,7 +1086,7 @@ ST_FUNC void gfunc_call(int nb_args) · 277 unmodified lines
10861086 else if (a[i] < 32) {
10871087 // value in floating-point registers
10881088 if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1089− uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz);
1089+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
10901090 vtop->type.t = VT_PTR;
10911091 gaddrof();
10921092 gv(RC_R30);
@@ -1137,7 +1137,7 @@ ST_FUNC void gfunc_call(int nb_args) · 44 unmodified lines
11371137
11381138 }
11391139 else if (a[0] == 16) {
1140− uint32_t j, sz, n = arm64_hfa(return_type, (int *)&sz);
1140+ uint32_t j, sz, n = arm64_hfa(return_type, &sz);
11411141 for (j = 0; j < n; j++)
11421142 o(0x3d000100 |
11431143 (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
@@ -1213,7 +1213,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) · 69 unmodified lines
12131213
12141214 // HFAs of float and double need to be written differently:
12151215 if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) {
1216− uint32_t j, sz, k = arm64_hfa(&sym->type, (int *)&sz);
1216+ uint32_t j, sz, k = arm64_hfa(&sym->type, &sz);
12171217 if (sz < 16)
12181218 for (j = 0; j < k; j++) {
12191219 o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
@@ -1277,7 +1277,7 @@ ST_FUNC void gen_va_start(void) · 57 unmodified lines
12771277 ST_FUNC void gen_va_arg(CType *t)
12781278 {
12791279 int align, size = type_size(t, &align);
1280− int fsize, hfa = arm64_hfa(t, (int *)&fsize);
1280+ unsigned fsize, hfa = arm64_hfa(t, &fsize);
12811281 uint32_t r0, r1;
12821282
12831283 if (is_float(t->t)) {
@@ -1387,7 +1387,7 @@ ST_FUNC void gfunc_return(CType *func_type) · 103 unmodified lines
13871387 }
13881388 case 16:
13891389 if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
1390− uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz);
1390+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
13911391 gaddrof();
13921392 gv(RC_R(0));
13931393 for (j = 0; j < n; j++)
configure+19−12
@@ -48,7 +48,8 @@ cpu= · 47 unmodified lines
4848 cpuver=
4949 gcc_major=0
5050 gcc_minor=0
51−gcc_name="gcc"
51+cc_name="gcc"
52+ar_set=
5253
5354 # OS specific
5455 targetos=`uname`
@@ -110,7 +111,7 @@ for opt do · 55 unmodified lines
110111 ;;
111112 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
112113 ;;
113− --ar=*) ar=`echo $opt | cut -d '=' -f 2`
114+ --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes"
114115 ;;
115116 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
116117 ;;
@@ -226,9 +227,6 @@ if test "$mingw32" = "yes" ; then · 109 unmodified lines
226227 if test "$source_path_used" = "no"; then
227228 source_path="."
228229 fi
229− if test "${cc%% *}" = "gcc"; then
230− test -z "$LDFLAGS" && LDFLAGS="-static"
231− fi
232230 test -z "$prefix" && prefix="C:/Program Files/tcc"
233231 test -z "$tccdir" && tccdir="${prefix}"
234232 test -z "$bindir" && bindir="${tccdir}"
@@ -323,17 +321,17 @@ if test -z "$cross_prefix" ; then · 88 unmodified lines
323321 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
324322 echo "configure: error: '$cc' failed to compile conftest.c."
325323 else
324+ cc_name="$($CONFTEST compiler)"
326325 gcc_major="$($CONFTEST version)"
327326 gcc_minor="$($CONFTEST minor)"
328− gcc_name="$($CONFTEST compiler)"
327+ bigendian="$($CONFTEST bigendian)"
328+ _triplet="$($CONFTEST triplet)"
329329 fi
330− bigendian="$($CONFTEST bigendian)"
331330 if test "$mingw32" = "no" ; then
332331
333332 if test -z "$triplet"; then
334− tt="$($CONFTEST triplet)"
335− if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
336− triplet="$tt"
333+ if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
334+ triplet="$_triplet"
337335 fi
338336 fi
339337
@@ -364,6 +362,11 @@ if test -z "$cross_prefix" ; then · 24 unmodified lines
364362 echo "Perhaps you want ./configure --config-musl"
365363 fi
366364 fi
365+ else # mingw32 = yes
366+ if test "$cc_name" = "gcc"; then
367+ # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
368+ test -z "$LDFLAGS" && LDFLAGS="-static"
369+ fi
367370 fi
368371 else
369372 # if cross compiling, cannot launch a program, so make a static guess
@@ -377,11 +380,11 @@ if test "$bigendian" = "yes" ; then · 7 unmodified lines
377380 fi
378381
379382 # a final configuration tuning
380−if ! echo "$cc" | grep -q "tcc"; then
383+if test "$cc_name" != "tcc"; then
381384 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
382385 # we want -Wno- but gcc does not always reject unknown -Wno- options
383386 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
384− if $cc --version 2>&1 | grep -q "clang"; then
387+ if test "$cc_name" = "clang"; then
385388 OPT1="$OPT1 -fheinous-gnu-extensions"
386389 OPT2="$OPT2 -Wstring-plus-int"
387390 fi
@@ -395,6 +398,8 @@ if ! echo "$cc" | grep -q "tcc"; then · 7 unmodified lines
395398 # cat cc_msg.txt
396399 # echo $CFLAGS
397400 rm -f cc_msg.txt a.out
401+else # cc is tcc
402+ test "$ar_set" || ar="$cc -ar"
398403 fi
399404
400405 fcho() { if test -n "$2"; then echo "$1$2"; fi }
@@ -427,6 +432,7 @@ mandir=\$(DESTDIR)$mandir · 26 unmodified lines
427432 infodir=\$(DESTDIR)$infodir
428433 docdir=\$(DESTDIR)$docdir
429434 CC=$cc
435+CC_NAME=$cc_name
430436 GCC_MAJOR=$gcc_major
431437 GCC_MINOR=$gcc_minor
432438 AR=$ar
@@ -502,6 +508,7 @@ fi · 69 unmodified lines
502508 cat >>$TMPH <<EOF
503509 #define GCC_MAJOR $gcc_major
504510 #define GCC_MINOR $gcc_minor
511+#define CC_NAME CC_${cc_name}
505512 EOF
506513
507514 diff $TMPH config.h >/dev/null 2>&1
conftest.c+20−11
@@ -61,48 +61,57 @@ int main(int argc, char *argv[]) · 60 unmodified lines
6161 _setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */
6262 #endif
6363 switch(argc == 2 ? argv[1][0] : 0) {
64− case 'b':
64+ case 'b'://igendian
6565 {
6666 volatile unsigned foo = 0x01234567;
6767 puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
6868 break;
6969 }
7070 #if defined(__clang__)
71− case 'm':
71+ case 'm'://inor
7272 printf("%d\n", __clang_minor__);
7373 break;
74− case 'v':
74+ case 'v'://ersion
7575 printf("%d\n", __clang_major__);
7676 break;
7777 #elif defined(__TINYC__)
78− case 'v':
78+ case 'v'://ersion
7979 puts("0");
8080 break;
81− case 'm':
81+ case 'm'://inor
8282 printf("%d\n", __TINYC__);
8383 break;
84+#elif defined(_MSC_VER)
85+ case 'v'://ersion
86+ puts("0");
87+ break;
88+ case 'm'://inor
89+ printf("%d\n", _MSC_VER);
90+ break;
8491 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
8592 /* GNU comes last as other compilers may add 'GNU' compatibility */
86− case 'm':
93+ case 'm'://inor
8794 printf("%d\n", __GNUC_MINOR__);
8895 break;
89− case 'v':
96+ case 'v'://ersion
9097 printf("%d\n", __GNUC__);
9198 break;
9299 #else
93− case 'm':
94− case 'v':
100+ case 'm'://inor
101+ case 'v'://ersion
95102 puts("0");
96103 break;
97104 #endif
98− case 't':
105+ case 't'://riplet
99106 puts(TRIPLET);
100107 break;
101− case 'c':
108+ case 'c'://ompiler
102109 #if defined(__clang__)
103110 puts("clang");
104111 #elif defined(__TINYC__)
105112 puts("tcc");
113+#elif defined(_MSC_VER)
114+ puts("msvc");
106115 #elif defined(__GNUC__)
107116 puts("gcc");
108117 #else
lib/Makefile+0−4
@@ -8,11 +8,7 @@ VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib · 7 unmodified lines
88 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
99 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
1010
11−ifdef CONFIG_OSX
12−XTCC ?= DYLD_LIBRARY_PATH=$(TOP) $(TOP)/$(X)tcc$(EXESUF)
13−else
1411 XTCC ?= $(TOP)/$(X)tcc$(EXESUF)
15−endif
1612 XCC = $(XTCC)
1713 XAR = $(XTCC) -ar
1814 XFLAGS-unx = -B$(TOPSRC)
riscv64-gen.c+2−1
@@ -578,7 +578,7 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named) · 577 unmodified lines
578578 ST_FUNC void gfunc_call(int nb_args)
579579 {
580580 int i, align, size, areg[2];
581− int info[nb_args ? nb_args : 1];
581+ int *info = tcc_malloc((nb_args + 1) * sizeof (int));
582582 int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0;
583583 SValue *sv;
584584 Sym *sa;
@@ -775,6 +775,7 @@ ST_FUNC void gfunc_call(int nb_args) · 190 unmodified lines
775775 else
776776 EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
777777 }
778+ tcc_free(info);
778779 }
779780
780781 static int func_sub_sp_offset, num_va_regs, func_va_list_ofs;
tccasm.c+2−2
@@ -57,8 +57,8 @@ static int asm2cname(int v, int *addeddot) · 56 unmodified lines
5757 v = tok_alloc(name + 1, strlen(name) - 1)->tok;
5858 } else if (!strchr(name, '.')) {
5959 int n = strlen(name) + 2;
60− char newname[n];
61− snprintf(newname, n, ".%s", name);
60+ char newname[256];
61+ snprintf(newname, sizeof newname, ".%s", name);
6262 v = tok_alloc(newname, n - 1)->tok;
6363 *addeddot = 1;
6464 }
tccgen.c+1−1
@@ -4978,7 +4978,7 @@ the_end: · 4977 unmodified lines
49784978 bt = t & (VT_BTYPE|VT_LONG);
49794979 if (bt == VT_LONG)
49804980 t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT;
4981−#ifdef TCC_TARGET_PE
4981+#if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER)
49824982 if (bt == VT_LDOUBLE)
49834983 t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG);
49844984 #endif
tccmacho.c+16−11
@@ -530,15 +530,20 @@ struct { · 529 unmodified lines
530530 uint32_t flags;
531531 char *name;
532532 } skinfo[sk_last] = {
533− [sk_text] = { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS
533+ /*[sk_unknown] =*/ { 0 },
534+ /*[sk_discard] =*/ { 0 },
535+ /*[sk_text] =*/ { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS
534536 | S_ATTR_SOME_INSTRUCTIONS, "__text" },
535− [sk_ro_data] = { 1, S_REGULAR, "__rodata" },
536− [sk_nl_ptr] = { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" },
537− [sk_init] = { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" },
538− [sk_fini] = { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" },
539− [sk_rw_data] = { 2, S_REGULAR, "__data" },
540− [sk_bss] = { 2, S_ZEROFILL, "__bss" },
541− [sk_linkedit] = { 3, S_REGULAR, NULL },
537+ /*[sk_stubs] =*/ { 0 },
538+ /*[sk_ro_data] =*/ { 1, S_REGULAR, "__rodata" },
539+ /*[sk_uw_info] =*/ { 0 },
540+ /*[sk_nl_ptr] =*/ { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" },
541+ /*[sk_la_ptr] =*/ { 0 },
542+ /*[sk_init] =*/ { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" },
543+ /*[sk_fini] =*/ { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" },
544+ /*[sk_rw_data] =*/ { 2, S_REGULAR, "__data" },
545+ /*[sk_bss] =*/ { 2, S_ZEROFILL, "__bss" },
546+ /*[sk_linkedit] =*/ { 3, S_REGULAR, NULL },
542547 };
543548
544549 static void collect_sections(TCCState *s1, struct macho *mo)
@@ -663,7 +668,7 @@ static void collect_sections(TCCState *s1, struct macho *mo) · 118 unmodified lines
663668 }
664669 if (sec)
665670 sec->align = al;
666− al = 1U << al;
671+ al = 1ULL << al;
667672 if (al > 4096)
668673 tcc_warning("alignment > 4096"), sec->align = 12, al = 4096;
669674 curaddr = (curaddr + al - 1) & -al;
@@ -779,7 +784,7 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) · 109 unmodified lines
779784 int fd, mode, file_type;
780785 FILE *fp;
781786 int i, ret = -1;
782− struct macho mo = {};
787+ struct macho mo = {0};
783788
784789 file_type = s1->output_type;
785790 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) · 126 unmodified lines
912917 {
913918 struct dylib_command *dc = (struct dylib_command*)lc;
914919 char *name = (char*)lc + dc->name;
915− dprintf(" REEXPORT %s\n", name);
916920 int subfd = open(name, O_RDONLY | O_BINARY);
921+ dprintf(" REEXPORT %s\n", name);
917922 if (subfd < 0)
918923 tcc_warning("can't open %s (reexported from %s)", name, filename);
919924 else {
tests/Makefile+4−1
@@ -73,6 +73,9 @@ ifeq ($(ARCH),i386) · 72 unmodified lines
7373 # by GCC in 32bit mode when PIC is enabled.
7474 test.ref: CFLAGS+=-fno-PIC -fno-PIE
7575 endif
76+ifeq ($(CC_NAME),msvc)
77+test.ref abitest : CC = gcc
78+endif
7679
7780 RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
7881 DISAS = objdump -d
@@ -302,7 +305,7 @@ clean: · 223 unmodified lines
302305 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
303306 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
304307 rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
305− rm -f ex? tcc_g weaktest.*.txt *.def libtcc_test_mt
308+ rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt
306309 @$(MAKE) -C tests2 $@
307310 @$(MAKE) -C pp $@
308311
tests/tcctest.c+8−2
@@ -2,6 +2,10 @@ · 1 unmodified line
22 * TCC auto test program
33 */
44 #include "config.h"
5+#define CC_gcc 1
6+#define CC_clang 2
7+#define CC_tcc 3
8+#define CC_msvc 4 /* cannot compile this file */
59
610 /* Unfortunately, gcc version < 3 does not handle that! */
711 #define ALL_ISOC99
@@ -1829,11 +1833,13 @@ void cast_test() · 1821 unmodified lines
18291833 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
18301834 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
18311835
1836+#if CC_NAME != CC_clang /* doesn't like non-portable conversions */
18321837 /* from pointer to integer types */
18331838 printf("%d %d %ld %ld %lld %lld\n",
1834− (int)(long)p, (unsigned int)(long)p,
1839+ (int)p, (unsigned int)p,
18351840 (long)p, (unsigned long)p,
1836− (long long)(long)p, (unsigned long long)(long)p);
1841+ (long long)p, (unsigned long long)p);
1842+#endif
18371843
18381844 /* from integers to pointers */
18391845 printf("%p %p %p %p\n",
tests/tests2/114_bound_signal.c+5−53
@@ -8,52 +8,6 @@ · 7 unmodified lines
88 #include <errno.h>
99 #include <setjmp.h>
1010
11−#if defined(__APPLE__)
12−/*
13− * clock_nanosleep is missing on all macOS version, add emulation.
14− */
15−
16−/* scale factors */
17−#define TIMING_GIGA 1000000000
18−#define TIMER_ABSTIME 0 /* not used */
19−
20−/* timespec difference (monotonic) right - left */
21−static inline void
22−timespec_monodiff_rml(struct timespec *ts_out, const struct timespec *ts_in) {
23− /*
24− * out = in - out,
25− * where in > out
26− */
27− ts_out->tv_sec = ts_in->tv_sec - ts_out->tv_sec;
28− ts_out->tv_nsec = ts_in->tv_nsec - ts_out->tv_nsec;
29− if (ts_out->tv_sec < 0) {
30− ts_out->tv_sec = 0;
31− ts_out->tv_nsec = 0;
32− } else if (ts_out->tv_nsec < 0) {
33− if (ts_out->tv_sec == 0) {
34− ts_out->tv_sec = 0;
35− ts_out->tv_nsec = 0;
36− } else {
37− ts_out->tv_sec = ts_out->tv_sec - 1;
38− ts_out->tv_nsec = ts_out->tv_nsec + TIMING_GIGA;
39− }
40− }
41−}
42−
43−static inline int
44−clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, struct timespec *remain) {
45− struct timespec ts_delta;
46− int retval = clock_gettime(clock_id, &ts_delta);
47− (void)remain;
48− (void)flags;
49− if (retval == 0) {
50− timespec_monodiff_rml(&ts_delta, req);
51− retval = nanosleep(&ts_delta, NULL);
52− }
53− return retval;
54−}
55−#endif
56−
5711 static volatile int run = 1;
5812 static int dummy[10];
5913 static sem_t sem;
@@ -116,7 +70,6 @@ main (void) · 56 unmodified lines
11670 int i;
11771 pthread_t id1, id2;
11872 struct sigaction act;
119− struct timespec request;
12073 sigjmp_buf sj;
12174 sigset_t m;
12275
@@ -125,17 +78,16 @@ main (void) · 2 unmodified lines
12578 act.sa_flags = 0;
12679 sigemptyset (&act.sa_mask);
12780 sigaction (SIGUSR1, &act, NULL);
81+
12882 sem_init (&sem, 1, 0);
12983 pthread_create(&id1, NULL, high_load, NULL);
13084 pthread_create(&id2, NULL, do_signal, NULL);
131− clock_gettime (CLOCK_MONOTONIC, &request);
132− request.tv_sec += 1;
133− request.tv_nsec += 0;
85+
13486 printf ("start\n");
135− while (clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &request, NULL)) {
136− }
137− printf ("end\n");
87+ sleep(1);
13888 run = 0;
89+ printf ("end\n");
90+
13991 pthread_join(id1, NULL);
14092 pthread_join(id2, NULL);
14193 sem_destroy (&sem);
tests/tests2/Makefile+1−3
@@ -43,9 +43,7 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) · 42 unmodified lines
4343 endif
4444 ifeq (-$(CONFIG_WIN32)-,-yes-)
4545 SKIP += 106_pthread.test # No pthread support
46−endif
47−ifneq (-$(CONFIG_WIN32)-$(findstring $(GCC_MAJOR),3 4)-,---)
48− SKIP += 114_bound_signal.test # not on windows or older linuxes
46+ SKIP += 114_bound_signal.test # No pthread support
4947 endif
5048
5149 # Some tests might need arguments
x86_64-gen.c+8−6
@@ -1289,11 +1289,11 @@ void gfunc_call(int nb_args) · 1288 unmodified lines
12891289 {
12901290 X86_64_Mode mode;
12911291 CType type;
1292− int size, align, r, args_size, stack_adjust, i, reg_count;
1292+ int size, align, r, args_size, stack_adjust, i, reg_count, k;
12931293 int nb_reg_args = 0;
12941294 int nb_sse_args = 0;
12951295 int sse_reg, gen_reg;
1296− char _onstack[nb_args ? nb_args : 1], *onstack = _onstack;
1296+ char *onstack = tcc_malloc((nb_args + 1) * sizeof (char));
12971297
12981298 #ifdef CONFIG_TCC_BCHECK
12991299 if (tcc_state->do_bounds_check)
@@ -1339,9 +1339,9 @@ void gfunc_call(int nb_args) · 39 unmodified lines
13391339 sse_reg = nb_sse_args;
13401340 args_size = 0;
13411341 stack_adjust &= 15;
1342− for (i = 0; i < nb_args;) {
1342+ for (i = k = 0; i < nb_args;) {
13431343 mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, &reg_count);
1344− if (!onstack[i]) {
1344+ if (!onstack[i + k]) {
13451345 ++i;
13461346 continue;
13471347 }
@@ -1354,7 +1354,7 @@ void gfunc_call(int nb_args) · 6 unmodified lines
13541354 args_size += 8;
13551355 stack_adjust = 0;
13561356 }
1357− if (onstack[i] == 2)
1357+ if (onstack[i + k] == 2)
13581358 stack_adjust = 1;
13591359
13601360 vrotb(i+1);
@@ -1404,9 +1404,11 @@ void gfunc_call(int nb_args) · 43 unmodified lines
14041404
14051405 vpop();
14061406 --nb_args;
1407− onstack++;
1407+ k++;
14081408 }
14091409
1410+ tcc_free(onstack);
1411+
14101412 /* XXX This should be superfluous. */
14111413 save_regs(0); /* save used temporary registers */
14121414

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