History

various stuff

win32/Makefile ("for cygwin") removed - On cygwin, the normal ./configure && make can be used with either cygwin's "GCC for Win32 Toolchain" ./configure --cross-prefix=i686-w64-mingw32- or with an existing tcc: ./configure --cc=<old-tccdir>/tcc.exe tcctest.c: - exclude test_high_clobbers() on _WIN64 (does not work) tests2/95_bitfield.c: - use 'signed char' for ARM (where default 'char' is unsigned) tests: - remove -I "expr" diff option to allow tests with busybox-diff. libtcc.c, tcc.c: - removed -iwithprefix option. It is supposed to be combined with -iprefix which we don't have either. tccgen.c: - fix assignments and return of 'void', as in void f() { void *p, *q; *p = *q: return *p; } This appears to be allowed but should do nothing. tcc.h, libtcc.c, tccpp.c: - Revert "Introduce VIP sysinclude paths which are always searched first" This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1. The patch was giving tcc's system includes priority over -I which is not how it should be. tccelf.c: - add DT_TEXTREL tag only if text relocations are actually used (which is likely not the case on x86_64) - prepare_dynamic_rel(): avoid relocation of unresolved (weak) symbols tccrun.c: - for HAVE_SELINUX, use two mappings to the same (real) file. (it was so once except the RX mapping wasn't used at all). tccpe.c: - fix relocation constant used for x86_64 (by Andrei E. Warentin) - #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin. tccasm.c: - keep forward asm labels static, otherwise they will endup in dynsym eventually. configure, Makefile: - mingw32: respect ./configure options --bindir --docdir --libdir - allow overriding tcc when building libtcc1.a and libtcc.def with make XTCC=<tcc program to use> - use $(wildcard ...) for install to allow installing just a cross compiler for example make cross-arm make install - use name <target>-libtcc1.a build-tcc.bat: - add options: -clean, -b bindir

grischka committed 9 years ago

Commit da8c62f1 parent faa974430 files · +426 −656Browse files

Unified · Split

30 files
  1. Makefile +53 −58
  2. configure +26 −42
  3. include/stdarg.h +0 −5
  4. lib/Makefile +7 −7
  5. libtcc.c +11 −28
  6. libtcc.h +0 −3
  7. tcc.c +2 −3
  8. tcc.h +8 −23
  9. tccasm.c +2 −0
  10. tccelf.c +94 −116
  11. tccgen.c +27 −11
  12. tccpe.c +15 −20
  13. tccpp.c +23 −28
  14. tccrun.c +36 −17
  15. tcctok.h +7 −9
  16. tests/Makefile +4 −0
  17. tests/pp/13.expect +0 −1
  18. tests/pp/15.c +2 −2
  19. tests/pp/15.expect +0 −2
  20. tests/pp/Makefile +2 −2
  21. tests/tcctest.c +3 −4
  22. tests/tests2/95_bitfields.c +1 −1
  23. tests/tests2/96_nodata_wanted.c +1 −1
  24. tests/tests2/96_nodata_wanted.expect +0 −2
  25. tests/tests2/Makefile +1 −1
  26. win32/Makefile +0 −148
  27. win32/build-tcc.bat +59 −48
  28. win32/lib/crt1.c +6 −15
  29. win32/lib/wincrt1.c +29 −47
  30. win32/tcc-win32.txt +7 −12
