- 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
Unified · Split
| @@ -25,13 +25,14 @@ CFLAGS += $(CPPFLAGS) · 24 unmodified lines | ||
| 25 | 25 | VPATH = $(TOPSRC) |
| 26 | 26 | |
| 27 | 27 | ifdef CONFIG_WIN32 |
| 28 | + CFG = -win | |
| 28 | 29 | ifneq ($(CONFIG_static),yes) |
| 29 | 30 | LIBTCC = libtcc$(DLLSUF) |
| 30 | 31 | LIBTCCDEF = libtcc.def |
| 31 | 32 | endif |
| 32 | − CFGWIN = -win | |
| 33 | 33 | NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) |
| 34 | 34 | else |
| 35 | + CFG = -unx | |
| 35 | 36 | LIBS=-lm -lpthread |
| 36 | 37 | ifneq ($(CONFIG_ldl),no) |
| 37 | 38 | LIBS+=-ldl |
| @@ -44,21 +45,21 @@ else · 6 unmodified lines | ||
| 44 | 45 | LINK_LIBTCC += -Wl,-rpath,"$(libdir)" |
| 45 | 46 | endif |
| 46 | 47 | endif |
| 47 | − CFGWIN =-unx | |
| 48 | 48 | NATIVE_TARGET = $(ARCH) |
| 49 | 49 | ifdef CONFIG_OSX |
| 50 | 50 | NATIVE_TARGET = $(ARCH)-osx |
| 51 | − ifneq ($(CC),tcc) | |
| 51 | + ifneq ($(CC_NAME),tcc) | |
| 52 | 52 | LDFLAGS += -flat_namespace -undefined warning |
| 53 | 53 | endif |
| 54 | 54 | export MACOSX_DEPLOYMENT_TARGET := 10.6 |
| 55 | + export DYLD_LIBRARY_PATH := $(CURDIR)/$(TOP) | |
| 55 | 56 | endif |
| 56 | 57 | endif |
| 57 | 58 | |
| 58 | 59 | # run local version of tcc with local libraries and includes |
| 59 | 60 | TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) |
| 60 | 61 | TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) |
| 61 | −TCCFLAGS = $(TCCFLAGS$(CFGWIN)) | |
| 62 | +TCCFLAGS = $(TCCFLAGS$(CFG)) | |
| 62 | 63 | TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) |
| 63 | 64 | |
| 64 | 65 | # cross compiler targets to build |
| @@ -110,9 +111,9 @@ cross: $(LIBTCC1_CROSS) $(PROGS_CROSS) · 45 unmodified lines | ||
| 110 | 111 | # build specific cross compiler & lib |
| 111 | 112 | cross-%: %-tcc$(EXESUF) %-libtcc1.a ; |
| 112 | 113 | |
| 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) | |
| 116 | 117 | |
| 117 | 118 | ifdef CONFIG_cross |
| 118 | 119 | all : cross |
| @@ -228,11 +229,7 @@ tcc_p$(EXESUF): $($T_FILES) · 109 unmodified lines | ||
| 228 | 229 | |
| 229 | 230 | # static libtcc library |
| 230 | 231 | libtcc.a: $(LIBTCC_OBJ) |
| 231 | −ifeq ($(CC),tcc) | |
| 232 | − $(CC) -ar rcs $@ $^ | |
| 233 | −else | |
| 234 | 232 | $S$(AR) rcs $@ $^ |
| 235 | −endif | |
| 236 | 233 | |
| 237 | 234 | # dynamic libtcc library |
| 238 | 235 | libtcc.so: $(LIBTCC_OBJ) |
| @@ -943,8 +943,6 @@ struct avail_regs { · 942 unmodified lines | ||
| 943 | 943 | int first_free_reg; /* next free register in the sequence, hole excluded */ |
| 944 | 944 | }; |
| 945 | 945 | |
| 946 | −#define AVAIL_REGS_INITIALIZER (struct avail_regs) { { 0, 0, 0}, 0, 0, 0 } | |
| 947 | − | |
| 948 | 946 | /* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC |
| 949 | 947 | param) according to the rules described in the procedure call standard for |
| 950 | 948 | the ARM architecture (AAPCS). If found, the registers are assigned to this |
| @@ -1060,14 +1058,16 @@ struct param_plan { · 109 unmodified lines | ||
| 1060 | 1058 | struct plan { |
| 1061 | 1059 | struct param_plan *pplans; /* array of all the param plans */ |
| 1062 | 1060 | struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */ |
| 1061 | + int nb_plans; | |
| 1063 | 1062 | }; |
| 1064 | 1063 | |
| 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 | +} | |
| 1071 | 1071 | |
| 1072 | 1072 | /* Assign parameters to registers and stack with alignment according to the |
| 1073 | 1073 | 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 | ||
| 1090 | 1090 | { |
| 1091 | 1091 | int i, size, align; |
| 1092 | 1092 | 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}}; | |
| 1096 | 1094 | |
| 1097 | 1095 | ncrn = nsaa = 0; |
| 1098 | 1096 | *todo = 0; |
| 1099 | − plan->pplans = nb_args ? tcc_malloc(nb_args * sizeof(*plan->pplans)) : NULL; | |
| 1100 | − memset(plan->clsplans, 0, sizeof(plan->clsplans)); | |
| 1097 | + | |
| 1101 | 1098 | for(i = nb_args; i-- ;) { |
| 1102 | 1099 | int j, start_vfpreg = 0; |
| 1103 | 1100 | 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 | ||
| 1120 | 1117 | start_vfpreg = assign_vfpreg(&avregs, align, size); |
| 1121 | 1118 | end_vfpreg = start_vfpreg + ((size - 1) >> 2); |
| 1122 | 1119 | 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]); | |
| 1128 | 1122 | continue; |
| 1129 | 1123 | } else |
| 1130 | 1124 | break; |
| @@ -1137,8 +1131,7 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) · 6 unmodified lines | ||
| 1137 | 1131 | * CORE_STRUCT_CLASS or the first of STACK_CLASS. */ |
| 1138 | 1132 | for (j = ncrn; j < 4 && j < ncrn + size / 4; j++) |
| 1139 | 1133 | *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]); | |
| 1142 | 1135 | ncrn += size/4; |
| 1143 | 1136 | if (ncrn > 4) |
| 1144 | 1137 | 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 | ||
| 1156 | 1149 | if (ncrn == 4) |
| 1157 | 1150 | break; |
| 1158 | 1151 | } |
| 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; | |
| 1164 | 1154 | continue; |
| 1165 | 1155 | } |
| 1166 | 1156 | } |
| 1167 | 1157 | 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]); | |
| 1170 | 1159 | nsaa += size; /* size already rounded up before */ |
| 1171 | 1160 | } |
| 1172 | 1161 | return nsaa; |
| 1173 | 1162 | } |
| 1174 | 1163 | |
| 1175 | −#undef add_param_plan | |
| 1176 | − | |
| 1177 | 1164 | /* Copy parameters to their final destination (core reg, VFP reg or stack) for |
| 1178 | 1165 | function call. |
| 1179 | 1166 | |
| @@ -1378,6 +1365,10 @@ void gfunc_call(int nb_args) · 198 unmodified lines | ||
| 1378 | 1365 | if (r == VT_CMP || (r & ~1) == VT_JMP) |
| 1379 | 1366 | gv(RC_INT); |
| 1380 | 1367 | |
| 1368 | + memset(&plan, 0, sizeof plan); | |
| 1369 | + if (nb_args) | |
| 1370 | + plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans)); | |
| 1371 | + | |
| 1381 | 1372 | args_size = assign_regs(nb_args, float_abi, &plan, &todo); |
| 1382 | 1373 | |
| 1383 | 1374 | #ifdef TCC_ARM_EABI |
| @@ -1420,7 +1411,7 @@ void gfunc_prolog(Sym *func_sym) · 36 unmodified lines | ||
| 1420 | 1411 | CType ret_type; |
| 1421 | 1412 | |
| 1422 | 1413 | #ifdef TCC_ARM_EABI |
| 1423 | − struct avail_regs avregs = AVAIL_REGS_INITIALIZER; | |
| 1414 | + struct avail_regs avregs = {{0}}; | |
| 1424 | 1415 | #endif |
| 1425 | 1416 | |
| 1426 | 1417 | sym = func_type->ref; |
| @@ -1471,7 +1462,7 @@ void gfunc_prolog(Sym *func_sym) · 44 unmodified lines | ||
| 1471 | 1462 | #ifdef TCC_ARM_EABI |
| 1472 | 1463 | if (float_abi == ARM_HARD_FLOAT) { |
| 1473 | 1464 | func_vc += nf * 4; |
| 1474 | − avregs = AVAIL_REGS_INITIALIZER; | |
| 1465 | + memset(&avregs, 0, sizeof avregs); | |
| 1475 | 1466 | } |
| 1476 | 1467 | #endif |
| 1477 | 1468 | pn = struct_ret, sn = 0; |
| @@ -98,6 +98,7 @@ int gotplt_entry_type (int reloc_type) · 97 unmodified lines | ||
| 98 | 98 | return -1; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | +#ifndef TCC_TARGET_PE | |
| 101 | 102 | ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) |
| 102 | 103 | { |
| 103 | 104 | Section *plt = s1->plt; |
| @@ -160,6 +161,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 56 unmodified lines | ||
| 160 | 161 | } |
| 161 | 162 | } |
| 162 | 163 | } |
| 164 | +#endif | |
| 163 | 165 | |
| 164 | 166 | void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) |
| 165 | 167 | { |
| @@ -802,7 +802,7 @@ static int arm64_hfa_aux(CType *type, int *fsize, int num) · 801 unmodified lines | ||
| 802 | 802 | return -1; |
| 803 | 803 | } |
| 804 | 804 | |
| 805 | −static int arm64_hfa(CType *type, int *fsize) | |
| 805 | +static int arm64_hfa(CType *type, unsigned *fsize) | |
| 806 | 806 | { |
| 807 | 807 | if ((type->t & VT_BTYPE) == VT_STRUCT || |
| 808 | 808 | ((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 | ||
| 1086 | 1086 | else if (a[i] < 32) { |
| 1087 | 1087 | // value in floating-point registers |
| 1088 | 1088 | 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); | |
| 1090 | 1090 | vtop->type.t = VT_PTR; |
| 1091 | 1091 | gaddrof(); |
| 1092 | 1092 | gv(RC_R30); |
| @@ -1137,7 +1137,7 @@ ST_FUNC void gfunc_call(int nb_args) · 44 unmodified lines | ||
| 1137 | 1137 | |
| 1138 | 1138 | } |
| 1139 | 1139 | 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); | |
| 1141 | 1141 | for (j = 0; j < n; j++) |
| 1142 | 1142 | o(0x3d000100 | |
| 1143 | 1143 | (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | |
| @@ -1213,7 +1213,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) · 69 unmodified lines | ||
| 1213 | 1213 | |
| 1214 | 1214 | // HFAs of float and double need to be written differently: |
| 1215 | 1215 | 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); | |
| 1217 | 1217 | if (sz < 16) |
| 1218 | 1218 | for (j = 0; j < k; j++) { |
| 1219 | 1219 | o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 | |
| @@ -1277,7 +1277,7 @@ ST_FUNC void gen_va_start(void) · 57 unmodified lines | ||
| 1277 | 1277 | ST_FUNC void gen_va_arg(CType *t) |
| 1278 | 1278 | { |
| 1279 | 1279 | int align, size = type_size(t, &align); |
| 1280 | − int fsize, hfa = arm64_hfa(t, (int *)&fsize); | |
| 1280 | + unsigned fsize, hfa = arm64_hfa(t, &fsize); | |
| 1281 | 1281 | uint32_t r0, r1; |
| 1282 | 1282 | |
| 1283 | 1283 | if (is_float(t->t)) { |
| @@ -1387,7 +1387,7 @@ ST_FUNC void gfunc_return(CType *func_type) · 103 unmodified lines | ||
| 1387 | 1387 | } |
| 1388 | 1388 | case 16: |
| 1389 | 1389 | 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); | |
| 1391 | 1391 | gaddrof(); |
| 1392 | 1392 | gv(RC_R(0)); |
| 1393 | 1393 | for (j = 0; j < n; j++) |
| @@ -48,7 +48,8 @@ cpu= · 47 unmodified lines | ||
| 48 | 48 | cpuver= |
| 49 | 49 | gcc_major=0 |
| 50 | 50 | gcc_minor=0 |
| 51 | −gcc_name="gcc" | |
| 51 | +cc_name="gcc" | |
| 52 | +ar_set= | |
| 52 | 53 | |
| 53 | 54 | # OS specific |
| 54 | 55 | targetos=`uname` |
| @@ -110,7 +111,7 @@ for opt do · 55 unmodified lines | ||
| 110 | 111 | ;; |
| 111 | 112 | --cc=*) cc=`echo $opt | cut -d '=' -f 2` |
| 112 | 113 | ;; |
| 113 | − --ar=*) ar=`echo $opt | cut -d '=' -f 2` | |
| 114 | + --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes" | |
| 114 | 115 | ;; |
| 115 | 116 | --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" |
| 116 | 117 | ;; |
| @@ -226,9 +227,6 @@ if test "$mingw32" = "yes" ; then · 109 unmodified lines | ||
| 226 | 227 | if test "$source_path_used" = "no"; then |
| 227 | 228 | source_path="." |
| 228 | 229 | fi |
| 229 | − if test "${cc%% *}" = "gcc"; then | |
| 230 | − test -z "$LDFLAGS" && LDFLAGS="-static" | |
| 231 | − fi | |
| 232 | 230 | test -z "$prefix" && prefix="C:/Program Files/tcc" |
| 233 | 231 | test -z "$tccdir" && tccdir="${prefix}" |
| 234 | 232 | test -z "$bindir" && bindir="${tccdir}" |
| @@ -323,17 +321,17 @@ if test -z "$cross_prefix" ; then · 88 unmodified lines | ||
| 323 | 321 | if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then |
| 324 | 322 | echo "configure: error: '$cc' failed to compile conftest.c." |
| 325 | 323 | else |
| 324 | + cc_name="$($CONFTEST compiler)" | |
| 326 | 325 | gcc_major="$($CONFTEST version)" |
| 327 | 326 | gcc_minor="$($CONFTEST minor)" |
| 328 | − gcc_name="$($CONFTEST compiler)" | |
| 327 | + bigendian="$($CONFTEST bigendian)" | |
| 328 | + _triplet="$($CONFTEST triplet)" | |
| 329 | 329 | fi |
| 330 | − bigendian="$($CONFTEST bigendian)" | |
| 331 | 330 | if test "$mingw32" = "no" ; then |
| 332 | 331 | |
| 333 | 332 | 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" | |
| 337 | 335 | fi |
| 338 | 336 | fi |
| 339 | 337 | |
| @@ -364,6 +362,11 @@ if test -z "$cross_prefix" ; then · 24 unmodified lines | ||
| 364 | 362 | echo "Perhaps you want ./configure --config-musl" |
| 365 | 363 | fi |
| 366 | 364 | 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 | |
| 367 | 370 | fi |
| 368 | 371 | else |
| 369 | 372 | # if cross compiling, cannot launch a program, so make a static guess |
| @@ -377,11 +380,11 @@ if test "$bigendian" = "yes" ; then · 7 unmodified lines | ||
| 377 | 380 | fi |
| 378 | 381 | |
| 379 | 382 | # a final configuration tuning |
| 380 | −if ! echo "$cc" | grep -q "tcc"; then | |
| 383 | +if test "$cc_name" != "tcc"; then | |
| 381 | 384 | OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" |
| 382 | 385 | # we want -Wno- but gcc does not always reject unknown -Wno- options |
| 383 | 386 | 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 | |
| 385 | 388 | OPT1="$OPT1 -fheinous-gnu-extensions" |
| 386 | 389 | OPT2="$OPT2 -Wstring-plus-int" |
| 387 | 390 | fi |
| @@ -395,6 +398,8 @@ if ! echo "$cc" | grep -q "tcc"; then · 7 unmodified lines | ||
| 395 | 398 | # cat cc_msg.txt |
| 396 | 399 | # echo $CFLAGS |
| 397 | 400 | rm -f cc_msg.txt a.out |
| 401 | +else # cc is tcc | |
| 402 | + test "$ar_set" || ar="$cc -ar" | |
| 398 | 403 | fi |
| 399 | 404 | |
| 400 | 405 | fcho() { if test -n "$2"; then echo "$1$2"; fi } |
| @@ -427,6 +432,7 @@ mandir=\$(DESTDIR)$mandir · 26 unmodified lines | ||
| 427 | 432 | infodir=\$(DESTDIR)$infodir |
| 428 | 433 | docdir=\$(DESTDIR)$docdir |
| 429 | 434 | CC=$cc |
| 435 | +CC_NAME=$cc_name | |
| 430 | 436 | GCC_MAJOR=$gcc_major |
| 431 | 437 | GCC_MINOR=$gcc_minor |
| 432 | 438 | AR=$ar |
| @@ -502,6 +508,7 @@ fi · 69 unmodified lines | ||
| 502 | 508 | cat >>$TMPH <<EOF |
| 503 | 509 | #define GCC_MAJOR $gcc_major |
| 504 | 510 | #define GCC_MINOR $gcc_minor |
| 511 | +#define CC_NAME CC_${cc_name} | |
| 505 | 512 | EOF |
| 506 | 513 | |
| 507 | 514 | diff $TMPH config.h >/dev/null 2>&1 |
| @@ -61,48 +61,57 @@ int main(int argc, char *argv[]) · 60 unmodified lines | ||
| 61 | 61 | _setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */ |
| 62 | 62 | #endif |
| 63 | 63 | switch(argc == 2 ? argv[1][0] : 0) { |
| 64 | − case 'b': | |
| 64 | + case 'b'://igendian | |
| 65 | 65 | { |
| 66 | 66 | volatile unsigned foo = 0x01234567; |
| 67 | 67 | puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); |
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | #if defined(__clang__) |
| 71 | − case 'm': | |
| 71 | + case 'm'://inor | |
| 72 | 72 | printf("%d\n", __clang_minor__); |
| 73 | 73 | break; |
| 74 | − case 'v': | |
| 74 | + case 'v'://ersion | |
| 75 | 75 | printf("%d\n", __clang_major__); |
| 76 | 76 | break; |
| 77 | 77 | #elif defined(__TINYC__) |
| 78 | − case 'v': | |
| 78 | + case 'v'://ersion | |
| 79 | 79 | puts("0"); |
| 80 | 80 | break; |
| 81 | − case 'm': | |
| 81 | + case 'm'://inor | |
| 82 | 82 | printf("%d\n", __TINYC__); |
| 83 | 83 | 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; | |
| 84 | 91 | #elif defined(__GNUC__) && defined(__GNUC_MINOR__) |
| 85 | 92 | /* GNU comes last as other compilers may add 'GNU' compatibility */ |
| 86 | − case 'm': | |
| 93 | + case 'm'://inor | |
| 87 | 94 | printf("%d\n", __GNUC_MINOR__); |
| 88 | 95 | break; |
| 89 | − case 'v': | |
| 96 | + case 'v'://ersion | |
| 90 | 97 | printf("%d\n", __GNUC__); |
| 91 | 98 | break; |
| 92 | 99 | #else |
| 93 | − case 'm': | |
| 94 | − case 'v': | |
| 100 | + case 'm'://inor | |
| 101 | + case 'v'://ersion | |
| 95 | 102 | puts("0"); |
| 96 | 103 | break; |
| 97 | 104 | #endif |
| 98 | − case 't': | |
| 105 | + case 't'://riplet | |
| 99 | 106 | puts(TRIPLET); |
| 100 | 107 | break; |
| 101 | − case 'c': | |
| 108 | + case 'c'://ompiler | |
| 102 | 109 | #if defined(__clang__) |
| 103 | 110 | puts("clang"); |
| 104 | 111 | #elif defined(__TINYC__) |
| 105 | 112 | puts("tcc"); |
| 113 | +#elif defined(_MSC_VER) | |
| 114 | + puts("msvc"); | |
| 106 | 115 | #elif defined(__GNUC__) |
| 107 | 116 | puts("gcc"); |
| 108 | 117 | #else |
| @@ -8,11 +8,7 @@ VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib · 7 unmodified lines | ||
| 8 | 8 | T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) |
| 9 | 9 | X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) |
| 10 | 10 | |
| 11 | −ifdef CONFIG_OSX | |
| 12 | −XTCC ?= DYLD_LIBRARY_PATH=$(TOP) $(TOP)/$(X)tcc$(EXESUF) | |
| 13 | −else | |
| 14 | 11 | XTCC ?= $(TOP)/$(X)tcc$(EXESUF) |
| 15 | −endif | |
| 16 | 12 | XCC = $(XTCC) |
| 17 | 13 | XAR = $(XTCC) -ar |
| 18 | 14 | XFLAGS-unx = -B$(TOPSRC) |
| @@ -578,7 +578,7 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named) · 577 unmodified lines | ||
| 578 | 578 | ST_FUNC void gfunc_call(int nb_args) |
| 579 | 579 | { |
| 580 | 580 | int i, align, size, areg[2]; |
| 581 | − int info[nb_args ? nb_args : 1]; | |
| 581 | + int *info = tcc_malloc((nb_args + 1) * sizeof (int)); | |
| 582 | 582 | int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0; |
| 583 | 583 | SValue *sv; |
| 584 | 584 | Sym *sa; |
| @@ -775,6 +775,7 @@ ST_FUNC void gfunc_call(int nb_args) · 190 unmodified lines | ||
| 775 | 775 | else |
| 776 | 776 | EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj |
| 777 | 777 | } |
| 778 | + tcc_free(info); | |
| 778 | 779 | } |
| 779 | 780 | |
| 780 | 781 | static int func_sub_sp_offset, num_va_regs, func_va_list_ofs; |
| @@ -57,8 +57,8 @@ static int asm2cname(int v, int *addeddot) · 56 unmodified lines | ||
| 57 | 57 | v = tok_alloc(name + 1, strlen(name) - 1)->tok; |
| 58 | 58 | } else if (!strchr(name, '.')) { |
| 59 | 59 | 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); | |
| 62 | 62 | v = tok_alloc(newname, n - 1)->tok; |
| 63 | 63 | *addeddot = 1; |
| 64 | 64 | } |
| @@ -4978,7 +4978,7 @@ the_end: · 4977 unmodified lines | ||
| 4978 | 4978 | bt = t & (VT_BTYPE|VT_LONG); |
| 4979 | 4979 | if (bt == VT_LONG) |
| 4980 | 4980 | t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; |
| 4981 | −#ifdef TCC_TARGET_PE | |
| 4981 | +#if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER) | |
| 4982 | 4982 | if (bt == VT_LDOUBLE) |
| 4983 | 4983 | t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG); |
| 4984 | 4984 | #endif |
| @@ -530,15 +530,20 @@ struct { · 529 unmodified lines | ||
| 530 | 530 | uint32_t flags; |
| 531 | 531 | char *name; |
| 532 | 532 | } 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 | |
| 534 | 536 | | 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 }, | |
| 542 | 547 | }; |
| 543 | 548 | |
| 544 | 549 | 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 | ||
| 663 | 668 | } |
| 664 | 669 | if (sec) |
| 665 | 670 | sec->align = al; |
| 666 | − al = 1U << al; | |
| 671 | + al = 1ULL << al; | |
| 667 | 672 | if (al > 4096) |
| 668 | 673 | tcc_warning("alignment > 4096"), sec->align = 12, al = 4096; |
| 669 | 674 | curaddr = (curaddr + al - 1) & -al; |
| @@ -779,7 +784,7 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) · 109 unmodified lines | ||
| 779 | 784 | int fd, mode, file_type; |
| 780 | 785 | FILE *fp; |
| 781 | 786 | int i, ret = -1; |
| 782 | − struct macho mo = {}; | |
| 787 | + struct macho mo = {0}; | |
| 783 | 788 | |
| 784 | 789 | file_type = s1->output_type; |
| 785 | 790 | 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 | ||
| 912 | 917 | { |
| 913 | 918 | struct dylib_command *dc = (struct dylib_command*)lc; |
| 914 | 919 | char *name = (char*)lc + dc->name; |
| 915 | − dprintf(" REEXPORT %s\n", name); | |
| 916 | 920 | int subfd = open(name, O_RDONLY | O_BINARY); |
| 921 | + dprintf(" REEXPORT %s\n", name); | |
| 917 | 922 | if (subfd < 0) |
| 918 | 923 | tcc_warning("can't open %s (reexported from %s)", name, filename); |
| 919 | 924 | else { |
| @@ -73,6 +73,9 @@ ifeq ($(ARCH),i386) · 72 unmodified lines | ||
| 73 | 73 | # by GCC in 32bit mode when PIC is enabled. |
| 74 | 74 | test.ref: CFLAGS+=-fno-PIC -fno-PIE |
| 75 | 75 | endif |
| 76 | +ifeq ($(CC_NAME),msvc) | |
| 77 | +test.ref abitest : CC = gcc | |
| 78 | +endif | |
| 76 | 79 | |
| 77 | 80 | RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) |
| 78 | 81 | DISAS = objdump -d |
| @@ -302,7 +305,7 @@ clean: · 223 unmodified lines | ||
| 302 | 305 | rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc |
| 303 | 306 | rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] |
| 304 | 307 | 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 | |
| 306 | 309 | @$(MAKE) -C tests2 $@ |
| 307 | 310 | @$(MAKE) -C pp $@ |
| 308 | 311 | |
| @@ -2,6 +2,10 @@ · 1 unmodified line | ||
| 2 | 2 | * TCC auto test program |
| 3 | 3 | */ |
| 4 | 4 | #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 */ | |
| 5 | 9 | |
| 6 | 10 | /* Unfortunately, gcc version < 3 does not handle that! */ |
| 7 | 11 | #define ALL_ISOC99 |
| @@ -1829,11 +1833,13 @@ void cast_test() · 1821 unmodified lines | ||
| 1829 | 1833 | printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a')); |
| 1830 | 1834 | printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a')); |
| 1831 | 1835 | |
| 1836 | +#if CC_NAME != CC_clang /* doesn't like non-portable conversions */ | |
| 1832 | 1837 | /* from pointer to integer types */ |
| 1833 | 1838 | printf("%d %d %ld %ld %lld %lld\n", |
| 1834 | − (int)(long)p, (unsigned int)(long)p, | |
| 1839 | + (int)p, (unsigned int)p, | |
| 1835 | 1840 | (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 | |
| 1837 | 1843 | |
| 1838 | 1844 | /* from integers to pointers */ |
| 1839 | 1845 | printf("%p %p %p %p\n", |
| @@ -8,52 +8,6 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <errno.h> |
| 9 | 9 | #include <setjmp.h> |
| 10 | 10 | |
| 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 | − | |
| 57 | 11 | static volatile int run = 1; |
| 58 | 12 | static int dummy[10]; |
| 59 | 13 | static sem_t sem; |
| @@ -116,7 +70,6 @@ main (void) · 56 unmodified lines | ||
| 116 | 70 | int i; |
| 117 | 71 | pthread_t id1, id2; |
| 118 | 72 | struct sigaction act; |
| 119 | − struct timespec request; | |
| 120 | 73 | sigjmp_buf sj; |
| 121 | 74 | sigset_t m; |
| 122 | 75 | |
| @@ -125,17 +78,16 @@ main (void) · 2 unmodified lines | ||
| 125 | 78 | act.sa_flags = 0; |
| 126 | 79 | sigemptyset (&act.sa_mask); |
| 127 | 80 | sigaction (SIGUSR1, &act, NULL); |
| 81 | + | |
| 128 | 82 | sem_init (&sem, 1, 0); |
| 129 | 83 | pthread_create(&id1, NULL, high_load, NULL); |
| 130 | 84 | pthread_create(&id2, NULL, do_signal, NULL); |
| 131 | − clock_gettime (CLOCK_MONOTONIC, &request); | |
| 132 | − request.tv_sec += 1; | |
| 133 | − request.tv_nsec += 0; | |
| 85 | + | |
| 134 | 86 | printf ("start\n"); |
| 135 | − while (clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &request, NULL)) { | |
| 136 | − } | |
| 137 | − printf ("end\n"); | |
| 87 | + sleep(1); | |
| 138 | 88 | run = 0; |
| 89 | + printf ("end\n"); | |
| 90 | + | |
| 139 | 91 | pthread_join(id1, NULL); |
| 140 | 92 | pthread_join(id2, NULL); |
| 141 | 93 | sem_destroy (&sem); |
| @@ -43,9 +43,7 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) · 42 unmodified lines | ||
| 43 | 43 | endif |
| 44 | 44 | ifeq (-$(CONFIG_WIN32)-,-yes-) |
| 45 | 45 | 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 | |
| 49 | 47 | endif |
| 50 | 48 | |
| 51 | 49 | # Some tests might need arguments |
| @@ -1289,11 +1289,11 @@ void gfunc_call(int nb_args) · 1288 unmodified lines | ||
| 1289 | 1289 | { |
| 1290 | 1290 | X86_64_Mode mode; |
| 1291 | 1291 | 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; | |
| 1293 | 1293 | int nb_reg_args = 0; |
| 1294 | 1294 | int nb_sse_args = 0; |
| 1295 | 1295 | 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)); | |
| 1297 | 1297 | |
| 1298 | 1298 | #ifdef CONFIG_TCC_BCHECK |
| 1299 | 1299 | if (tcc_state->do_bounds_check) |
| @@ -1339,9 +1339,9 @@ void gfunc_call(int nb_args) · 39 unmodified lines | ||
| 1339 | 1339 | sse_reg = nb_sse_args; |
| 1340 | 1340 | args_size = 0; |
| 1341 | 1341 | stack_adjust &= 15; |
| 1342 | − for (i = 0; i < nb_args;) { | |
| 1342 | + for (i = k = 0; i < nb_args;) { | |
| 1343 | 1343 | mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, ®_count); |
| 1344 | − if (!onstack[i]) { | |
| 1344 | + if (!onstack[i + k]) { | |
| 1345 | 1345 | ++i; |
| 1346 | 1346 | continue; |
| 1347 | 1347 | } |
| @@ -1354,7 +1354,7 @@ void gfunc_call(int nb_args) · 6 unmodified lines | ||
| 1354 | 1354 | args_size += 8; |
| 1355 | 1355 | stack_adjust = 0; |
| 1356 | 1356 | } |
| 1357 | − if (onstack[i] == 2) | |
| 1357 | + if (onstack[i + k] == 2) | |
| 1358 | 1358 | stack_adjust = 1; |
| 1359 | 1359 | |
| 1360 | 1360 | vrotb(i+1); |
| @@ -1404,9 +1404,11 @@ void gfunc_call(int nb_args) · 43 unmodified lines | ||
| 1404 | 1404 | |
| 1405 | 1405 | vpop(); |
| 1406 | 1406 | --nb_args; |
| 1407 | − onstack++; | |
| 1407 | + k++; | |
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | + tcc_free(onstack); | |
| 1411 | + | |
| 1410 | 1412 | /* XXX This should be superfluous. */ |
| 1411 | 1413 | save_regs(0); /* save used temporary registers */ |
| 1412 | 1414 | |