Makefile+53−58
@@ -98,16 +98,17 @@ TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 · 97 unmodified lines
9898 LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
9999
100100 PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
101−LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)
101+LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)
102102
103103 # build cross compilers & libs
104104 cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
105105
106106 # build specific cross compiler & lib
107−cross-%: %-tcc$(EXESUF) libtcc1-%.a ;
107+cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
108108
109−install: install$(CFGWIN)
110−uninstall: uninstall$(CFGWIN)
109+install: ; @$(MAKE) --no-print-directory install$(CFGWIN)
110+install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes
111+uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN)
111112
112113 ifdef CONFIG_cross
113114 all : cross
@@ -143,10 +144,10 @@ DEFINES += $(DEF-$(or $(findstring win,$T),unx)) · 29 unmodified lines
143144
144145 ifneq ($(X),)
145146 ifeq ($(CONFIG_WIN32),yes)
146−DEF-win += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
147−DEF-unx += -DTCC_LIBTCC1="\"lib/libtcc1-$T.a\""
147+DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
148+DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\""
148149 else
149−DEF-all += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
150+DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
150151 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
151152 endif
152153 endif
@@ -217,21 +218,22 @@ libtcc.so: LDFLAGS+=-fPIC · 64 unmodified lines
217218 # windows dynamic libtcc library
218219 libtcc.dll : $(LIBTCC_OBJ)
219220 $(CC) -shared -o $@ $^ $(LDFLAGS)
221+libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
220222
223+# import file for windows libtcc.dll
221224 libtcc.def : libtcc.dll tcc$(EXESUF)
222− ./tcc$(EXESUF) -impdef $< -o $@
223−
224−libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
225+ $(XTCC) -impdef $< -o $@
226+XTCC ?= ./tcc$(EXESUF)
225227
226228 # TinyCC runtime libraries
227229 libtcc1.a : tcc$(EXESUF) FORCE
228− @$(MAKE) -C lib DEFINES="$(DEF-$T)"
230+ @$(MAKE) -C lib DEFINES='$(DEF-$T)'
229231
230232 # Cross libtcc1.a
231−libtcc1-%.a : %-tcc$(EXESUF) FORCE
232− @$(MAKE) -C lib DEFINES="$(DEF-$*)" CROSS_TARGET=$*
233+%-libtcc1.a : %-tcc$(EXESUF) FORCE
234+ @$(MAKE) -C lib DEFINES='$(DEF-$*)' CROSS_TARGET=$*
233235
234−.PRECIOUS: libtcc1-%.a
236+.PRECIOUS: %-libtcc1.a
235237 FORCE:
236238
237239 # --------------------------------------------------------------------------
@@ -252,35 +254,29 @@ tcc-doc.info: tcc-doc.texi · 14 unmodified lines
252254 INSTALL = install -m644
253255 INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
254256 STRIP_yes = -s
255−install-strip: install
256−install-strip: CONFIG_strip = yes
257257
258−TRY-INSTALL = $(if $(wildcard $1),mkdir -p $2 && $(INSTALL) $1 $2)
259−LIBTCC1_W = $(wildcard $(filter %-win32.a %-wince.a,$(LIBTCC1_CROSS)))
260−LIBTCC1_U = $(wildcard $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)))
261−PROGS_X = $(wildcard $(PROGS_CROSS))
258+LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS))
259+LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS))
260+IB = $(if $1,mkdir -p $2 && $(INSTALLBIN) $1 $2)
261+IBw = $(call IB,$(wildcard $1),$2)
262+IF = $(if $1,mkdir -p $2 && $(INSTALL) $1 $2)
263+IFw = $(call IF,$(wildcard $1),$2)
264+IR = mkdir -p $2 && cp -r $1/. $2
262265
263266 # install progs & libs
264267 install-unx:
265− mkdir -p "$(bindir)"
266− $(INSTALLBIN) $(PROGS) $(PROGS_X) "$(bindir)"
267− mkdir -p "$(tccdir)"
268− $(INSTALL) $(LIBTCC1) $(LIBTCC1_U) "$(tccdir)"
269− mkdir -p "$(tccdir)/include"
270− $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
271− mkdir -p "$(libdir)"
272− $(INSTALL) $(LIBTCC) "$(libdir)"
273− mkdir -p "$(includedir)"
274− $(INSTALL) $(TOPSRC)/libtcc.h "$(includedir)"
275− $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
276− $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
277− $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
278−ifneq "$(LIBTCC1_W)" ""
279− mkdir -p "$(tccdir)/win32/lib"
280− $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
281− mkdir -p "$(tccdir)/win32/include"
282− cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
283− $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/win32/include"
268+ $(call IBw,$(PROGS) $(PROGS_CROSS),"$(bindir)")
269+ $(call IFw,$(LIBTCC1) $(LIBTCC1_U),"$(tccdir)")
270+ $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
271+ $(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)")
272+ $(call IF,$(TOPSRC)/libtcc.h,"$(includedir)")
273+ $(call IFw,tcc.1,"$(mandir)/man1")
274+ $(call IFw,tcc-doc.info,"$(infodir)")
275+ $(call IFw,tcc-doc.html,"$(docdir)")
276+ifneq "$(wildcard $(LIBTCC1_W))" ""
277+ $(call IFw,$(TOPSRC)/win32/lib/*.def $(LIBTCC1_W),"$(tccdir)/win32/lib")
278+ $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/win32/include")
279+ $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/win32/include")
284280 endif
285281
286282 # uninstall
@@ -293,32 +289,31 @@ uninstall-unx: · 6 unmodified lines
293289
294290 # install progs & libs on windows
295291 install-win:
296− mkdir -p "$(tccdir)"
297− $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
298− mkdir -p "$(tccdir)/lib"
299− $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
300− $(INSTALL) libtcc1.a $(LIBTCC1_W) "$(tccdir)/lib"
301− mkdir -p "$(tccdir)/include"
302− cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
303− $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
304− mkdir -p "$(tccdir)/examples"
305− cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
306− $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
307− mkdir -p "$(tccdir)/libtcc"
308− $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
309− mkdir -p "$(tccdir)/doc"
310− $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
311−ifneq "$(LIBTCC1_U)" ""
312− $(INSTALL) $(LIBTCC1_U) "$(tccdir)/lib"
313− mkdir -p "$(tccdir)/lib/include";
314− $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
292+ $(call IBw,$(PROGS) $(PROGS_CROSS) $(subst libtcc.a,,$(LIBTCC)),"$(bindir)")
293+ $(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib")
294+ $(call IFw,libtcc1.a $(LIBTCC1_W),"$(tccdir)/lib")
295+ $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
296+ $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include")
297+ $(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples")
298+ $(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples")
299+ $(call IFw,$(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)),"$(libdir)")
300+ $(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)")
301+ifneq "$(wildcard $(LIBTCC1_U))" ""
302+ $(call IFw,$(LIBTCC1_U),"$(tccdir)/lib")
303+ $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include")
315304 endif
316305
317306 # the msys-git shell works to configure && make except it does not have install
307+ifeq ($(CONFIG_WIN32)-$(shell which install >/dev/null 2>&1 || echo no),yes-no)
318308 install-win : INSTALL = cp
309+install-win : INSTALLBIN = cp
310+endif
319311
320312 # uninstall on windows
321313 uninstall-win:
314+ @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS) libtcc.dll,"$(bindir)/$P")
315+ @rm -fv $(foreach F,tcc-doc.html tcc-win32.txt,"$(docdir)/$F")
316+ @rm -fv $(foreach F,libtcc.h libtcc.def libtcc.a,"$(libdir)/$F")
322317 rm -r "$(tccdir)"
323318
324319 # --------------------------------------------------------------------------
configure+26−42
@@ -56,7 +56,6 @@ case $targetos in · 55 unmodified lines
5656 DLLSUF=".dylib"
5757 ;;
5858 MINGW*|MSYS*|CYGWIN*)
59− confvars="$confvars WIN32"
6059 mingw32=yes
6160 ;;
6261 DragonFly|OpenBSD|FreeBSD|NetBSD)
@@ -126,8 +125,6 @@ for opt do · 63 unmodified lines
126125 ;;
127126 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
128127 ;;
129− --enable-mingw32) confvars="$confvars WIN32"; mingw32="yes"
130− ;;
131128 --enable-cross) confvars="$confvars cross"
132129 ;;
133130 --disable-static) confvars="$confvars static=no"
@@ -142,6 +139,8 @@ for opt do · 8 unmodified lines
142139 ;;
143140 --with-selinux) confvars="$confvars selinux"
144141 ;;
142+ --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
143+ ;;
145144 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
146145 ;;
147146 --help|-h) show_help="yes"
@@ -216,22 +215,12 @@ if test "$mingw32" = "yes" ; then · 68 unmodified lines
216215 if test "$cc" = gcc; then
217216 test -z "$LDFLAGS" && LDFLAGS="-static"
218217 fi
219− if test x"$tccdir" = x""; then
220− tccdir="tcc"
221− fi
222− if test -z "$prefix" ; then
223− prefix="C:/Program Files/${tccdir}"
224− fi
225− if test -z "$sharedir" ; then
226− sharedir="${prefix}"
227− fi
228− execprefix="$prefix"
229− bindir="${prefix}"
230− tccdir="${prefix}"
231− libdir="${prefix}/lib"
232− docdir="${sharedir}/doc"
233− mandir="${sharedir}/man"
234− infodir="${sharedir}/info"
218+ test -z "$prefix" && prefix="C:/Program Files/tcc"
219+ test -z "$tccdir" && tccdir="${prefix}"
220+ test -z "$bindir" && bindir="${tccdir}"
221+ test -z "$docdir" && docdir="${tccdir}/doc"
222+ test -z "$libdir" && libdir="${tccdir}/libtcc"
223+ confvars="$confvars WIN32"
235224 LIBSUF=".lib"
236225 EXESUF=".exe"
237226 DLLSUF=".dll"
@@ -263,12 +252,11 @@ else · 25 unmodified lines
263252 if test x"$tccdir" = x""; then
264253 tccdir="${libdir}/tcc"
265254 fi
255+ if test x"$includedir" = x""; then
256+ includedir="${prefix}/include"
257+ fi
266258 fi # mingw32
267259
268−if test x"$includedir" = x""; then
269− includedir="${prefix}/include"
270−fi
271−
272260 if test x"$show_help" = "xyes" ; then
273261 cat << EOF
274262 Usage: configure [options]
@@ -302,7 +290,6 @@ Advanced options (experts only): · 27 unmodified lines
302290 --enable-static make libtcc.a instead of libtcc.dll (win32)
303291 --disable-rpath disable use of -rpath with the above
304292 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
305− --enable-mingw32 build windows version on linux with mingw32
306293 --enable-cross build cross compilers
307294 --with-selinux use mmap for executable memory (with tcc -run)
308295 --sysincludepaths=... specify system include paths, colon separated
@@ -310,7 +297,7 @@ Advanced options (experts only): · 1 unmodified line
310297 --crtprefix=... specify locations of crt?.o, colon separated
311298 --elfinterp=... specify elf interpreter
312299 --triplet=... specify system library/include directory triplet
313− --config-uClibc,-musl... enable specific configuration for some systems
300+ --config-uClibc,-musl,-mingw32... enable system specific configurations
314301 EOF
315302 #echo "NOTE: The object files are build at the place where configure is launched"
316303 exit 1
@@ -320,15 +307,14 @@ cc="${cross_prefix}${cc}" · 3 unmodified lines
320307 ar="${cross_prefix}${ar}"
321308 strip="${cross_prefix}${strip}"
322309
323−CONFTEST=./conftest$EXESUF
324−if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
325− echo "configure: error: '$cc' failed to compile conftest.c."
326−else
327− gcc_major="$($CONFTEST version)"
328− gcc_minor="$($CONFTEST minor)"
329−fi
330−
331310 if test -z "$cross_prefix" ; then
311+ CONFTEST=./conftest$EXESUF
312+ if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
313+ echo "configure: error: '$cc' failed to compile conftest.c."
314+ else
315+ gcc_major="$($CONFTEST version)"
316+ gcc_minor="$($CONFTEST minor)"
317+ fi
332318 bigendian="$($CONFTEST bigendian)"
333319 if test "$mingw32" = "no" ; then
334320
@@ -401,13 +387,13 @@ fi · 66 unmodified lines
401387
402388 fcho() { if test -n "$2"; then echo "$1$2"; fi }
403389
404−echo "Binary directory $bindir"
405−echo "TinyCC directory $tccdir"
406−echo "Library directory $libdir"
407−echo "Include directory $includedir"
408−echo "Manual directory $mandir"
409−echo "Info directory $infodir"
410−echo "Doc directory $docdir"
390+fcho "Binary directory " "$bindir"
391+fcho "TinyCC directory " "$tccdir"
392+fcho "Library directory " "$libdir"
393+fcho "Include directory " "$includedir"
394+fcho "Manual directory " "$mandir"
395+fcho "Info directory " "$infodir"
396+fcho "Doc directory " "$docdir"
411397 fcho "Target root prefix " "$sysroot"
412398 echo "Source path $source_path"
413399 echo "C compiler $cc ($gcc_major.$gcc_minor)"
@@ -471,8 +457,6 @@ print_mak CONFIG_LDDIR "$tcc_lddir" · 57 unmodified lines
471457 print_mak CONFIG_TRIPLET "$triplet"
472458 print_mak_int TCC_CPU_VERSION "$cpuver"
473459
474−echo "#define GCC_MAJOR $gcc_major" >> $TMPH
475−echo "#define GCC_MINOR $gcc_minor" >> $TMPH
476460 if test "$cpu" = "aarch64" ; then
477461 echo "ARCH=arm64" >> config.mak
478462 else
include/stdarg.h+0−5
@@ -16,12 +16,7 @@ typedef struct { · 15 unmodified lines
1616 char *reg_save_area;
1717 } __va_list_struct;
1818
19−/* Avoid conflicting definition for va_list on musl libc */
20−#if !defined __DEFINED_va_list || defined __TCC_NEEDS_va_list
2119 typedef __va_list_struct va_list[1];
22−#undef __DEFINED_va_list
23−#define __DEFINED_va_list
24−#endif
2520
2621 void __va_start(__va_list_struct *ap, void *fp);
2722 void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
lib/Makefile+7−7
@@ -7,20 +7,20 @@ include $(TOP)/Makefile · 6 unmodified lines
77 VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
88 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
99 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
10−BIN = $(TOP)/libtcc1$(if $(CROSS_TARGET),-$(CROSS_TARGET)).a
10+BIN = $(TOP)/$(X)libtcc1.a
1111
12−TCC = $(TOP)/$(X)tcc$(EXESUF)
13−XCC = $(TCC)
14−XAR = $(TCC) -ar
12+XTCC ?= $(TOP)/$(X)tcc$(EXESUF)
13+XCC = $(XTCC)
14+XAR = $(XTCC) -ar
1515 XFLAGS-unx = -B$(TOPSRC)
1616 XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include
1717 XFLAGS = $(XFLAGS$(XCFG))
1818 XCFG = $(or $(findstring -win,$T),-unx)
1919
20−# in order to use gcc, tyoe: make <target>lib-usegcc=yes
21−armlib-usegcc ?= no
20+# in order to use gcc, tyoe: make <target>-libtcc1-usegcc=yes
21+arm-libtcc1-usegcc ?= no
2222
23−ifeq "$($(X)$(T)lib-usegcc)" "yes"
23+ifeq "$($(T)-libtcc1-usegcc)" "yes"
2424 XCC = $(CC)
2525 XAR = $(AR)
2626 XFLAGS = $(CFLAGS) -fPIC
libtcc.c+11−28
@@ -104,10 +104,8 @@ static void tcc_set_lib_path_w32(TCCState *s) · 103 unmodified lines
104104 char path[1024], *p;
105105 GetModuleFileNameA(tcc_module, path, sizeof path);
106106 p = tcc_basename(normalize_slashes(strlwr(path)));
107− if (p - 5 > path && 0 == strncmp(p - 5, "/bin/", 5))
108− p -= 5;
109− else if (p > path)
110− p--;
107+ if (p > path)
108+ --p;
111109 *p = 0;
112110 tcc_set_lib_path(s, path);
113111 }
@@ -440,7 +438,7 @@ static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char * · 326 unmodified lines
440438 CString str;
441439
442440 cstr_new(&str);
443− for (p = in; c = *p, c != '\0' && c != PATHSEP; ++p) {
441+ for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) {
444442 if (c == '{' && p[1] && p[2] == '}') {
445443 c = p[1], p += 2;
446444 if (c == 'B')
@@ -804,6 +802,8 @@ LIBTCCAPI TCCState *tcc_new(void) · 357 unmodified lines
804802 #endif
805803 #elif defined(TCC_TARGET_ARM64)
806804 tcc_define_symbol(s, "__aarch64__", NULL);
805+#elif defined TCC_TARGET_C67
806+ tcc_define_symbol(s, "__C67__", NULL);
807807 #endif
808808
809809 #ifdef TCC_TARGET_PE
@@ -827,13 +827,13 @@ LIBTCCAPI TCCState *tcc_new(void) · 17 unmodified lines
827827 # if defined(__FreeBSD_kernel__)
828828 tcc_define_symbol(s, "__FreeBSD_kernel__", NULL);
829829 # endif
830−#endif
831830 # if defined(__NetBSD__)
832831 tcc_define_symbol(s, "__NetBSD__", "__NetBSD__");
833832 # endif
834833 # if defined(__OpenBSD__)
835834 tcc_define_symbol(s, "__OpenBSD__", "__OpenBSD__");
836835 # endif
836+#endif
837837
838838 /* TinyCC & gcc defines */
839839 #if PTR_SIZE == 4
@@ -853,14 +853,6 @@ LIBTCCAPI TCCState *tcc_new(void) · 13 unmodified lines
853853 tcc_define_symbol(s, "__LP64__", NULL);
854854 #endif
855855
856−#if defined(TCC_MUSL)
857− tcc_define_symbol(s, "__TCC_NEEDS_va_list", "");
858− tcc_define_symbol(s, "__builtin_va_list", "va_list");
859− tcc_define_symbol(s, "__DEFINED_va_list", "");
860− tcc_define_symbol(s, "__DEFINED___isoc_va_list", "");
861− tcc_define_symbol(s, "__isoc_va_list", "void *");
862−#endif /* TCC_MUSL */
863−
864856 #ifdef TCC_TARGET_PE
865857 tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short");
866858 tcc_define_symbol(s, "__WINT_TYPE__", "unsigned short");
@@ -887,6 +879,11 @@ LIBTCCAPI TCCState *tcc_new(void) · 20 unmodified lines
887879 tcc_define_symbol(s, "__REDIRECT_NTH(name, proto, alias)",
888880 "name proto __asm__ (#alias) __THROW");
889881 # endif
882+# if defined(TCC_MUSL)
883+ tcc_define_symbol(s, "__DEFINED_va_list", "");
884+ tcc_define_symbol(s, "__DEFINED___isoc_va_list", "");
885+ tcc_define_symbol(s, "__isoc_va_list", "void *");
886+# endif /* TCC_MUSL */
890887 /* Some GCC builtins that are simple to express as macros. */
891888 tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x");
892889 #endif /* ndef TCC_TARGET_PE */
@@ -906,7 +903,6 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 13 unmodified lines
906903
907904 /* free include paths */
908905 dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes);
909− dynarray_reset(&s1->tccinclude_paths, &s1->nb_tccinclude_paths);
910906 dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
911907 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
912908 dynarray_reset(&s1->cmd_include_files, &s1->nb_cmd_include_files);
@@ -947,7 +943,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 34 unmodified lines
947943 if (!s->nostdinc) {
948944 /* default include paths */
949945 /* -isystem paths have already been handled */
950− tcc_add_tccinclude_path(s, CONFIG_TCC_TCCINCLUDEPATHS);
951946 tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
952947 }
953948
@@ -985,12 +980,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 31 unmodified lines
985980 return 0;
986981 }
987982
988−LIBTCCAPI int tcc_add_tccinclude_path(TCCState *s, const char *pathname)
989−{
990− tcc_split_path(s, &s->tccinclude_paths, &s->nb_tccinclude_paths, pathname);
991− return 0;
992−}
993−
994983 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
995984 {
996985 tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
@@ -1547,7 +1536,6 @@ static const TCCOption tcc_options[] = { · 550 unmodified lines
15471536 { "m", TCC_OPTION_m, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
15481537 { "f", TCC_OPTION_f, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
15491538 { "isystem", TCC_OPTION_isystem, TCC_OPTION_HAS_ARG },
1550− { "iwithprefix", TCC_OPTION_iwithprefix, TCC_OPTION_HAS_ARG },
15511539 { "include", TCC_OPTION_include, TCC_OPTION_HAS_ARG },
15521540 { "nostdinc", TCC_OPTION_nostdinc, 0 },
15531541 { "nostdlib", TCC_OPTION_nostdlib, 0 },
@@ -1682,7 +1670,6 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind) · 128 unmodified lines
16821670 int last_o = -1;
16831671 int x;
16841672 CString linker_arg; /* collect -Wl options */
1685− char buf[1024];
16861673 int tool = 0, arg_start = 0, noaction = optind;
16871674 char **argv = *pargv;
16881675 int argc = *pargc;
@@ -1827,10 +1814,6 @@ reparse: · 138 unmodified lines
18271814 case TCC_OPTION_isystem:
18281815 tcc_add_sysinclude_path(s, optarg);
18291816 break;
1830− case TCC_OPTION_iwithprefix:
1831− snprintf(buf, sizeof buf, "{B}/%s", optarg);
1832− tcc_add_tccinclude_path(s, buf);
1833− break;
18341817 case TCC_OPTION_include:
18351818 dynarray_add(&s->cmd_include_files,
18361819 &s->nb_cmd_include_files, tcc_strdup(optarg));
libtcc.h+0−3
@@ -32,9 +32,6 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *str); · 31 unmodified lines
3232 /*****************************/
3333 /* preprocessor */
3434
35−/* add in tcc include path, searched before anything else */
36−LIBTCCAPI int tcc_add_tccinclude_path(TCCState *s, const char *pathname);
37−
3835 /* add include path */
3936 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
4037
tcc.c+2−3
@@ -86,7 +86,6 @@ static const char help2[] = · 85 unmodified lines
8686 " -Wp,-opt same as -opt\n"
8787 " -include file include 'file' above each input file\n"
8888 " -isystem dir add 'dir' to system include path\n"
89− " -iwithprefix dir set tcc's private include/library subdir\n"
9089 " -static link to static libraries (not recommended)\n"
9190 " -dumpversion print version\n"
9291 " -print-search-dirs print search paths\n"
@@ -181,7 +180,6 @@ static void print_search_dirs(TCCState *s) · 88 unmodified lines
181180 {
182181 printf("install: %s\n", s->tcc_lib_path);
183182 /* print_dirs("programs", NULL, 0); */
184− print_dirs("tcc-include", s->tccinclude_paths, s->nb_tccinclude_paths);
185183 print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
186184 print_dirs("libraries", s->library_paths, s->nb_library_paths);
187185 #ifndef TCC_TARGET_PE
@@ -197,7 +195,7 @@ static void set_environment(TCCState *s) · 9 unmodified lines
197195
198196 path = getenv("C_INCLUDE_PATH");
199197 if(path != NULL) {
200− tcc_add_include_path(s, path);
198+ tcc_add_sysinclude_path(s, path);
201199 }
202200 path = getenv("CPATH");
203201 if(path != NULL) {
@@ -278,6 +276,7 @@ redo: · 74 unmodified lines
278276 return 0;
279277 if (opt == OPT_PRINT_DIRS) {
280278 /* initialize search dirs */
279+ set_environment(s);
281280 tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
282281 print_search_dirs(s);
283282 return 0;
tcc.h+8−23
@@ -101,10 +101,12 @@ extern long double strtold (const char *__nptr, char **__endptr); · 100 unmodified lines
101101 # define IS_DIRSEP(c) (c == '/' || c == '\\')
102102 # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
103103 # define PATHCMP stricmp
104+# define PATHSEP ";"
104105 #else
105106 # define IS_DIRSEP(c) (c == '/')
106107 # define IS_ABSPATH(p) IS_DIRSEP(p[0])
107108 # define PATHCMP strcmp
109+# define PATHSEP ":"
108110 #endif
109111
110112 /* -------------------------------------------- */
@@ -195,21 +197,14 @@ extern long double strtold (const char *__nptr, char **__endptr); · 84 unmodified lines
195197 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
196198
197199 /* system include paths */
198−#ifndef CONFIG_TCC_TCCINCLUDEPATHS
200+#ifndef CONFIG_TCC_SYSINCLUDEPATHS
199201 # ifdef TCC_TARGET_PE
200−# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include;{B}/include/winapi"
202+# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi"
201203 # else
202−# define CONFIG_TCC_TCCINCLUDEPATHS "{B}/include"
203−# endif
204−#endif
205−
206−#ifndef CONFIG_TCC_SYSINCLUDEPATHS
207−# ifndef TCC_TARGET_PE
208204 # define CONFIG_TCC_SYSINCLUDEPATHS \
209− ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
205+ "{B}/include" \
206+ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
210207 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
211−# else
212−# define CONFIG_TCC_SYSINCLUDEPATHS ""
213208 # endif
214209 #endif
215210
@@ -283,12 +278,6 @@ extern long double strtold (const char *__nptr, char **__endptr); · 67 unmodified lines
283278 #define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
284279 #endif
285280
286−#ifdef TCC_TARGET_PE
287−#define PATHSEP ';'
288−#else
289−#define PATHSEP ':'
290−#endif
291−
292281 /* -------------------------------------------- */
293282
294283 #include "libtcc.h"
@@ -722,10 +711,7 @@ struct TCCState { · 427 unmodified lines
722711 DLLReference **loaded_dlls;
723712 int nb_loaded_dlls;
724713
725− /* include paths, search order */
726− char **tccinclude_paths;
727− int nb_tccinclude_paths;
728−
714+ /* include paths */
729715 char **include_paths;
730716 int nb_include_paths;
731717
@@ -1616,7 +1602,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str); · 884 unmodified lines
16161602 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
16171603 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
16181604 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
1619−#ifndef TCC_TARGET_ARM
1605+#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
16201606 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
16211607 #endif
16221608 #ifdef TCC_TARGET_X86_64
@@ -1628,7 +1614,6 @@ PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp); · 5 unmodified lines
16281614 # define ST_PE_IMPORT 0x20
16291615 # define ST_PE_STDCALL 0x40
16301616 #endif
1631−
16321617 /* ------------ tccrun.c ----------------- */
16331618 #ifdef TCC_IS_NATIVE
16341619 #ifdef CONFIG_TCC_STATIC
tccasm.c+2−0
@@ -75,6 +75,8 @@ ST_FUNC Sym* get_asm_sym(int name, Sym *csym) · 74 unmodified lines
7575 sym->type.t &= ~VT_EXTERN;
7676 /* Mark that this asm symbol doesn't need to be fed back. */
7777 sym->a.dllimport = 1;
78+ } else {
79+ sym->type.t |= VT_STATIC;
7880 }
7981 }
8082 return sym;
tccelf.c+94−116
@@ -828,6 +828,12 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 827 unmodified lines
828828 switch(type) {
829829 #if defined(TCC_TARGET_I386)
830830 case R_386_32:
831+ if (!get_sym_attr(s1, sym_index, 0)->dyn_index
832+ && ((ElfW(Sym)*)symtab_section->data + sym_index)->st_shndx == SHN_UNDEF) {
833+ /* don't fixup unresolved (weak) symbols */
834+ rel->r_info = ELFW(R_INFO)(sym_index, R_386_RELATIVE);
835+ break;
836+ }
831837 #elif defined(TCC_TARGET_X86_64)
832838 case R_X86_64_32:
833839 case R_X86_64_32S:
@@ -1238,14 +1244,6 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 404 unmodified lines
12381244 }
12391245 }
12401246
1241−#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1242−#define HAVE_PHDR 1
1243−#define EXTRA_RELITEMS 14
1244−#else
1245−#define HAVE_PHDR 1
1246−#define EXTRA_RELITEMS 9
1247−#endif
1248−
12491247 ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel)
12501248 {
12511249 int sym_index = ELFW(R_SYM) (rel->r_info);
@@ -1413,13 +1411,12 @@ static void bind_libs_dynsyms(TCCState *s1) · 161 unmodified lines
14131411 for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) {
14141412 name = (char *) s1->dynsymtab_section->link->data + esym->st_name;
14151413 sym_index = find_elf_sym(symtab_section, name);
1416− /* XXX: avoid adding a symbol if already present because of
1417− -rdynamic ? */
14181414 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
1419− if (sym_index && sym->st_shndx != SHN_UNDEF)
1420− set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
1421− 0, sym->st_shndx, name);
1422− else if (esym->st_shndx == SHN_UNDEF) {
1415+ if (sym_index && sym->st_shndx != SHN_UNDEF
1416+ && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
1417+ set_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
1418+ sym->st_info, 0, sym->st_shndx, name);
1419+ } else if (esym->st_shndx == SHN_UNDEF) {
14231420 /* weak symbols can stay undefined */
14241421 if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK)
14251422 tcc_warning("undefined dynamic symbol '%s'", name);
@@ -1451,10 +1448,11 @@ static void export_global_syms(TCCState *s1) · 25 unmodified lines
14511448 /* Allocate strings for section names and decide if an unallocated section
14521449 should be output.
14531450 NOTE: the strsec section comes last, so its size is also correct ! */
1454−static void alloc_sec_names(TCCState *s1, int file_type, Section *strsec)
1451+static int alloc_sec_names(TCCState *s1, int file_type, Section *strsec)
14551452 {
14561453 int i;
14571454 Section *s;
1455+ int textrel = 0;
14581456
14591457 /* Allocate strings for section names */
14601458 for(i = 1; i < s1->nb_sections; i++) {
@@ -1463,12 +1461,11 @@ static void alloc_sec_names(TCCState *s1, int file_type, Section *strsec) · 2 unmodified lines
14631461 patch them */
14641462 if (file_type == TCC_OUTPUT_DLL &&
14651463 s->sh_type == SHT_RELX &&
1466− !(s->sh_flags & SHF_ALLOC)) {
1467− /* gr: avoid bogus relocs for empty (debug) sections */
1468− if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC)
1469− prepare_dynamic_rel(s1, s);
1470− else if (s1->do_debug)
1471− s->sh_size = s->data_offset;
1464+ !(s->sh_flags & SHF_ALLOC) &&
1465+ (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC) &&
1466+ prepare_dynamic_rel(s1, s)) {
1467+ if (s1->sections[s->sh_info]->sh_flags & SHF_EXECINSTR)
1468+ textrel = 1;
14721469 } else if (s1->do_debug ||
14731470 file_type == TCC_OUTPUT_OBJ ||
14741471 (s->sh_flags & SHF_ALLOC) ||
@@ -1480,13 +1477,14 @@ static void alloc_sec_names(TCCState *s1, int file_type, Section *strsec) · 5 unmodified lines
14801477 s->sh_name = put_elf_str(strsec, s->name);
14811478 }
14821479 strsec->sh_size = strsec->data_offset;
1480+ return textrel;
14831481 }
14841482
14851483 /* Info to be copied in dynamic section */
14861484 struct dyn_inf {
14871485 Section *dynamic;
14881486 Section *dynstr;
1489− unsigned long dyn_rel_off;
1487+ unsigned long data_offset;
14901488 addr_t rel_addr;
14911489 addr_t rel_size;
14921490 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@@ -1542,7 +1540,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 49 unmodified lines
15421540 the program header table itself if needed. These are done later as
15431541 they require section layout to be done first. */
15441542 if (interp)
1545− ph += 1 + HAVE_PHDR;
1543+ ph += 2;
15461544
15471545 /* dynamic relocation table information, for .dynamic section */
15481546 dyninf->rel_addr = dyninf->rel_size = 0;
@@ -1684,19 +1682,14 @@ static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp, · 135 unmodified lines
16841682 if (interp) {
16851683 ph = &phdr[0];
16861684
1687− if (HAVE_PHDR)
1688− {
1689− int len = phnum * sizeof(ElfW(Phdr));
1690−
1691− ph->p_type = PT_PHDR;
1692− ph->p_offset = sizeof(ElfW(Ehdr));
1693− ph->p_vaddr = interp->sh_addr - len;
1694− ph->p_paddr = ph->p_vaddr;
1695− ph->p_filesz = ph->p_memsz = len;
1696− ph->p_flags = PF_R | PF_X;
1697− ph->p_align = 4; /* interp->sh_addralign; */
1698− ph++;
1699− }
1685+ ph->p_type = PT_PHDR;
1686+ ph->p_offset = sizeof(ElfW(Ehdr));
1687+ ph->p_filesz = ph->p_memsz = phnum * sizeof(ElfW(Phdr));
1688+ ph->p_vaddr = interp->sh_addr - ph->p_filesz;
1689+ ph->p_paddr = ph->p_vaddr;
1690+ ph->p_flags = PF_R | PF_X;
1691+ ph->p_align = 4; /* interp->sh_addralign; */
1692+ ph++;
17001693
17011694 ph->p_type = PT_INTERP;
17021695 ph->p_offset = interp->sh_offset;
@@ -1727,12 +1720,9 @@ static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp, · 24 unmodified lines
17271720 sections */
17281721 static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf)
17291722 {
1730− Section *dynamic;
1731−
1732− dynamic = dyninf->dynamic;
1723+ Section *dynamic = dyninf->dynamic;
17331724
17341725 /* put dynamic section entries */
1735− dynamic->data_offset = dyninf->dyn_rel_off;
17361726 put_dt(dynamic, DT_HASH, s1->dynsym->hash->sh_addr);
17371727 put_dt(dynamic, DT_STRTAB, dyninf->dynstr->sh_addr);
17381728 put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr);
@@ -2009,22 +1999,20 @@ static int elf_output_file(TCCState *s1, const char *filename) · 270 unmodified lines
20091999 ElfW(Phdr) *phdr;
20102000 ElfW(Sym) *sym;
20112001 Section *strsec, *interp, *dynamic, *dynstr;
2002+ int textrel;
20122003
20132004 file_type = s1->output_type;
20142005 s1->nb_errors = 0;
2015−
2016− /* if linking, also link in runtime libraries (libc, libgcc, etc.) */
2017− if (file_type != TCC_OUTPUT_OBJ) {
2018− tcc_add_runtime(s1);
2019− }
2020−
2006+ ret = -1;
20212007 phdr = NULL;
20222008 sec_order = NULL;
20232009 interp = dynamic = dynstr = NULL; /* avoid warning */
2010+ textrel = 0;
20242011
20252012 if (file_type != TCC_OUTPUT_OBJ) {
2013+ /* if linking, also link in runtime libraries (libc, libgcc, etc.) */
2014+ tcc_add_runtime(s1);
20262015 relocate_common_syms();
2027−
20282016 tcc_add_linker_symbols(s1);
20292017
20302018 if (!s1->static_link) {
@@ -2057,52 +2045,69 @@ static int elf_output_file(TCCState *s1, const char *filename) · 26 unmodified lines
20572045
20582046 if (file_type == TCC_OUTPUT_EXE) {
20592047 bind_exe_dynsyms(s1);
2060−
2061− if (s1->nb_errors) {
2062− ret = -1;
2048+ if (s1->nb_errors)
20632049 goto the_end;
2064− }
2065−
20662050 bind_libs_dynsyms(s1);
2067− } else /* shared library case: simply export all global symbols */
2051+ } else {
2052+ /* shared library case: simply export all global symbols */
20682053 export_global_syms(s1);
2054+ }
2055+ }
2056+ build_got_entries(s1);
2057+ }
20692058
2070− build_got_entries(s1);
2059+ /* we add a section for symbols */
2060+ strsec = new_section(s1, ".shstrtab", SHT_STRTAB, 0);
2061+ put_elf_str(strsec, "");
20712062
2072− /* add a list of needed dlls */
2073− for(i = 0; i < s1->nb_loaded_dlls; i++) {
2074− DLLReference *dllref = s1->loaded_dlls[i];
2075− if (dllref->level == 0)
2076− put_dt(dynamic, DT_NEEDED, put_elf_str(dynstr, dllref->name));
2077− }
2063+ /* Allocate strings for section names */
2064+ textrel = alloc_sec_names(s1, file_type, strsec);
20782065
2079− if (s1->rpath)
2080− put_dt(dynamic, s1->enable_new_dtags ? DT_RUNPATH : DT_RPATH,
2081− put_elf_str(dynstr, s1->rpath));
2066+ if (dynamic) {
2067+ /* add a list of needed dlls */
2068+ for(i = 0; i < s1->nb_loaded_dlls; i++) {
2069+ DLLReference *dllref = s1->loaded_dlls[i];
2070+ if (dllref->level == 0)
2071+ put_dt(dynamic, DT_NEEDED, put_elf_str(dynstr, dllref->name));
2072+ }
20822073
2074+ if (s1->rpath)
2075+ put_dt(dynamic, s1->enable_new_dtags ? DT_RUNPATH : DT_RPATH,
2076+ put_elf_str(dynstr, s1->rpath));
2077+
2078+ if (file_type == TCC_OUTPUT_DLL) {
2079+ if (s1->soname)
2080+ put_dt(dynamic, DT_SONAME, put_elf_str(dynstr, s1->soname));
20832081 /* XXX: currently, since we do not handle PIC code, we
20842082 must relocate the readonly segments */
2085− if (file_type == TCC_OUTPUT_DLL) {
2086− if (s1->soname)
2087− put_dt(dynamic, DT_SONAME, put_elf_str(dynstr, s1->soname));
2083+ if (textrel)
20882084 put_dt(dynamic, DT_TEXTREL, 0);
2089− }
2085+ }
20902086
2091− if (s1->symbolic)
2092− put_dt(dynamic, DT_SYMBOLIC, 0);
2087+ if (s1->symbolic)
2088+ put_dt(dynamic, DT_SYMBOLIC, 0);
20932089
2094− /* add necessary space for other entries */
2095− dyninf.dyn_rel_off = dynamic->data_offset;
2096− dynamic->data_offset += sizeof(ElfW(Dyn)) * EXTRA_RELITEMS;
2097− } else {
2098− /* still need to build got entries in case of static link */
2099− build_got_entries(s1);
2100− }
2090+ dyninf.dynamic = dynamic;
2091+ dyninf.dynstr = dynstr;
2092+ /* remember offset and reserve space for 2nd call below */
2093+ dyninf.data_offset = dynamic->data_offset;
2094+ fill_dynamic(s1, &dyninf);
2095+ dynamic->sh_size = dynamic->data_offset;
2096+ dynstr->sh_size = dynstr->data_offset;
21012097 }
21022098
2103− /* we add a section for symbols */
2104− strsec = new_section(s1, ".shstrtab", SHT_STRTAB, 0);
2105− put_elf_str(strsec, "");
2099+ /* compute number of program headers */
2100+ if (file_type == TCC_OUTPUT_OBJ)
2101+ phnum = 0;
2102+ else if (file_type == TCC_OUTPUT_DLL)
2103+ phnum = 3;
2104+ else if (s1->static_link)
2105+ phnum = 2;
2106+ else
2107+ phnum = 5;
2108+
2109+ /* allocate program segment headers */
2110+ phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr)));
21062111
21072112 /* compute number of sections */
21082113 shnum = s1->nb_sections;
@@ -2111,41 +2116,16 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2 unmodified lines
21112116 sec_order = tcc_malloc(sizeof(int) * shnum);
21122117 sec_order[0] = 0;
21132118
2114− /* compute number of program headers */
2115− switch(file_type) {
2116− default:
2117− case TCC_OUTPUT_OBJ:
2118− phnum = 0;
2119− break;
2120− case TCC_OUTPUT_EXE:
2121− if (!s1->static_link)
2122− phnum = 4 + HAVE_PHDR;
2123− else
2124− phnum = 2;
2125− break;
2126− case TCC_OUTPUT_DLL:
2127− phnum = 3;
2128− break;
2129− }
2130−
2131− /* Allocate strings for section names */
2132− alloc_sec_names(s1, file_type, strsec);
2133−
2134− /* allocate program segment headers */
2135− phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr)));
2136−
21372119 /* compute section to program header mapping */
21382120 file_offset = layout_sections(s1, phdr, phnum, interp, strsec, &dyninf,
21392121 sec_order);
21402122
21412123 /* Fill remaining program header and finalize relocation related to dynamic
21422124 linking. */
2143− if (phnum > 0) {
2125+ if (file_type != TCC_OUTPUT_OBJ) {
21442126 fill_unloadable_phdr(phdr, phnum, interp, dynamic);
21452127 if (dynamic) {
2146− dyninf.dynamic = dynamic;
2147− dyninf.dynstr = dynstr;
2148−
2128+ dynamic->data_offset = dyninf.data_offset;
21492129 fill_dynamic(s1, &dyninf);
21502130
21512131 /* put in GOT the dynamic section address and relocate PLT */
@@ -2162,22 +2142,20 @@ static int elf_output_file(TCCState *s1, const char *filename) · 10 unmodified lines
21622142 }
21632143 }
21642144 }
2165− }
21662145
2167− /* if building executable or DLL, then relocate each section
2168− except the GOT which is already relocated */
2169− if (file_type != TCC_OUTPUT_OBJ) {
2146+ /* if building executable or DLL, then relocate each section
2147+ except the GOT which is already relocated */
21702148 ret = final_sections_reloc(s1);
21712149 if (ret)
21722150 goto the_end;
21732151 tidy_section_headers(s1, sec_order);
2174− }
21752152
2176− /* Perform relocation to GOT or PLT entries */
2177− if (file_type == TCC_OUTPUT_EXE && s1->static_link)
2178− fill_got(s1);
2179− else if (s1->got)
2180− fill_local_got_entries(s1);
2153+ /* Perform relocation to GOT or PLT entries */
2154+ if (file_type == TCC_OUTPUT_EXE && s1->static_link)
2155+ fill_got(s1);
2156+ else if (s1->got)
2157+ fill_local_got_entries(s1);
2158+ }
21812159
21822160 /* Create the ELF file with name 'filename' */
21832161 ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order);
tccgen.c+27−11
@@ -116,6 +116,12 @@ ST_FUNC int ieee_finite(double d) · 115 unmodified lines
116116 return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
117117 }
118118
119+/* compiling intel long double natively */
120+#if (defined __i386__ || defined __x86_64__) \
121+ && (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64)
122+# define TCC_IS_NATIVE_387
123+#endif
124+
119125 ST_FUNC void test_lvalue(void)
120126 {
121127 if (!(vtop->r & VT_LVAL))
@@ -267,9 +273,6 @@ ST_FUNC int tccgen_compile(TCCState *s1) · 145 unmodified lines
267273 parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR;
268274 next();
269275 decl(VT_CONST);
270− if (tok != TOK_EOF)
271− expect("declaration");
272−
273276 gen_inline_functions(s1);
274277 check_vstack();
275278 /* end of translation unit info */
@@ -2411,6 +2414,9 @@ static void gen_cast(CType *type) · 2135 unmodified lines
24112414 df = is_float(dbt);
24122415 c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
24132416 p = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM);
2417+#if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387
2418+ c &= dbt != VT_LDOUBLE;
2419+#endif
24142420 if (c) {
24152421 /* constant case: we can do it now */
24162422 /* XXX: in ISOC, cannot do it if error in convert */
@@ -3096,6 +3102,8 @@ ST_FUNC void vstore(void) · 679 unmodified lines
30963102 /* ... and discard */
30973103 vpop();
30983104 }
3105+ } else if (dbt == VT_VOID) {
3106+ --vtop;
30993107 } else {
31003108 #ifdef CONFIG_TCC_BCHECK
31013109 /* bound check case */
@@ -5925,7 +5933,10 @@ static void block(int *bsym, int *csym, int is_expr) · 2823 unmodified lines
59255933 if (tok != ';') {
59265934 gexpr();
59275935 gen_assign_cast(&func_vt);
5928− gfunc_return(&func_vt);
5936+ if ((func_vt.t & VT_BTYPE) == VT_VOID)
5937+ vtop--;
5938+ else
5939+ gfunc_return(&func_vt);
59295940 }
59305941 skip(';');
59315942 /* jump unless last stmt in top-level block */
@@ -6483,7 +6494,7 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 551 unmodified lines
64836494 *(double *)ptr = vtop->c.d;
64846495 break;
64856496 case VT_LDOUBLE:
6486−#if (defined __i386__ || defined __x86_64__) && (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64)
6497+#if defined TCC_IS_NATIVE_387
64876498 if (sizeof (long double) >= 10) /* zero pad ten-byte LD */
64886499 memcpy(ptr, &vtop->c.ld, 10);
64896500 #ifdef __TINYC__
@@ -7091,17 +7102,22 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 601 unmodified lines
70917102 next();
70927103 continue;
70937104 }
7094− if (l == VT_CONST &&
7095− (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
7105+ if (l != VT_CONST)
7106+ break;
7107+ if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
70967108 /* global asm block */
70977109 asm_global_instr();
70987110 continue;
70997111 }
7100− /* special test for old K&R protos without explicit int
7101− type. Only accepted when defining global data */
7102− if (l != VT_CONST || tok < TOK_UIDENT)
7112+ if (tok >= TOK_UIDENT) {
7113+ /* special test for old K&R protos without explicit int
7114+ type. Only accepted when defining global data */
7115+ btype.t = VT_INT;
7116+ } else {
7117+ if (tok != TOK_EOF)
7118+ expect("declaration");
71037119 break;
7104− btype.t = VT_INT;
7120+ }
71057121 }
71067122 if (tok == ';') {
71077123 if ((btype.t & VT_BTYPE) == VT_STRUCT) {
tccpe.c+15−20
@@ -26,10 +26,12 @@ · 25 unmodified lines
2626 #ifndef _WIN32
2727 #define stricmp strcasecmp
2828 #define strnicmp strncasecmp
29+#include <sys/stat.h> /* chmod() */
2930 #endif
3031
3132 #ifdef TCC_TARGET_X86_64
3233 # define ADDR3264 ULONGLONG
34+# define PE_IMAGE_REL IMAGE_REL_BASED_DIR64
3335 # define REL_TYPE_DIRECT R_X86_64_64
3436 # define R_XXX_THUNKFIX R_X86_64_PC32
3537 # define R_XXX_RELATIVE R_X86_64_RELATIVE
@@ -38,6 +40,7 @@ · 2 unmodified lines
3840
3941 #elif defined TCC_TARGET_ARM
4042 # define ADDR3264 DWORD
43+# define PE_IMAGE_REL IMAGE_REL_BASED_HIGHLOW
4144 # define REL_TYPE_DIRECT R_ARM_ABS32
4245 # define R_XXX_THUNKFIX R_ARM_ABS32
4346 # define R_XXX_RELATIVE R_ARM_RELATIVE
@@ -46,6 +49,7 @@ · 2 unmodified lines
4649
4750 #elif defined TCC_TARGET_I386
4851 # define ADDR3264 DWORD
52+# define PE_IMAGE_REL IMAGE_REL_BASED_HIGHLOW
4953 # define REL_TYPE_DIRECT R_386_32
5054 # define R_XXX_THUNKFIX R_386_32
5155 # define R_XXX_RELATIVE R_386_RELATIVE
@@ -54,22 +58,6 @@ · 2 unmodified lines
5458
5559 #endif
5660
57−#if 0
58−#ifdef _WIN32
59−void dbg_printf (const char *fmt, ...)
60−{
61− char buffer[4000];
62− va_list arg;
63− int x;
64− va_start(arg, fmt);
65− x = vsprintf (buffer, fmt, arg);
66− strcpy(buffer+x, "\n");
67− OutputDebugString(buffer);
68−}
69−#endif
70−#endif
71−
72−/* ----------------------------------------------------------- */
7361 #ifndef IMAGE_NT_SIGNATURE
7462 /* ----------------------------------------------------------- */
7563 /* definitions below are from winnt.h */
@@ -241,14 +229,19 @@ typedef struct _IMAGE_BASE_RELOCATION { · 165 unmodified lines
241229 #define IMAGE_REL_BASED_MIPS_JMPADDR 5
242230 #define IMAGE_REL_BASED_SECTION 6
243231 #define IMAGE_REL_BASED_REL32 7
232+#define IMAGE_REL_BASED_DIR64 10
244233
245234 #pragma pack(pop)
246235
247236 /* ----------------------------------------------------------- */
248237 #endif /* ndef IMAGE_NT_SIGNATURE */
249238 /* ----------------------------------------------------------- */
250−#pragma pack(push, 1)
251239
240+#ifndef IMAGE_REL_BASED_DIR64
241+# define IMAGE_REL_BASED_DIR64 10
242+#endif
243+
244+#pragma pack(push, 1)
252245 struct pe_header
253246 {
254247 IMAGE_DOS_HEADER doshdr;
@@ -281,7 +274,6 @@ struct pe_rsrc_reloc { · 26 unmodified lines
281274 DWORD size;
282275 WORD type;
283276 };
284−
285277 #pragma pack(pop)
286278
287279 /* ------------------------------------------------------------- */
@@ -732,6 +724,9 @@ static int pe_write(struct pe_info *pe) · 444 unmodified lines
732724 fseek(op, offsetof(struct pe_header, opthdr.CheckSum), SEEK_SET);
733725 pe_fwrite(&pe_header.opthdr.CheckSum, sizeof pe_header.opthdr.CheckSum, op, NULL);
734726 fclose (op);
727+#ifndef _WIN32
728+ chmod(pe->filename, 0777);
729+#endif
735730
736731 if (2 == pe->s1->verbose)
737732 printf("-------------------------------\n");
@@ -1017,7 +1012,7 @@ static void pe_build_reloc (struct pe_info *pe) · 279 unmodified lines
10171012 }
10181013 if ((addr -= offset) < (1<<12)) { /* one block spans 4k addresses */
10191014 WORD *wp = section_ptr_add(pe->reloc, sizeof (WORD));
1020− *wp = addr | IMAGE_REL_BASED_HIGHLOW<<12;
1015+ *wp = addr | PE_IMAGE_REL<<12;
10211016 ++count;
10221017 continue;
10231018 }
@@ -1471,7 +1466,7 @@ static void pe_print_sections(TCCState *s1, const char *fname) · 447 unmodified lines
14711466 /* ------------------------------------------------------------- */
14721467 /* helper function for load/store to insert one more indirection */
14731468
1474−#ifndef TCC_TARGET_ARM
1469+#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
14751470 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2)
14761471 {
14771472 int r2;
tccpp.c+23−28
@@ -591,7 +591,7 @@ ST_FUNC int handle_eob(void) · 590 unmodified lines
591591
592592 /* only tries to read if really end of buffer */
593593 if (bf->buf_ptr >= bf->buf_end) {
594− if (bf->fd != -1) {
594+ if (bf->fd >= 0) {
595595 #if defined(PARSE_DEBUG)
596596 len = 1;
597597 #else
@@ -1803,8 +1803,7 @@ ST_FUNC void preprocess(int is_bof) · 1205 unmodified lines
18031803 /* store current file in stack, but increment stack later below */
18041804 *s1->include_stack_ptr = file;
18051805 i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0;
1806− n = 2 + s1->nb_tccinclude_paths + s1->nb_include_paths +
1807− s1->nb_sysinclude_paths;
1806+ n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
18081807 for (; i < n; ++i) {
18091808 char buf1[sizeof file->filename];
18101809 CachedInclude *e;
@@ -1826,14 +1825,8 @@ ST_FUNC void preprocess(int is_bof) · 15 unmodified lines
18261825
18271826 } else {
18281827 /* search in all the include paths */
1829− int k, j = i - 2;
1830−
1831− if (j < (k = s1->nb_tccinclude_paths))
1832− path = s1->tccinclude_paths[j];
1833− else if ((j -= k) < s1->nb_include_paths)
1834− path = s1->include_paths[j];
1835− else if ((j -= s1->nb_include_paths) < s1->nb_sysinclude_paths)
1836− path = s1->sysinclude_paths[j];
1828+ int j = i - 2, k = j - s1->nb_include_paths;
1829+ path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
18371830 pstrcpy(buf1, sizeof(buf1), path);
18381831 pstrcat(buf1, sizeof(buf1), "/");
18391832 }
@@ -2635,6 +2628,8 @@ static inline void next_nomacro1(void) · 795 unmodified lines
26352628 tcc_close();
26362629 s1->include_stack_ptr--;
26372630 p = file->buf_ptr;
2631+ if (p == file->buffer)
2632+ tok_flags = TOK_FLAG_BOF|TOK_FLAG_BOL;
26382633 goto redo_no_start;
26392634 }
26402635 }
@@ -2968,7 +2963,7 @@ maybe_newline: · 327 unmodified lines
29682963 keep_tok_flags:
29692964 file->buf_ptr = p;
29702965 #if defined(PARSE_DEBUG)
2971− printf("token = %s\n", get_tok_str(tok, &tokc));
2966+ printf("token = %d %s\n", tok, get_tok_str(tok, &tokc));
29722967 #endif
29732968 }
29742969
@@ -3585,7 +3580,8 @@ ST_INLN void unget_tok(int last_tok) · 610 unmodified lines
35853580
35863581 ST_FUNC void preprocess_start(TCCState *s1, int is_asm)
35873582 {
3588− char *buf;
3583+ CString cstr;
3584+ int i;
35893585
35903586 s1->include_stack_ptr = s1->include_stack;
35913587 s1->ifdef_stack_ptr = s1->ifdef_stack;
@@ -3601,25 +3597,24 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm) · 9 unmodified lines
36013597 set_idnum('$', s1->dollars_in_identifiers ? IS_ID : 0);
36023598 set_idnum('.', is_asm ? IS_ID : 0);
36033599
3604− buf = tcc_malloc(3 + strlen(file->filename));
3605− sprintf(buf, "\"%s\"", file->filename);
3606− tcc_define_symbol(s1, "__BASE_FILE__", buf);
3607− tcc_free(buf);
3608−
3609− if (s1->nb_cmd_include_files) {
3610− CString cstr;
3611− int i;
3612− cstr_new(&cstr);
3613− for (i = 0; i < s1->nb_cmd_include_files; i++) {
3614− cstr_cat(&cstr, "#include \"", -1);
3615− cstr_cat(&cstr, s1->cmd_include_files[i], -1);
3616− cstr_cat(&cstr, "\"\n", -1);
3617− }
3600+ cstr_new(&cstr);
3601+ cstr_cat(&cstr, "\"", -1);
3602+ cstr_cat(&cstr, file->filename, -1);
3603+ cstr_cat(&cstr, "\"", 0);
3604+ tcc_define_symbol(s1, "__BASE_FILE__", cstr.data);
3605+
3606+ cstr_reset(&cstr);
3607+ for (i = 0; i < s1->nb_cmd_include_files; i++) {
3608+ cstr_cat(&cstr, "#include \"", -1);
3609+ cstr_cat(&cstr, s1->cmd_include_files[i], -1);
3610+ cstr_cat(&cstr, "\"\n", -1);
3611+ }
3612+ if (cstr.size) {
36183613 *s1->include_stack_ptr++ = file;
36193614 tcc_open_bf(s1, "<command line>", cstr.size);
36203615 memcpy(file->buffer, cstr.data, cstr.size);
3621− cstr_free(&cstr);
36223616 }
3617+ cstr_free(&cstr);
36233618
36243619 if (is_asm)
36253620 tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
tccrun.c+36−17
@@ -45,15 +45,13 @@ static void set_exception_handler(void); · 44 unmodified lines
4545 #endif
4646
4747 static void set_pages_executable(void *ptr, unsigned long length);
48−static int tcc_relocate_ex(TCCState *s1, void *ptr);
48+static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff);
4949
5050 #ifdef _WIN64
5151 static void *win64_add_function_table(TCCState *s1);
5252 static void win64_del_function_table(void *);
5353 #endif
5454
55−// #define HAVE_SELINUX
56−
5755 /* ------------------------------------------------------------- */
5856 /* Do all relocations (needed before using tcc_get_symbol())
5957 Returns -1 on error. */
@@ -61,25 +59,36 @@ static void win64_del_function_table(void *); · 1 unmodified line
6159 LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
6260 {
6361 int size;
62+ addr_t ptr_diff = 0;
6463
6564 if (TCC_RELOCATE_AUTO != ptr)
66− return tcc_relocate_ex(s1, ptr);
65+ return tcc_relocate_ex(s1, ptr, 0);
6766
68− size = tcc_relocate_ex(s1, NULL);
67+ size = tcc_relocate_ex(s1, NULL, 0);
6968 if (size < 0)
7069 return -1;
7170
7271 #ifdef HAVE_SELINUX
73− /* Use mmap instead of malloc for Selinux. */
74− ptr = mmap (NULL, size, PROT_READ|PROT_WRITE,
75− MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
76− if (ptr == MAP_FAILED)
77− tcc_error("tccrun: could not map memory");
72+{
73+ /* Using mmap instead of malloc */
74+ void *prx;
75+ char tmpfname[] = "/tmp/.tccrunXXXXXX";
76+ int fd = mkstemp(tmpfname);
77+ unlink(tmpfname);
78+ ftruncate(fd, size);
79+
80+ ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
81+ prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
82+ if (ptr == MAP_FAILED || prx == MAP_FAILED)
83+ tcc_error("tccrun: could not map memory");
7884 dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size);
85+ dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, prx);
86+ ptr_diff = (char*)prx - (char*)ptr;
87+}
7988 #else
8089 ptr = tcc_malloc(size);
8190 #endif
82− tcc_relocate_ex(s1, ptr); /* no more errors expected */
91+ tcc_relocate_ex(s1, ptr, ptr_diff); /* no more errors expected */
8392 dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, ptr);
8493 return 0;
8594 }
@@ -91,6 +100,7 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 5 unmodified lines
91100 for (i = 0; i < s1->nb_runtime_mem; ++i) {
92101 #ifdef HAVE_SELINUX
93102 unsigned size = (unsigned)(addr_t)s1->runtime_mem[i++];
103+ munmap(s1->runtime_mem[i++], size);
94104 munmap(s1->runtime_mem[i], size);
95105 #else
96106 #ifdef _WIN64
@@ -166,7 +176,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) · 69 unmodified lines
166176
167177 /* relocate code. Return -1 on error, required size if ptr is NULL,
168178 otherwise copy code into buffer passed by the caller */
169−static int tcc_relocate_ex(TCCState *s1, void *ptr)
179+static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff)
170180 {
171181 Section *s;
172182 unsigned offset, length, fill, i, k;
@@ -199,7 +209,12 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 26 unmodified lines
199209 if (k != !(s->sh_flags & SHF_EXECINSTR))
200210 continue;
201211 offset += fill;
202− s->sh_addr = mem ? mem + offset : 0;
212+ if (!mem)
213+ s->sh_addr = 0;
214+ else if (s->sh_flags & SHF_EXECINSTR)
215+ s->sh_addr = mem + offset + ptr_diff;
216+ else
217+ s->sh_addr = mem + offset;
203218 #if 0
204219 if (mem)
205220 printf("%-16s +%02lx %p %04x\n",
@@ -242,13 +257,15 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr) · 36 unmodified lines
242257 continue;
243258 length = s->data_offset;
244259 ptr = (void*)s->sh_addr;
260+ if (s->sh_flags & SHF_EXECINSTR)
261+ ptr = (char*)ptr - ptr_diff;
245262 if (NULL == s->data || s->sh_type == SHT_NOBITS)
246263 memset(ptr, 0, length);
247264 else
248265 memcpy(ptr, s->data, length);
249266 /* mark executable sections as executable in memory */
250267 if (s->sh_flags & SHF_EXECINSTR)
251− set_pages_executable(ptr, length);
268+ set_pages_executable((char*)ptr + ptr_diff, length);
252269 }
253270 return 0;
254271 }
@@ -263,15 +280,17 @@ static void set_pages_executable(void *ptr, unsigned long length) · 8 unmodified lines
263280 VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
264281 #else
265282 void __clear_cache(void *beginning, void *end);
283+# ifndef HAVE_SELINUX
266284 addr_t start, end;
267−#ifndef PAGESIZE
268−# define PAGESIZE 4096
269−#endif
285+# ifndef PAGESIZE
286+# define PAGESIZE 4096
287+# endif
270288 start = (addr_t)ptr & ~(PAGESIZE - 1);
271289 end = (addr_t)ptr + length;
272290 end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
273291 if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC))
274292 tcc_error("mprotect failed: did you mean to configure --with-selinux?");
293+# endif
275294 # if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64
276295 __clear_cache(ptr, (char *)ptr + length);
277296 # endif
tcctok.h+7−9
@@ -120,6 +120,8 @@ · 119 unmodified lines
120120 DEF(TOK_FASTCALL1, "fastcall")
121121 DEF(TOK_FASTCALL2, "__fastcall")
122122 DEF(TOK_FASTCALL3, "__fastcall__")
123+ DEF(TOK_REGPARM1, "regparm")
124+ DEF(TOK_REGPARM2, "__regparm__")
123125
124126 DEF(TOK_MODE, "__mode__")
125127 DEF(TOK_MODE_QI, "__QI__")
@@ -134,23 +136,19 @@ · 8 unmodified lines
134136 DEF(TOK_NORETURN2, "__noreturn__")
135137 DEF(TOK_VISIBILITY1, "visibility")
136138 DEF(TOK_VISIBILITY2, "__visibility__")
139+
137140 DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
138141 DEF(TOK_builtin_choose_expr, "__builtin_choose_expr")
139142 DEF(TOK_builtin_constant_p, "__builtin_constant_p")
140143 DEF(TOK_builtin_frame_address, "__builtin_frame_address")
141144 DEF(TOK_builtin_return_address, "__builtin_return_address")
142145 DEF(TOK_builtin_expect, "__builtin_expect")
143−#ifdef TCC_TARGET_X86_64
144−#ifdef TCC_TARGET_PE
146+ /*DEF(TOK_builtin_va_list, "__builtin_va_list")*/
147+#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
145148 DEF(TOK_builtin_va_start, "__builtin_va_start")
146−#else
149+#elif defined TCC_TARGET_X86_64
147150 DEF(TOK_builtin_va_arg_types, "__builtin_va_arg_types")
148−#endif
149−#endif
150− DEF(TOK_REGPARM1, "regparm")
151− DEF(TOK_REGPARM2, "__regparm__")
152−
153−#ifdef TCC_TARGET_ARM64
151+#elif defined TCC_TARGET_ARM64
154152 DEF(TOK___va_start, "__va_start")
155153 DEF(TOK___va_arg, "__va_arg")
156154 #endif
tests/Makefile+4−0
@@ -234,8 +234,12 @@ vla_test-run: vla_test$(EXESUF) · 233 unmodified lines
234234 cross-test :
235235 @echo ------------ $@ ------------
236236 $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
237+ $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
237238 $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
239+ $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
238240 $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
241+ $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
242+ $(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
239243 $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
240244 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
241245 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
tests/pp/13.expect+0−1
@@ -1,3 +1,2 @@
1−# `modelist' label. Each video mode record looks like:
21 .text
32 endtext:
tests/pp/15.c+2−2
@@ -12,7 +12,7 @@ return n(A)n(++)n(+)n(+)n(B); · 11 unmodified lines
1212 return n(0x1E)n(-1);
1313
1414 // unlike gcc but correct
15−XXX: return n(x)+n(x)-n(1)+n(1)-2;
15+// XXX: return n(x)+n(x)-n(1)+n(1)-2;
1616
1717 // unlike gcc, but cannot appear in valid C
18−XXX: return n(x)n(x)n(1)n(2)n(x);
18+// XXX: return n(x)n(x)n(1)n(2)n(x);
tests/pp/15.expect+0−2
@@ -3,5 +3,3 @@ return A+++B; · 2 unmodified lines
33 return A+ ++B;
44 return A+++ +B;
55 return 0x1E -1;
6−XXX: return x+x-1 +1 -2;
7−XXX: return x x 1 2 x;
tests/pp/Makefile+2−2
@@ -12,7 +12,7 @@ TESTS = $(call files,c) $(call files,S) · 11 unmodified lines
1212
1313 all test : $(sort $(TESTS))
1414
15−DIFF_OPTS = -Nu -b -B -I "^\#"
15+DIFF_OPTS = -Nu -b -B
1616
1717 # Filter source directory in warnings/errors (out-of-tree builds)
1818 FILTER = 2>&1 | sed 's,$(SRC)/,,g'
@@ -40,7 +40,7 @@ clean: · 21 unmodified lines
4040 rm -f *.output
4141
4242 02.test : DIFF_OPTS += -w
43−15.test : DIFF_OPTS += -I"^XXX:"
43+# 15.test : DIFF_OPTS += -I"^XXX:"
4444
4545 # diff options:
4646 # -b ighore space changes
tests/tcctest.c+3−4
@@ -3235,6 +3235,7 @@ void asm_local_statics (void) · 3234 unmodified lines
32353235 }
32363236 #endif
32373237
3238+static
32383239 unsigned int set;
32393240
32403241 void fancy_copy (unsigned *in, unsigned *out)
@@ -3247,7 +3248,7 @@ void fancy_copy2 (unsigned *in, unsigned *out) · 6 unmodified lines
32473248 asm volatile ("mov %0,(%1)" : : "r" (*in), "r" (out) : "memory");
32483249 }
32493250
3250−#ifdef __x86_64__
3251+#if defined __x86_64__ && !defined _WIN64
32513252 void clobber_r12(void)
32523253 {
32533254 asm volatile("mov $1, %%r12" ::: "r12");
@@ -3256,7 +3257,7 @@ void clobber_r12(void) · 2 unmodified lines
32563257
32573258 void test_high_clobbers(void)
32583259 {
3259−#ifdef __x86_64__
3260+#if defined __x86_64__ && !defined _WIN64
32603261 register long val asm("r12");
32613262 long val2;
32623263 /* This tests if asm clobbers correctly save/restore callee saved
@@ -3265,11 +3266,9 @@ void test_high_clobbers(void) · 2 unmodified lines
32653266 correctly capture the data flow, but good enough for us. */
32663267 asm volatile("mov $0x4542, %%r12" : "=r" (val):: "memory");
32673268 clobber_r12();
3268−#ifndef _WIN64
32693269 asm volatile("mov %%r12, %0" : "=r" (val2) : "r" (val): "memory");
32703270 printf("asmhc: 0x%x\n", val2);
32713271 #endif
3272−#endif
32733272 }
32743273
32753274 static long cpu_number;
tests/tests2/95_bitfields.c+1−1
@@ -70,7 +70,7 @@ · 69 unmodified lines
7070 {
7171 struct M P __s {
7272 int a;
73− char b;
73+ signed char b;
7474 int x : 12, y : 4, : 0, : 4, z : 3;
7575 char d;
7676 };
tests/tests2/96_nodata_wanted.c+1−1
@@ -78,7 +78,7 @@ te1:; · 77 unmodified lines
7878 tl += &&te1 - &&ts1;
7979 printf("size of data/text:\n %s/%s\n",
8080 dl ? "non-zero":"zero", tl ? "non-zero":"zero");
81− printf("# %d/%d\n", dl, tl);
81+ /*printf("# %d/%d\n", dl, tl);*/
8282 }
8383
8484 #endif
tests/tests2/96_nodata_wanted.expect+0−2
@@ -17,9 +17,7 @@ data: · 16 unmodified lines
1717 333 44 555555 6 7
1818 size of data/text:
1919 non-zero/non-zero
20−# 111/193
2120
2221 [test_data_suppression_on]
2322 size of data/text:
2423 zero/zero
25−# 0/0
tests/tests2/Makefile+1−1
@@ -70,7 +70,7 @@ all test tests2.all: $(filter-out $(SKIP),$(TESTS)) ; · 69 unmodified lines
7070 T1 = $(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS)
7171 T2 = $(TCC) $(FLAGS) -run $< $(ARGS)
7272 T3 = $(FILTER) >$*.output 2>&1 || true \
73− && diff -Nbu -I "^\#" $(filter %.expect,$^) $*.output \
73+ && diff -Nbu $(filter %.expect,$^) $*.output \
7474 && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
7575
7676 # run single test and update .expect file, e.g. "make tests2.37+"
win32/Makefile+0−148
@@ -1,148 +0,0 @@
1−#
2−# This Makefile builds native Windows tcc for both 32 and 64 bits generator.
3−# It requires Cygwin 64 and gcc to bootstrap a first tcc version which is used
4−# by a second stage to compile tcc it self.
5−# Generated binaries do not require cygwin to run.
6−# You can launch 'tarball' target to build a tar.gz you can install on any
7−# Windows machines.
8−
9−CPU = $(shell if `gcc -v 2>&1 | grep Target | grep -q x86_64`; then echo 64; else echo 32; fi)
10−VERSION = $(shell cat ../VERSION)
11−BOOTCC = gcc
12−CFLAGS = -s -static -fno-strict-aliasing -Wno-incompatible-pointer-types -DTCC_TARGET_PE
13−#WINPWD = `cygpath --mixed $(PWD)`
14−#@echo "#define CONFIG_TCCDIR \"$(WINPWD)\""
15−
16−ifeq ($(CPU), 64)
17−NATIVE = -m$(CPU) -DTCC_TARGET_X86_64
18−ARCH = x86_64
19−else
20−NATIVE = -m$(CPU) -DTCC_TARGET_I386
21−ARCH = i386
22−endif
23−
24−TARGET = $(CPU)
25−
26−ifeq ($(TARGET), 64)
27−TFLAGS = -m$(TARGET) -DTCC_TARGET_X86_64
28−TARCH = x86_64
29−else
30−TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
31−TARCH = i386
32−endif
33−
34−all: pre bootstrap libs rebuild
35− @chmod 775 *.exe
36− @ls -ls *.exe
37−
38−pre:
39− @echo ARCH=$(TARCH) 1> ../config.mak
40− @echo TARGETOS=Windows 1>> ../config.mak
41− @echo CONFIG_WIN32=yes 1>> ../config.mak
42− @echo TOPSRC=$$\(TOP\) 1>> ../config.mak
43− @echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
44− @echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
45− @echo "#define TCC_LIBTCC1 \"libtcc1-64.a\"" 1>>../config.h
46− @echo "#else" 1>>../config.h
47− @echo "#define TCC_LIBTCC1 \"libtcc1-32.a\"" 1>>../config.h
48− @echo "#endif" 1>>../config.h
49− @echo @set VERSION $(VERSION) 1>../config.texi
50− @rm -f *tcc.exe tiny_*.exe *tcc.dll lib/*.a
51− @rm -r -f libtcc doc
52− @mkdir libtcc
53− @mkdir doc
54− @cp ../include/*.h include
55− @cp ../tcclib.h include
56− @cp ../libtcc.h include
57− @cp tcc-win32.txt doc
58− @cp ../tests/libtcc_test.c examples
59−
60−PHONY += pre
61−
62−bootstrap:
63− @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
64− @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
65− @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
66− @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
67− @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
68−
69−PHONY += bootstrap
70−
71−lib/libtcc1-32.a:
72− @echo Building $*.a with tcc -m32
73− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
74− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
75− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
76− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
77− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1w.c
78− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
79− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1w.c
80− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
81− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
82− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
83− @./tcc -m32 -ar lib/libtcc1-32.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o crt1w.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
84− @rm *.o
85−
86−lib/libtcc1-64.a:
87− @echo Building $*.a with tcc -m64
88− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
89− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
90− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
91− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
92− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1w.c
93− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
94− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1w.c
95− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
96− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
97− @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
98− @./tcc -m64 -ar lib/libtcc1-64.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o wincrt1.o crt1w.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
99− @rm *.o
100−
101−libs: lib/libtcc1-32.a lib/libtcc1-64.a
102−
103−PHONY += libs
104−
105−rebuild:
106− @echo Rebuild using tcc itself - default $(TARGET)bits
107− @./$(TARCH)-win32-tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -o tcc.exe ../tcc.c
108− @./tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
109− @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe i386-win32-tcc.exe
110− @./tcc -O2 -B. -m$(TARGET) -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe x86_64-win32-tcc.exe
111−
112−PHONY += rebuild
113−
114−test:
115− @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc hello-exe hello-run)
116− @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc vla_test-run tests2-dir pp-dir)
117−ifeq ($(CPU), 64)
118− @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc hello-exe hello-run)
119− @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc vla_test-run tests2-dir pp-dir)
120−endif
121−
122−PHONY += test
123−
124−TARNAME = tcc-$(VERSION)-$(ARCH)-win32
125−
126−tarball:
127− @rm -r -f $(TARNAME)
128− @mkdir $(TARNAME)
129− @cp -r doc $(TARNAME)
130− @cp -r examples $(TARNAME)
131− @cp -r include $(TARNAME)
132− @cp -r lib $(TARNAME)
133− @cp -r libtcc $(TARNAME)
134− @cp -r build-tcc.bat $(TARNAME)
135− @cp -r i386-win32-tcc.exe $(TARNAME)
136− @cp -r libtcc.def $(TARNAME)
137− @cp -r libtcc.dll $(TARNAME)
138− @cp -r Makefile $(TARNAME)
139− @cp -r tcc.exe $(TARNAME)
140− @cp -r tcc-win32.txt $(TARNAME)
141− @cp -r x86_64-win32-tcc.exe $(TARNAME)
142− @tar czf $(TARNAME).tar.gz $(TARNAME)
143− @rm -r -f $(TARNAME)
144−
145−PHONY += tarball
146−
147−clean:
148− rm -f *.o *.exe *.dll lib/*.a *.pdb *.obj *.exp *.def *.lib
win32/build-tcc.bat+59−48
@@ -4,13 +4,31 @@ · 3 unmodified lines
44
55 @echo off
66 setlocal
7−
8−set CC=gcc -Os -s -static
7+if (%1)==(-clean) goto :cleanup
8+set CC=gcc
99 set /p VERSION= < ..\VERSION
1010 set INST=
11+set BIN=
1112 set DOC=no
13+set EXES_ONLY=no
1214 goto :a0
13−
15+:a2
16+shift
17+:a3
18+shift
19+:a0
20+if not (%1)==(-c) goto :a1
21+set CC=%~2
22+if (%2)==(cl) set CC=@call :cl
23+goto :a2
24+:a1
25+if (%1)==(-t) set T=%2&& goto :a2
26+if (%1)==(-v) set VERSION=%~2&& goto :a2
27+if (%1)==(-i) set INST=%2&& goto :a2
28+if (%1)==(-b) set BIN=%2&& goto :a2
29+if (%1)==(-d) set DOC=yes&& goto :a3
30+if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
31+if (%1)==() goto :p1
1432 :usage
1533 echo usage: build-tcc.bat [ options ... ]
1634 echo options:
@@ -18,10 +36,35 @@ echo -c prog use prog (gcc/tcc/cl) to compile tcc · 1 unmodified line
1836 echo -c "prog options" use prog with options to compile tcc
1937 echo -t 32/64 force 32/64 bit default target
2038 echo -v "version" set tcc version
21−echo -i dir install tcc into dir
39+echo -i tccdir install tcc into tccdir
40+echo -b bindir optionally install binaries into bindir elsewhere
2241 echo -d create tcc-doc.html too (needs makeinfo)
42+echo -x just create the executables
43+echo -clean delete all previously produced files and directories
2344 exit /B 1
2445
46+@rem ------------------------------------------------------
47+@rem sub-routines
48+
49+:cleanup
50+set LOG=echo
51+%LOG% removing files:
52+for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
53+for %%f in (..\config.h ..\config.texi) do call :del_file %%f
54+for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
55+for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
56+for %%f in (*.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
57+%LOG% removing directories:
58+for %%f in (doc libtcc) do call :del_dir %%f
59+%LOG% done.
60+exit /B 0
61+:del_file
62+if exist %1 del %1 && %LOG% %1
63+exit /B 0
64+:del_dir
65+if exist %1 rmdir /Q/S %1 && %LOG% %1
66+exit /B 0
67+
2568 :cl
2669 @echo off
2770 set CMD=cl
@@ -37,52 +80,16 @@ echo on · 9 unmodified lines
3780 %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
3881 @exit /B %ERRORLEVEL%
3982
40−:a2
41−shift
42−:a1
43−shift
44−:a0
45−if not (%1)==(-c) goto :a3
46−set CC=%~2
47−if (%2)==(cl) set CC=@call :cl
48−goto :a2
49−:a3
50−if not (%1)==(-t) goto :a4
51−set T=%2
52−goto :a2
53−:a4
54−if not (%1)==(-v) goto :a5
55−set VERSION=%~2
56−goto :a2
57−:a5
58−if not (%1)==(-i) goto :a6
59−set INST=%2
60−goto :a2
61−:a6
62−if not (%1)==(-d) goto :a7
63−set DOC=yes
64−goto :a1
65−:a7
66−if not (%1)==() goto :usage
67−
68−if not "%CC%"=="@call :cl" goto :p1
69−set VSCOMNTOOLS=%VS150COMNTOOLS%
70−if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS140COMNTOOLS%
71−if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS130COMNTOOLS%
72−if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS120COMNTOOLS%
73−if %T%_==32_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\vcvars32.bat"
74−if %T%_==64_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\amd64\vcvars64.bat"
75−if %T%_==_ set T=32& if %Platform%_==X64_ set T=64
76−if %CLVARS%_==_ goto :p1
77−if exist %CLVARS% call %CLVARS%
78−:p1
83+@rem ------------------------------------------------------
84+@rem main program
7985
86+:p1
8087 if not %T%_==_ goto :p2
8188 set T=32
8289 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
8390 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
8491 :p2
85−
92+if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static
8693 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
8794 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
8895 set P32=i386-win32
@@ -91,13 +98,14 @@ if %T%==64 goto :t64 · 2 unmodified lines
9198 set D=%D32%
9299 set DX=%D64%
93100 set PX=%P64%
94−goto :t96
101+goto :p3
95102 :t64
96103 set D=%D64%
97104 set DX=%D32%
98105 set PX=%P32%
99−:t96
106+goto :p3
100107
108+:p3
101109 @echo on
102110
103111 :config.h
@@ -116,7 +124,7 @@ for %%f in (*tcc.exe *tcc.dll) do @del %%f · 12 unmodified lines
116124 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
117125 %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
118126
119−@if (%TCC_FILES%)==(no) goto :files-done
127+@if (%EXES_ONLY%)==(yes) goto :files-done
120128
121129 if not exist libtcc mkdir libtcc
122130 if not exist doc mkdir doc
@@ -170,8 +178,11 @@ for %%f in (*.o *.def) do @del %%f · 47 unmodified lines
170178 :copy-install
171179 @if (%INST%)==() goto :the_end
172180 if not exist %INST% mkdir %INST%
181+@if (%BIN%)==() set BIN=%INST%
182+if not exist %BIN% mkdir %BIN%
183+for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
173184 @if not exist %INST%\lib mkdir %INST%\lib
174−for %%f in (*tcc.exe *tcc.dll lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
185+for %%f in (lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
175186 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
176187
177188 :the_end
win32/lib/crt1.c+6−15
@@ -16,11 +16,6 @@ · 15 unmodified lines
1616 #define _PC_53 0x00010000 // 53 bits
1717 #define _PC_64 0x00000000 // 64 bits
1818
19−typedef struct
20−{
21− int newmode;
22−} _startupinfo;
23−
2419 #ifdef _UNICODE
2520 #define __tgetmainargs __wgetmainargs
2621 #define _tstart _wstart
@@ -33,6 +28,7 @@ typedef struct · 6 unmodified lines
3328 #define _runtmain _runmain
3429 #endif
3530
31+typedef struct { int newmode; } _startupinfo;
3632 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
3733 void __cdecl __set_app_type(int apptype);
3834 unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
@@ -44,23 +40,19 @@ int _dowildcard; · 5 unmodified lines
4440 void _tstart(void)
4541 {
4642 __TRY__
47− int ret;
48− _startupinfo start_info;
43+ _startupinfo start_info = {0};
4944
5045 // Sets the current application type
5146 __set_app_type(_CONSOLE_APP);
5247
5348 // Set default FP precision to 53 bits (8-byte double)
54− // _MCW_PC (Precision control) is not supported on
55− // the ARM and x64 architectures
56−#ifdef __i386
49+ // _MCW_PC (Precision control) is not supported on ARM
50+#if defined __i386__ || defined __x86_64__
5751 _controlfp(_PC_53, _MCW_PC);
5852 #endif
5953
60− start_info.newmode = 0;
6154 __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
62− ret = _tmain(__argc, __targv, _tenviron);
63− exit(ret);
55+ exit(_tmain(__argc, __targv, _tenviron));
6456 }
6557
6658 int _runtmain(int argc, /* as tcc passed in */ char **argv)
@@ -78,8 +70,7 @@ int _runtmain(int argc, /* as tcc passed in */ char **argv) · 11 unmodified lines
7870 __argc = argc;
7971 __targv = argv;
8072 #endif
81−
82−#ifdef __i386
73+#if defined __i386__ || defined __x86_64__
8374 _controlfp(_PC_53, _MCW_PC);
8475 #endif
8576 return _tmain(__argc, __targv, _tenviron);
win32/lib/wincrt1.c+29−47
@@ -23,71 +23,53 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); · 22 unmodified lines
2323 #define _runtwinmain _runwinmain
2424 #endif
2525
26−typedef struct
27−{
28− int newmode;
29−} _startupinfo; // CLI Vs GUI
30−
26+typedef struct { int newmode; } _startupinfo;
3127 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
3228
33−int _twinstart(void)
29+static int go_winmain(TCHAR *arg1)
3430 {
35− __TRY__
31+ STARTUPINFO si;
3632 _TCHAR *szCmd, *p;
37− STARTUPINFO startinfo;
38− _startupinfo start_info_con = {0};
3933 int fShow;
40− int ret;
41−
42− __set_app_type(__GUI_APP);
43− _controlfp(0x10000, 0x30000);
4434
45− start_info_con.newmode = 0;
46− __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
35+ GetStartupInfo(&si);
36+ if (si.dwFlags & STARTF_USESHOWWINDOW)
37+ fShow = si.wShowWindow;
38+ else
39+ fShow = SW_SHOWDEFAULT;
4740
48− p = GetCommandLine();
49− if (__argc > 1)
50− szCmd = _tcsstr(p, __targv[1]);
41+ szCmd = NULL, p = GetCommandLine();
42+ if (arg1)
43+ szCmd = _tcsstr(p, arg1);
5144 if (NULL == szCmd)
52− szCmd = __T("");
53− else if (szCmd > p && szCmd[-1] == __T('\"'))
45+ szCmd = _tcsdup(__T(""));
46+ else if (szCmd > p && szCmd[-1] == __T('"'))
5447 --szCmd;
48+#if defined __i386__ || defined __x86_64__
49+ _controlfp(0x10000, 0x30000);
50+#endif
51+ return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
52+}
5553
56− GetStartupInfo(&startinfo);
57− fShow = startinfo.wShowWindow;
58− if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW))
59− fShow = SW_SHOWDEFAULT;
60−
61− ret = _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
62− exit(ret);
54+int _twinstart(void)
55+{
56+ __TRY__
57+ _startupinfo start_info_con = {0};
58+ __set_app_type(__GUI_APP);
59+ __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
60+ exit(go_winmain(__argc > 1 ? __targv[1] : NULL));
6361 }
6462
6563 int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
6664 {
67− _TCHAR *szCmd, *p;
68−
6965 #ifdef UNICODE
7066 _startupinfo start_info = {0};
71−
7267 __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info);
7368 /* may be wrong when tcc has received wildcards (*.c) */
74− if (argc < __argc) {
75− __targv += __argc - argc;
76− __argc = argc;
77− }
69+ if (argc < __argc)
70+ __targv += __argc - argc, __argc = argc;
7871 #else
79− __argc = argc;
80− __targv = argv;
72+ __argc = argc, __targv = argv;
8173 #endif
82−
83− p = GetCommandLine();
84− szCmd = NULL;
85− if (argc > 1)
86− szCmd = _tcsstr(p, __targv[1]);
87− if (NULL == szCmd)
88− szCmd = __T("");
89− else if (szCmd > p && szCmd[-1] == __T('\"'))
90− --szCmd;
91− _controlfp(0x10000, 0x30000);
92− return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT);
74+ return go_winmain(__argc > 1 ? __targv[1] : NULL);
9375 }
win32/tcc-win32.txt+7−12
@@ -108,6 +108,8 @@ · 107 unmodified lines
108108 ------------------------
109109 * You can use the MinGW and MSYS tools available at
110110 http://www.mingw.org
111+ http://www.mingw-w64.org
112+ http://www.msys2.org
111113
112114 Untar the TCC archive and type in the MSYS shell:
113115 ./configure [--prefix installpath]
@@ -116,29 +118,22 @@ · 2 unmodified lines
116118
117119 The default install location is c:\Program Files\tcc
118120
121+ Cygwin can be used too with its mingw cross-compiler installed:
122+ ./configure --cross-prefix=i686-w64-mingw32-
123+ (the prefix may vary)
124+
119125 * Alternatively you can compile TCC with just GCC from MinGW using
120126 > build-tcc.bat (from the win32 directory)
121127
122128 Also MSVC can be used with the "VSTools Developer Command Prompt":
123129 > build-tcc.bat -c cl
124130
125− or with a tcc (needs to be in a different directory)
131+ or with an existing tcc (needs to be in a different directory)
126132 > build-tcc.bat -c some-tcc-dir\tcc.exe
127133
128134 Also you can copy/install everything into another directory:
129135 > build-tcc.bat -i <dir>
130136
131− * You can also bootstrap a native tcc Windows toolchain with cygwin.
132− https://www.cygwin.com/
133−
134− Install Base, gcc, make
135− Launch Cygwin Terminal
136− > make
137− or to force 32bit executables (including 64bit backend)
138− > make TARGET=32
139− or to force 64bit executables (including 32bit backend)
140− > make TARGET=64
141−
142137 Limitations:
143138 ------------
144139 - On the object file level, currently TCC supports only the ELF format,

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