History

make: make shorter command lines

Put former NATIVE_DEFINES into config.h. Such tcc can be run and tested directly from source more easily, like for example: tcc -run tcc.c -B. -run test.c Also: - tccelf.c: cleanup - tccpp.c: avoid stupid clang warning - configure: reduce -Wno- switches - tcc.h: inline wait/post_sem() - tccpe.c: simplify import (assume STT_NOTYPE is function)

grischka committed 1 year ago

Commit 729918e1 parent 4b0402821 files · +375 −468Browse files

Unified · Split

21 files
  1. .gitignore +3 −0
  2. Makefile +23 −51
  3. arm-gen.c +2 −2
  4. arm-link.c +1 −1
  5. configure +128 −80
  6. i386-gen.c +0 −10
  7. lib/Makefile +1 −1
  8. lib/bcheck.c +4 −2
  9. lib/bt-exe.c +0 −1
  10. libtcc.c +17 −7
  11. riscv64-asm.c +1 −1
  12. tcc.c +4 −0
  13. tcc.h +48 −96
  14. tccasm.c +10 −3
  15. tccelf.c +43 −38
  16. tccgen.c +8 −2
  17. tccpe.c +48 −130
  18. tccpp.c +7 −6
  19. tccrun.c +4 −4
  20. tests/Makefile +23 −23
  21. x86_64-gen.c +0 −10
.gitignore+3−0
@@ -48,6 +48,9 @@ win32/include/stddef.h · 47 unmodified lines
4848 win32/include/stdnoreturn.h
4949 win32/include/varargs.h
5050 win32/include/tcclib.h
51+win32/include/tccdefs.h
52+win32/include/stdatomic.h
53+win32/include/tgmath.h
5154
5255 tests/tcctest[1234]
5356 tests/tcctest.gcc
Makefile+23−51
@@ -20,18 +20,15 @@ LIBTCC = libtcc.a · 19 unmodified lines
2020 LIBTCC1 = libtcc1.a
2121 LINK_LIBTCC =
2222 LIBS =
23−CFLAGS += -I$(TOP)
2423 CFLAGS += $(CPPFLAGS)
2524 VPATH = $(TOPSRC)
25+-LTCC = $(TOP)/$(LIBTCC)
2626
2727 ifdef CONFIG_WIN32
2828 CFG = -win
2929 ifneq ($(CONFIG_static),yes)
3030 LIBTCC = libtcc$(DLLSUF)
3131 LIBTCCDEF = libtcc.def
32− -LTCC = $(bindir)/libtcc.dll
33− else
34− -LTCC = -ltcc -L$(libdir)
3532 endif
3633 ifneq ($(CONFIG_debug),yes)
3734 LDFLAGS += -s
@@ -76,7 +73,6 @@ else · 38 unmodified lines
7673 endif
7774 export MACOSX_DEPLOYMENT_TARGET := 10.6
7875 endif
79− -LTCC = -ltcc
8076 endif
8177
8278 # run local version of tcc with local libraries and includes
@@ -89,42 +85,15 @@ TCC = $(TCC_LOCAL) $(TCCFLAGS) · 6 unmodified lines
8985 # run tests with the installed tcc instead
9086 ifdef TESTINSTALL
9187 TCC_LOCAL = $(bindir)/tcc
92− TCCFLAGS-unx = -I..
93− TCCFLAGS-win = -I.. -B$(bindir)
94− LIBTCC =
95− LIBS += $(-LTCC)
88+ TCCFLAGS-unx = -I$(TOP)
89+ TCCFLAGS-win = -B$(bindir) -I$(TOP)
90+ -LTCC = $(libdir)/$(LIBTCC) $(LINK_LIBTCC)
9691 endif
9792
9893 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
9994 LIBS_P = $(LIBS)
10095 LDFLAGS_P = $(LDFLAGS)
10196
102−CONFIG_$(ARCH) = yes
103−NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
104−NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
105−NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
106−NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
107−NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
108−NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
109−NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC
110−NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX
111−NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
112−NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
113−NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
114−NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
115−NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
116−NATIVE_DEFINES_$(CONFIG_riscv64) += -DTCC_TARGET_RISCV64
117−NATIVE_DEFINES_$(CONFIG_BSD) += -DTARGETOS_$(TARGETOS)
118−NATIVE_DEFINES_$(CONFIG_Android) += -DTARGETOS_ANDROID
119−NATIVE_DEFINES_$(CONFIG_pie) += -DCONFIG_TCC_PIE
120−NATIVE_DEFINES_$(CONFIG_pic) += -DCONFIG_TCC_PIC
121−NATIVE_DEFINES_no_$(CONFIG_new_macho) += -DCONFIG_NEW_MACHO=0
122−NATIVE_DEFINES_$(CONFIG_codesign) += -DCONFIG_CODESIGN
123−NATIVE_DEFINES_$(CONFIG_new-dtags) += -DCONFIG_NEW_DTAGS
124−NATIVE_DEFINES_no_$(CONFIG_bcheck) += -DCONFIG_TCC_BCHECK=0
125−NATIVE_DEFINES_no_$(CONFIG_backtrace) += -DCONFIG_TCC_BACKTRACE=0
126−NATIVE_DEFINES += $(NATIVE_DEFINES_yes) $(NATIVE_DEFINES_no_no)
127−
12897 DEF-i386 = -DTCC_TARGET_I386
12998 DEF-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE
13099 DEF-i386-OpenBSD = $(DEF-i386) -DTARGETOS_OpenBSD
@@ -150,8 +119,6 @@ DEF-x86_64-FreeBSD = $(DEF-x86_64) -DTARGETOS_FreeBSD · 19 unmodified lines
150119 DEF-x86_64-NetBSD = $(DEF-x86_64) -DTARGETOS_NetBSD
151120 DEF-x86_64-OpenBSD = $(DEF-x86_64) -DTARGETOS_OpenBSD
152121
153−DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
154−
155122 ifeq ($(INCLUDED),no)
156123 # --------------------------------------------------------------------------
157124 # running top Makefile
@@ -192,7 +159,7 @@ endif · 34 unmodified lines
192159 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
193160 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
194161
195−DEFINES += $(DEF-$T) $(DEF-all)
162+DEFINES += $(DEF-$T)
196163 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
197164 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
198165 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
@@ -202,10 +169,15 @@ DEFINES += $(DEF-$(or $(findstring win,$T),unx)) · 3 unmodified lines
202169
203170 ifneq ($(X),)
204171 $(if $(DEF-$T),,$(error error: unknown target: '$T'))
205−DEF-all += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
172+DEF-$T += -DCONFIG_TCC_CROSS
173+DEF-$(NATIVE_TARGET) =
174+DEF-$T += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
206175 ifneq ($(CONFIG_WIN32),yes)
207176 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
208177 endif
178+else
179+# using values from config.h
180+DEF-$(NATIVE_TARGET) =
209181 endif
210182
211183 # include custom configuration (see make help)
@@ -255,15 +227,16 @@ ifeq ($(ONE_SOURCE),yes) · 43 unmodified lines
255227 LIBTCC_OBJ = $(X)libtcc.o
256228 LIBTCC_INC = $($T_FILES)
257229 TCC_FILES = $(X)tcc.o
258−tcc.o : DEFINES += -DONE_SOURCE=0
259−$(X)tcc.o $(X)libtcc.o : $(TCCDEFS_H)
230+$(X)tcc.o $(X)libtcc.o : $(TCCDEFS_H)
260231 else
261232 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
262233 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
263234 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
264−$(TCC_FILES) : DEFINES += -DONE_SOURCE=0
265235 $(X)tccpp.o : $(TCCDEFS_H)
236+$(X)libtcc.o : DEFINES += -DONE_SOURCE=0
266237 endif
238+tcc.o : DEFINES += -DONE_SOURCE=0
239+DEFINES += -I$(TOP)
267240
268241 GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no)
269242 ifneq ($(GITHASH),no)
@@ -283,7 +256,7 @@ endif · 13 unmodified lines
283256
284257 # target specific object rule
285258 $(X)%.o : %.c $(LIBTCC_INC)
286− $S$(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
259+ $S$(CC) -o $@ -c $< $(addsuffix ,$(DEFINES) $(CFLAGS))
287260
288261 # additional dependencies
289262 $(X)tcc.o : tcctools.c
@@ -291,7 +264,7 @@ $(X)tcc.o : DEFINES += $(DEF_GITHASH) · 1 unmodified line
291264
292265 # Host Tiny C Compiler
293266 tcc$(EXESUF): tcc.o $(LIBTCC)
294− $S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
267+ $S$(CC) -o $@ $^ $(addsuffix ,$(LIBS) $(LDFLAGS) $(LINK_LIBTCC))
295268
296269 # Cross Tiny C Compilers
297270 # (the TCCDEFS_H dependency is only necessary for parallel makes,
@@ -318,8 +291,8 @@ libtcc.a: $(LIBTCC_OBJ) · 20 unmodified lines
318291 libtcc.so: $(LIBTCC_OBJ)
319292 $S$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LIBS) $(LDFLAGS)
320293
321−libtcc.so: CFLAGS+=-fPIC
322−libtcc.so: LDFLAGS+=-fPIC
294+libtcc.so: override CFLAGS += -fPIC
295+libtcc.so: override LDFLAGS += -fPIC
323296
324297 # OSX dynamic libtcc library
325298 libtcc.dylib: $(LIBTCC_OBJ)
@@ -529,13 +502,12 @@ help: · 203 unmodified lines
529502 @echo "make test-install"
530503 @echo " run tests with the installed tcc"
531504 @echo "Other supported make targets:"
532− @echo " install install-strip doc clean tags ETAGS tar distclean help"
505+ @echo " install install-strip uninstall doc [dist]clean tags ETAGS tar help"
533506 @echo "Custom configuration:"
534507 @echo " The makefile includes a file 'config-extra.mak' if it is present."
535− @echo " This file may contain some custom configuration. For example:"
536− @echo " NATIVE_DEFINES += -D..."
537− @echo " Or for example to configure the search paths for a cross-compiler"
538− @echo " assuming the support files in /usr/i686-linux-gnu:"
508+ @echo " This file may contain some custom configuration. For example to"
509+ @echo " configure the search paths for a cross-compiler, assuming the"
510+ @echo " support files in /usr/i686-linux-gnu:"
539511 @echo " ROOT-i386 = /usr/i686-linux-gnu"
540512 @echo " CRT-i386 = {R}/lib"
541513 @echo " LIB-i386 = {B}:{R}/lib"
arm-gen.c+2−2
@@ -34,8 +34,8 @@ · 33 unmodified lines
3434 #define NB_REGS 9
3535 #endif
3636
37−#ifndef TCC_CPU_VERSION
38−# define TCC_CPU_VERSION 5
37+#ifndef CONFIG_TCC_CPUVER
38+# define CONFIG_TCC_CPUVER 5
3939 #endif
4040
4141 /* a register can belong to several classes. The classes must be
arm-link.c+1−1
@@ -202,7 +202,7 @@ ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 201 unmodified lines
202202 if (x & 0x800000)
203203 x -= 0x1000000;
204204 x <<= 2;
205− blx_avail = (TCC_CPU_VERSION >= 5);
205+ blx_avail = (CONFIG_TCC_CPUVER >= 5);
206206 is_thumb = val & 1;
207207 is_bl = (*(unsigned *) ptr) >> 24 == 0xeb;
208208 is_call = (type == R_ARM_CALL || (type == R_ARM_PC24 && is_bl));
configure+128−80
@@ -117,7 +117,7 @@ for opt do · 116 unmodified lines
117117 ;;
118118 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
119119 ;;
120− --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
120+ --dwarf=*) confvars="$confvars dwarf=${opt#*=}"
121121 ;;
122122 --enable-cross) confvars="$confvars cross"
123123 ;;
@@ -193,9 +193,10 @@ Advanced options (experts only): · 69 unmodified lines
193193 --config-backtrace=no disable stack backtraces (with -run or -bt)
194194 --config-bcheck=no disable bounds checker (-b)
195195 --config-predefs=no do not compile tccdefs.h, instead just include
196− --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
196+ --config-new_macho=no|yes force apple object format (autodetect osx <= 10)
197+ --config-new_dtags=yes use new ELF DTAGs (DT_RUNPATH instead of DT_RPATH)
197198 --config-codesign=no do not use codesign on apple to sign executables
198− --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
199+ --config-dwarf=x use dwarf debug info instead of stabs (x=2..5)
199200
200201 Cross build options (experimental):
201202 --cpu=CPU target CPU [$cpu]
@@ -209,7 +210,7 @@ default() # set variable unless already set · 7 unmodified lines
209210 {
210211 local v
211212 eval v=\"\$$1\"
212− test -z "$v" && eval $1=\"$2\"
213+ test -z "$v" -a -n "$2" && eval $1=\"$2\"
213214 }
214215
215216 default_conf() # add to confvars unless already present
@@ -251,10 +252,9 @@ else · 35 unmodified lines
251252 fi
252253
253254 default cpu "$cpu_sys"
254−cpu_set="$cpu"
255255
256256 # check for crpss build
257−if test "$cpu_set" != "$cpu_sys" \
257+if test "$cpu" != "$cpu_sys" \
258258 -o "$targetos" != "$buildos" \
259259 -o -n "$cross_prefix" ; then
260260 build_cross="yes"
@@ -322,8 +322,7 @@ esac · 61 unmodified lines
322322
323323 case $targetos in
324324 Darwin)
325− dwarf=4
326− confvars="$confvars OSX"
325+ confvars="$confvars OSX dwarf=4"
327326 default_conf "codesign"
328327 DLLSUF=".dylib"
329328 if test -z "$build_cross"; then
@@ -354,14 +353,14 @@ case $targetos in · 24 unmodified lines
354353 default sysroot "/usr"
355354 fi
356355 default prefix "${sysroot}"
357− confvars="$confvars Android new-dtags rpath=no"
356+ confvars="$confvars Android new_dtags rpath=no"
358357 test "${cpu}" != "i386" && confvars="$confvars pie"
359358 default_conf "static=no"
360359 if test "${cpu}" = "arm"; then
361360 default triplet "arm-linux-androideabi"
362361 cpuver=7
363362 else
364− default triplet "${cpu_set}-linux-android"
363+ default triplet "${cpu}-linux-android"
365364 fi
366365 test "${cpu%64}" != "${cpu}" && S="64" || S=""
367366 default tcc_sysincludepaths "{B}/include:{R}/include:{R}/include/${triplet}"
@@ -372,13 +371,16 @@ case $targetos in · 4 unmodified lines
372371 ;;
373372 WIN32)
374373 mingw32="yes"
375− confvars="$confvars WIN32"
374+ confvars="WIN32 $confvars"
376375 default prefix "C:/Program Files/tcc"
377376 default tccdir "${prefix}"
378377 default bindir "${tccdir}"
379378 default docdir "${tccdir}/doc"
380379 default libdir "${tccdir}/libtcc"
380+ # set tccdir at runtime from executable path
381381 test "$tccdir" = "$bindir" && tccdir_auto="yes"
382+ # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
383+ test "$cc_name" = "gcc" && default LDFLAGS "-static"
382384 LIBSUF=".lib"
383385 EXESUF=".exe"
384386 DLLSUF=".dll"
@@ -435,7 +437,7 @@ if test -z "$build_cross"; then · 50 unmodified lines
435437 if test -f "/lib/ld-uClibc.so.0" ; then
436438 echo "Perhaps you want ./configure --config-uClibc"
437439 fi
438− if test -f "/lib/ld-musl-$cpu.so.1"; then
440+ if test -f "/lib/ld-musl-${cpu}.so.1"; then
439441 echo "Perhaps you want ./configure --config-musl"
440442 fi
441443 fi
@@ -452,7 +454,7 @@ else · 10 unmodified lines
452454 esac
453455 case $targetos in
454456 Linux)
455− default triplet "$cpu_set-linux-gnu"
457+ default triplet "${cpu}-linux-gnu"
456458 esac
457459 fi
458460
@@ -460,11 +462,6 @@ if test "$bigendian" = "yes" ; then · 1 unmodified line
460462 confvars="$confvars BIGENDIAN"
461463 fi
462464
463−if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
464− # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
465− default LDFLAGS "-static"
466−fi
467−
468465 if test "$cpu" = "arm"; then
469466 if test "${triplet%eabihf}" != "$triplet" ; then
470467 confvars="$confvars arm_eabihf arm_vfp"
@@ -481,19 +478,14 @@ if test "$cpu" = "arm"; then · 10 unmodified lines
481478 fi
482479 fi
483480
484−if test -n "$dwarf"; then
485− confvars="$confvars dwarf=$dwarf"
486−fi
487−
488481 # a final configuration tuning
489482 if test "$cc_name" != "tcc"; then
490− OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
483+ OPT1="-Wdeclaration-after-statement" #-fno-strict-aliasing
491484 # we want -Wno- but gcc does not always reject unknown -Wno- options
492− OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
493− OPT2="$OPT2 -Wstringop-truncation"
494485 if test "$cc_name" = "clang"; then
495− OPT1="$OPT1 -fheinous-gnu-extensions"
496− OPT2="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
486+ OPT2= #"-Wstring-plus-int"
487+ else
488+ OPT2="-Wunused-result"
497489 fi
498490 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
499491 for o in $OPT1; do # enable these options
@@ -534,6 +526,8 @@ fcho "Switches " "$tcc_switches" · 34 unmodified lines
534526 fcho "Config " "${confvars# }"
535527 echo "Creating config.mak and config.h"
536528
529+version=`head $source_path/VERSION`
530+
537531 cat >config.mak <<EOF
538532 # Automatically generated by configure - do not modify
539533 prefix=$prefix
@@ -549,80 +543,132 @@ CC_NAME=$cc_name · 9 unmodified lines
549543 GCC_MAJOR=$gcc_major
550544 GCC_MINOR=$gcc_minor
551545 AR=$ar
552−CFLAGS=$CFLAGS
553−LDFLAGS=$LDFLAGS
554546 LIBSUF=$LIBSUF
555547 EXESUF=$EXESUF
556548 DLLSUF=$DLLSUF
549+CFLAGS=$CFLAGS
550+LDFLAGS=$LDFLAGS
551+ARCH=$cpu
552+TARGETOS=$targetos
553+BUILDOS=$buildos
554+VERSION=$version
557555 EOF
558556
559−print_inc() {
557+if test "$source_path_used" = "yes" ; then
558+ case $source_path in
559+ /*) echo "TOPSRC=$source_path";;
560+ *) echo "TOPSRC=\$(TOP)/$source_path";;
561+ esac >>config.mak
562+else
563+ echo 'TOPSRC=$(TOP)' >>config.mak
564+fi
565+
566+print_str() {
560567 local v="$2"
561568 if test -n "$v"; then
562− test "$3" = "num" || v="\"$v\""
563− echo "#ifndef $1" >> $TMPH
564− echo "# define $1 $v" >> $TMPH
565− echo "#endif" >> $TMPH
569+ test -n "$3" && echo "#ifndef $1" >> $TMPH
570+ echo "#define $1 \"$v\"" >> $TMPH
571+ test -n "$3" && echo "#endif" >> $TMPH
566572 fi
567573 }
568574
569−print_mak() {
575+print_num() {
570576 local v="$2"
571577 if test -n "$v"; then
572− test "$3" = "num" || v="\"\\\"$v\\\"\""
573− echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
578+ test -n "$3" && echo "#ifndef $1" >> $TMPH
579+ echo "#define $1 $v" >> $TMPH
580+ test -n "$3" && echo "#endif" >> $TMPH
574581 fi
575582 }
576583
577−echo "/* Automatically generated by configure - do not modify */" > $TMPH
578−
579−print_inc CONFIG_SYSROOT "$sysroot"
580−test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
581−print_inc DWARF_VERSION "$dwarf" num
582−print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
583−print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
584−print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
585−print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
586−print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
587−print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
588−print_mak CONFIG_LDDIR "$tcc_lddir"
589−print_mak CONFIG_TRIPLET "$triplet"
590−print_mak TCC_CPU_VERSION "$cpuver" num
591−
592−echo "ARCH=$cpu" >> config.mak
593−echo "TARGETOS=$targetos" >> config.mak
594−echo "BUILDOS=$buildos" >> config.mak
595−
596−predefs="1"
597−for v in $confvars ; do
598− test "$v" = "predefs=no" && predefs=""
599− if test "${v%=*}" = "$v"; then
600− echo "CONFIG_$v=yes" >> config.mak
601− else
602− echo "CONFIG_$v" >> config.mak
603− fi
604−done
605−print_inc CONFIG_TCC_PREDEFS "$predefs" num
584+cat >$TMPH <<EOF
585+/* Automatically generated by configure - do not modify */
606586
607−version=`head $source_path/VERSION`
608−echo "VERSION = $version" >> config.mak
609−echo "#define TCC_VERSION \"$version\"" >> $TMPH
610−echo "@set VERSION $version" > config.texi
587+#define TCC_VERSION "$version"
611588
612−if test "$source_path_used" = "yes" ; then
613− case $source_path in
614− /*) echo "TOPSRC=$source_path";;
615− *) echo "TOPSRC=\$(TOP)/$source_path";;
616− esac >>config.mak
617−else
618− echo 'TOPSRC=$(TOP)' >>config.mak
619−fi
620−cat >>$TMPH <<EOF
589+#define CC_NAME CC_$cc_name
621590 #define GCC_MAJOR $gcc_major
622591 #define GCC_MINOR $gcc_minor
623−#define CC_NAME CC_${cc_name}
592+
593+#if !CONFIG_TCC_CROSS
624594 EOF
625595
596+predefs=1
597+# options that are applied only to the native tcc
598+for v in $cpu $confvars ; do
599+ if test "${v%=*}" = "$v"; then
600+ v="$v=yes"
601+ fi
602+ R="CONFIG_$v"
603+ echo "$R" >> config.mak
604+ case "$R" in
605+ # CPU
606+ CONFIG_i386=yes) print_num TCC_TARGET_I386 1 ;;
607+ CONFIG_x86_64=yes) print_num TCC_TARGET_X86_64 1 ;;
608+ CONFIG_arm64=yes) print_num TCC_TARGET_ARM64 1 ;;
609+ CONFIG_riscv64=yes) print_num TCC_TARGET_RISCV64 1 ;;
610+ CONFIG_arm=yes) print_num TCC_TARGET_ARM 1
611+ print_num CONFIG_TCC_CPUVER "$cpuver" ;;
612+ CONFIG_arm_eabihf=yes) print_num TCC_ARM_EABI 1
613+ print_num TCC_ARM_HARDFLOAT 1 ;;
614+ CONFIG_arm_eabi=yes) print_num TCC_ARM_EABI 1 ;;
615+ CONFIG_arm_vfp=yes) print_num TCC_ARM_VFP 1 ;;
616+ # OS
617+ CONFIG_WIN32=yes) print_num TCC_TARGET_PE 1 ;;
618+ CONFIG_OSX=yes) print_num TCC_TARGET_MACHO 1 ;;
619+ CONFIG_Android=yes) print_num TARGETOS_ANDROID 1 ;;
620+ CONFIG_BSD=yes) print_num TARGETOS_$targetos 1
621+ case "$targetos" in
622+ FreeBSD) default tcc_elfinterp "/libexec/ld-elf.so.1";;
623+ FreeBSD_kernel)
624+ case "$cpu" in
625+ x86_64) default tcc_elfinterp "/lib/ld-kfreebsd-x86-64.so.1";;
626+ *) default tcc_elfinterp "/lib/ld.so.1";;
627+ esac ;;
628+ DragonFly) default tcc_elfinterp "/usr/libexec/ld-elf.so.2";;
629+ NetBSD) default tcc_elfinterp "/usr/libexec/ld.elf_so";;
630+ OpenBSD) default tcc_elfinterp "/usr/libexec/ld.so";;
631+ esac
632+ ;;
633+ CONFIG_uClibc=yes) print_num CONFIG_TCC_UCLIBC 1
634+ default tcc_elfinterp "/lib/ld-uClibc.so.0"
635+ ;;
636+ CONFIG_musl=yes) print_num CONFIG_TCC_MUSL 1
637+ case "$cpu" in
638+ arm64) default tcc_elfinterp "/lib/ld-musl-aarch64.so.1";;
639+ *) default tcc_elfinterp "/lib/ld-musl-${cpu}.so.1";;
640+ esac
641+ ;;
642+ # other
643+ CONFIG_libgcc=yes) print_num CONFIG_USE_LIBGCC 1 ;;
644+ CONFIG_selinux=yes) print_num CONFIG_SELINUX 1 ;;
645+ CONFIG_pie=yes) print_num CONFIG_TCC_PIE 1 ;;
646+ CONFIG_pic=yes) print_num CONFIG_TCC_PIC 1 ;;
647+ CONFIG_new_dtags=yes) print_num CONFIG_NEW_DTAGS 1 ;;
648+ CONFIG_codesign=yes) print_num CONFIG_CODESIGN 1 ;;
649+ CONFIG_new_macho=no) print_num CONFIG_NEW_MACHO 0 ;;
650+ CONFIG_bcheck=no) print_num CONFIG_TCC_BCHECK 0 ;;
651+ CONFIG_backtrace=no) print_num CONFIG_TCC_BACKTRACE 0 ;;
652+ CONFIG_dwarf=*) print_num CONFIG_DWARF_VERSION ${R#*=} ;;
653+ CONFIG_semlock=*) print_num CONFIG_TCC_SEMLOCK ${R#*=} ;;
654+ CONFIG_predefs=no) predefs=0 ;;
655+ esac
656+done
657+
658+print_str CONFIG_USR_INCLUDE "$tcc_usrinclude"
659+print_str CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
660+print_str CONFIG_TCC_LIBPATHS "$tcc_libpaths"
661+print_str CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
662+print_str CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
663+print_str CONFIG_TCC_SWITCHES "$tcc_switches"
664+print_str CONFIG_LDDIR "$tcc_lddir"
665+print_str CONFIG_TRIPLET "$triplet"
666+echo "#endif" >> $TMPH && echo >> $TMPH
667+
668+print_str CONFIG_SYSROOT "$sysroot" x
669+test "$tccdir_auto" = "yes" || print_str CONFIG_TCCDIR "$tccdir" x
670+print_num CONFIG_TCC_PREDEFS "$predefs"
671+
626672 diff $TMPH config.h >/dev/null 2>&1
627673 if test $? -ne 0 ; then
628674 mv -f $TMPH config.h
@@ -630,6 +676,8 @@ else · 1 unmodified line
630676 echo "config.h is unchanged"
631677 fi
632678
679+echo "@set VERSION $version" > config.texi
680+
633681 rm -f $TMPN* $CONFTEST
634682
635683 # ---------------------------------------------------------------------------
i386-gen.c+0−10
@@ -218,11 +218,6 @@ ST_FUNC void load(int r, SValue *sv) · 217 unmodified lines
218218 int v, t, ft, fc, fr;
219219 SValue v1;
220220
221−#ifdef TCC_TARGET_PE
222− SValue v2;
223− sv = pe_getimport(sv, &v2);
224−#endif
225−
226221 fr = sv->r;
227222 ft = sv->type.t & ~VT_DEFSIGN;
228223 fc = sv->c.i;
@@ -297,11 +292,6 @@ ST_FUNC void store(int r, SValue *v) · 68 unmodified lines
297292 {
298293 int fr, bt, ft, fc;
299294
300−#ifdef TCC_TARGET_PE
301− SValue v2;
302− v = pe_getimport(v, &v2);
303−#endif
304−
305295 ft = v->type.t;
306296 fc = v->c.i;
307297 fr = v->r & VT_VALMASK;
lib/Makefile+1−1
@@ -91,7 +91,7 @@ $(X)%.o : %.S $(TCC) · 90 unmodified lines
9191 $(TOP)/%.o : %.c $(TCC)
9292 $S$(XCC) -c $< -o $@ $(XFLAGS)
9393
94−$(TOP)/bcheck.o : XFLAGS += $(BFLAGS) $(if $(CONFIG_musl),-DTCC_MUSL)
94+$(TOP)/bcheck.o : XFLAGS += $(BFLAGS)
9595 $(TOP)/bt-exe.o : $(TOP)/tccrun.c
9696
9797 $(X)crt1w.o : crt1.c
lib/bcheck.c+4−2
@@ -37,6 +37,8 @@ · 36 unmodified lines
3737 #include <sys/syscall.h>
3838 #endif
3939
40+#include "config.h"
41+
4042 #define BOUND_DEBUG (1)
4143 #define BOUND_STATISTIC (1)
4244
@@ -161,7 +163,7 @@ static pthread_spinlock_t bounds_spin; · 118 unmodified lines
161163 #define HAVE_TLS_FUNC (1)
162164 #define HAVE_TLS_VAR (0)
163165 #endif
164−#if defined TCC_MUSL || defined __ANDROID__
166+#if defined CONFIG_TCC_MUSL || defined __ANDROID__
165167 # undef HAVE_CTYPE
166168 #endif
167169 #endif
@@ -1187,7 +1189,7 @@ void __attribute__((destructor)) __bound_exit(void) · 1019 unmodified lines
11871189 dprintf(stderr, "%s, %s():\n", __FILE__, __FUNCTION__);
11881190
11891191 if (inited) {
1190−#if !defined(_WIN32) && !defined(__APPLE__) && !defined TCC_MUSL && \
1192+#if !defined(_WIN32) && !defined(__APPLE__) && !defined CONFIG_TCC_MUSL && \
11911193 !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
11921194 !defined(__ANDROID__)
11931195 if (print_heap) {
lib/bt-exe.c+0−1
@@ -5,7 +5,6 @@ · 4 unmodified lines
55 #define CONFIG_TCC_BACKTRACE_ONLY
66 #define ONE_SOURCE 1
77 #define pstrcpy tcc_pstrcpy
8−#define TCC_SEM_IMPL 1
98 #include "../tccrun.c"
109
1110 #ifndef _WIN32
libtcc.c+17−7
@@ -18,7 +18,11 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−#if !defined ONE_SOURCE || ONE_SOURCE
21+#ifndef ONE_SOURCE
22+# define ONE_SOURCE 1
23+#endif
24+
25+#if ONE_SOURCE
2226 #include "tccpp.c"
2327 #include "tccgen.c"
2428 #include "tccdbg.c"
@@ -60,7 +64,6 @@ · 35 unmodified lines
6064 #endif
6165 #endif /* ONE_SOURCE */
6266
63−#define TCC_SEM_IMPL 1
6467 #include "tcc.h"
6568
6669 /********************************************************/
@@ -1189,12 +1192,14 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) · 1122 unmodified lines
11891192 }
11901193
11911194 /* find [cross-]libtcc1.a and tcc helper objects in library path */
1192−ST_FUNC void tcc_add_support(TCCState *s1, const char *filename)
1195+ST_FUNC int tcc_add_support(TCCState *s1, const char *filename)
11931196 {
1197+#if CONFIG_TCC_CROSS
11941198 char buf[100];
11951199 if (CONFIG_TCC_CROSSPREFIX[0])
11961200 filename = strcat(strcpy(buf, CONFIG_TCC_CROSSPREFIX), filename);
1197− tcc_add_dll(s1, filename, AFF_PRINT_ERROR);
1201+#endif
1202+ return tcc_add_dll(s1, filename, AFF_PRINT_ERROR);
11981203 }
11991204
12001205 #if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO
@@ -1229,6 +1234,11 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 28 unmodified lines
12291234 return ret;
12301235 ++pp;
12311236 }
1237+#if CONFIG_TCC_CROSS
1238+ /* hack for '<cross>-tcc -nostdlib -ltcc1' to find <cross>-libtcc1.a */
1239+ if (0 == strcmp(libraryname, "tcc1"))
1240+ return tcc_add_support(s, TCC_LIBTCC1);
1241+#endif
12321242 return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR);
12331243 }
12341244
@@ -1750,7 +1760,7 @@ static const char dumpmachine_str[] = · 515 unmodified lines
17501760 "openbsd"
17511761 #elif TARGETOS_NetBSD
17521762 "netbsd"
1753−#elif TCC_MUSL
1763+#elif CONFIG_TCC_MUSL
17541764 "linux-musl"
17551765 #else
17561766 "linux-gnu"
@@ -1941,7 +1951,7 @@ dorun: · 184 unmodified lines
19411951 enable_backtrace:
19421952 s->do_backtrace = 1;
19431953 s->do_debug = s->do_debug ? s->do_debug : 1;
1944− s->dwarf = DWARF_VERSION;
1954+ s->dwarf = CONFIG_DWARF_VERSION;
19451955 break;
19461956 #ifdef CONFIG_TCC_BCHECK
19471957 case TCC_OPTION_b:
@@ -1951,7 +1961,7 @@ dorun: · 3 unmodified lines
19511961 #endif
19521962 case TCC_OPTION_g:
19531963 s->do_debug = 2;
1954− s->dwarf = DWARF_VERSION;
1964+ s->dwarf = CONFIG_DWARF_VERSION;
19551965 if (strstart("dwarf", &optarg)) {
19561966 s->dwarf = (*optarg) ? (0 - atoi(optarg)) : DEFAULT_DWARF_VERSION;
19571967 } else if (isnum(*optarg)) {
riscv64-asm.c+1−1
@@ -1614,7 +1614,7 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, · 1613 unmodified lines
16141614 /* push */
16151615 /* addi sp, sp, -offset */
16161616 gen_le32((4 << 2) | 3 |
1617− ENCODE_RD(2) | ENCODE_RS1(2) | -8 << 20);
1617+ ENCODE_RD(2) | ENCODE_RS1(2) | (unsigned)-8 << 20);
16181618 if (REG_IS_FLOAT(reg)){
16191619 /* fsd reg, offset(sp) */
16201620 gen_le32( 0x27 | (3 << 12) |
tcc.c+4−0
@@ -18,6 +18,10 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#ifndef ONE_SOURCE
22+# define ONE_SOURCE 1
23+#endif
24+
2125 #include "tcc.h"
2226 #if ONE_SOURCE
2327 # include "libtcc.c"
tcc.h+48−96
@@ -212,7 +212,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 211 unmodified lines
212212 || defined TARGETOS_FreeBSD_kernel
213213 # define TARGETOS_BSD 1
214214 #elif !(defined TCC_TARGET_PE || defined TCC_TARGET_MACHO)
215−# define TARGETOS_Linux 1
215+# define TARGETOS_Linux 1 /* for tccdefs_.h */
216216 #endif
217217
218218 #if defined TCC_TARGET_PE || defined TCC_TARGET_MACHO
@@ -231,6 +231,11 @@ extern long double strtold (const char *__nptr, char **__endptr); · 12 unmodified lines
231231 # define CONFIG_TCC_PIC 1
232232 #endif
233233
234+/* support using libtcc from threads */
235+#ifndef CONFIG_TCC_SEMLOCK
236+# define CONFIG_TCC_SEMLOCK 1
237+#endif
238+
234239 /* ------------ path configuration ------------ */
235240
236241 #ifndef CONFIG_SYSROOT
@@ -288,58 +293,26 @@ extern long double strtold (const char *__nptr, char **__endptr); · 51 unmodified lines
288293
289294 /* name of ELF interpreter */
290295 #ifndef CONFIG_TCC_ELFINTERP
291−# if TARGETOS_FreeBSD
292−# define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
293−# elif TARGETOS_FreeBSD_kernel
294−# if defined(TCC_TARGET_X86_64)
295−# define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
296−# else
297−# define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
298−# endif
299−# elif TARGETOS_DragonFly
300−# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
301−# elif TARGETOS_NetBSD
302−# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
303−# elif TARGETOS_OpenBSD
304−# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.so"
305−# elif defined __GNU__
296+# if defined __GNU__
306297 # define CONFIG_TCC_ELFINTERP "/lib/ld.so"
307298 # elif defined(TCC_TARGET_PE)
308299 # define CONFIG_TCC_ELFINTERP "-"
309−# elif defined(TCC_UCLIBC)
310−# define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
311300 # elif defined TCC_TARGET_ARM64
312−# if defined(TCC_MUSL)
313−# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
314−# else
315−# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
316−# endif
301+# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
317302 # elif defined(TCC_TARGET_X86_64)
318−# if defined(TCC_MUSL)
319−# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
320−# else
321−# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
322−# endif
303+# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
323304 # elif defined(TCC_TARGET_RISCV64)
324305 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-riscv64-lp64d.so.1"
325−# elif !defined(TCC_ARM_EABI)
326−# if defined(TCC_MUSL)
327−# if defined(TCC_TARGET_I386)
328−# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-i386.so.1"
329−# else
330−# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
331−# endif
332−# else
333−# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
334−# endif
306+# elif defined(TCC_ARM_EABI)
307+# define DEFAULT_ELFINTERP(s) default_elfinterp(s)
308+# else
309+# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
335310 # endif
336311 #endif
337312
338313 /* var elf_interp dans *-gen.c */
339−#ifdef CONFIG_TCC_ELFINTERP
314+#ifndef DEFAULT_ELFINTERP
340315 # define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
341−#else
342−# define DEFAULT_ELFINTERP(s) default_elfinterp(s)
343316 #endif
344317
345318 /* (target specific) libtcc1.a */
@@ -347,15 +320,16 @@ extern long double strtold (const char *__nptr, char **__endptr); · 1 unmodified line
347320 # define TCC_LIBTCC1 "libtcc1.a"
348321 #endif
349322
350−#ifndef CONFIG_TCC_CROSSPREFIX
351−# define CONFIG_TCC_CROSSPREFIX ""
352−#endif
353−
354323 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
355324 #if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
356325 #define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
357326 #endif
358327
328+/* <cross-prefix-to->libtcc1.a */
329+#ifndef CONFIG_TCC_CROSSPREFIX
330+# define CONFIG_TCC_CROSSPREFIX ""
331+#endif
332+
359333 /* -------------------------------------------- */
360334
361335 #include "libtcc.h"
@@ -370,12 +344,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 8 unmodified lines
370344 #endif
371345
372346 #ifndef ONE_SOURCE
373−# define ONE_SOURCE 1
374−#endif
375−
376−/* support using libtcc from threads */
377−#ifndef CONFIG_TCC_SEMLOCK
378−# define CONFIG_TCC_SEMLOCK 1
347+# define ONE_SOURCE 0
379348 #endif
380349
381350 #if ONE_SOURCE
@@ -1310,7 +1279,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 928 unmodified lines
13101279 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
13111280 #endif
13121281 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1313−ST_FUNC void tcc_add_support(TCCState *s1, const char *filename);
1282+ST_FUNC int tcc_add_support(TCCState *s1, const char *filename);
13141283 #ifdef CONFIG_TCC_BCHECK
13151284 ST_FUNC void tcc_add_bcheck(TCCState *s1);
13161285 #endif
@@ -1821,7 +1790,6 @@ ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename); · 504 unmodified lines
18211790 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
18221791 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
18231792 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1824−ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
18251793 #endif
18261794 #ifdef TCC_TARGET_X86_64
18271795 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
@@ -1924,8 +1892,8 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1); · 96 unmodified lines
19241892 #endif
19251893
19261894 /* default dwarf version for "-g". use 0 to emit stab debug infos */
1927−#ifndef DWARF_VERSION
1928−# define DWARF_VERSION 0 //DEFAULT_DWARF_VERSION
1895+#ifndef CONFIG_DWARF_VERSION
1896+# define CONFIG_DWARF_VERSION 0
19291897 #endif
19301898
19311899 #if defined TCC_TARGET_PE
@@ -1939,16 +1907,38 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1); · 7 unmodified lines
19391907 /********************************************************/
19401908 #if CONFIG_TCC_SEMLOCK
19411909 #if defined _WIN32
1942−typedef struct { int init; CRITICAL_SECTION cr; } TCCSem;
1910+typedef struct { int init; CRITICAL_SECTION cs; } TCCSem;
1911+static inline void wait_sem(TCCSem *p) {
1912+ if (!p->init)
1913+ InitializeCriticalSection(&p->cs), p->init = 1;
1914+ EnterCriticalSection(&p->cs);
1915+}
1916+static inline void post_sem(TCCSem *p) {
1917+ LeaveCriticalSection(&p->cs);
1918+}
19431919 #elif defined __APPLE__
19441920 #include <dispatch/dispatch.h>
19451921 typedef struct { int init; dispatch_semaphore_t sem; } TCCSem;
1922+static inline void wait_sem(TCCSem *p) {
1923+ if (!p->init)
1924+ p->sem = dispatch_semaphore_create(1), p->init = 1;
1925+ dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER);
1926+}
1927+static inline void post_sem(TCCSem *p) {
1928+ dispatch_semaphore_signal(p->sem);
1929+}
19461930 #else
19471931 #include <semaphore.h>
19481932 typedef struct { int init; sem_t sem; } TCCSem;
1933+static inline void wait_sem(TCCSem *p) {
1934+ if (!p->init)
1935+ sem_init(&p->sem, 0, 1), p->init = 1;
1936+ while (sem_wait(&p->sem) < 0 && errno == EINTR);
1937+}
1938+static inline void post_sem(TCCSem *p) {
1939+ sem_post(&p->sem);
1940+}
19491941 #endif
1950−ST_FUNC void wait_sem(TCCSem *p);
1951−ST_FUNC void post_sem(TCCSem *p);
19521942 #define TCC_SEM(s) TCCSem s
19531943 #define WAIT_SEM wait_sem
19541944 #define POST_SEM post_sem
@@ -2009,41 +1999,3 @@ PUB_FUNC void tcc_exit_state(TCCState *s1); · 54 unmodified lines
20091999 # define TCC_SET_STATE(fn) (tcc_enter_state(s1),fn)
20102000 # define _tcc_error use_tcc_error_noabort
20112001 #endif
2012−
2013−#if CONFIG_TCC_SEMLOCK && TCC_SEM_IMPL
2014−#undef TCC_SEM_IMPL
2015−#if defined _WIN32
2016−ST_FUNC void wait_sem(TCCSem *p)
2017−{
2018− if (!p->init)
2019− InitializeCriticalSection(&p->cr), p->init = 1;
2020− EnterCriticalSection(&p->cr);
2021−}
2022−ST_FUNC void post_sem(TCCSem *p)
2023−{
2024− LeaveCriticalSection(&p->cr);
2025−}
2026−#elif defined __APPLE__
2027−ST_FUNC void wait_sem(TCCSem *p)
2028−{
2029− if (!p->init)
2030− p->sem = dispatch_semaphore_create(1), p->init = 1;
2031− dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER);
2032−}
2033−ST_FUNC void post_sem(TCCSem *p)
2034−{
2035− dispatch_semaphore_signal(p->sem);
2036−}
2037−#else
2038−ST_FUNC void wait_sem(TCCSem *p)
2039−{
2040− if (!p->init)
2041− sem_init(&p->sem, 0, 1), p->init = 1;
2042− while (sem_wait(&p->sem) < 0 && errno == EINTR);
2043−}
2044−ST_FUNC void post_sem(TCCSem *p)
2045−{
2046− sem_post(&p->sem);
2047−}
2048−#endif
2049−#endif
tccasm.c+10−3
@@ -826,6 +826,7 @@ static void asm_parse_directive(TCCState *s1, int global) · 825 unmodified lines
826826 {
827827 Sym *sym;
828828 const char *newtype;
829+ int st_type;
829830
830831 next();
831832 sym = get_asm_sym(tok, NULL);
@@ -840,11 +841,17 @@ static void asm_parse_directive(TCCState *s1, int global) · 8 unmodified lines
840841 }
841842
842843 if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
843− sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC;
844+ if (IS_ASM_SYM(sym))
845+ sym->type.t = (sym->type.t & ~VT_ASM) | VT_ASM_FUNC;
846+ st_type = STT_FUNC;
847+ set_st_type:
844848 if (sym->c) {
845849 ElfSym *esym = elfsym(sym);
846− esym->st_info = ELFW(ST_INFO)(ELFW(ST_BIND)(esym->st_info), STT_FUNC);
850+ esym->st_info = ELFW(ST_INFO)(ELFW(ST_BIND)(esym->st_info), st_type);
847851 }
852+ } else if (!strcmp(newtype, "object") || !strcmp(newtype, "STT_OBJECT")) {
853+ st_type = STT_OBJECT;
854+ goto set_st_type;
848855 } else
849856 tcc_warning_c(warn_unsupported)("change type of '%s' from 0x%x to '%s' ignored",
850857 get_tok_str(sym->v, NULL), sym->type.t, newtype);
@@ -1381,7 +1388,7 @@ ST_FUNC void asm_global_instr(void) · 530 unmodified lines
13811388 expect("';'");
13821389
13831390 #ifdef ASM_DEBUG
1384− printf("asm_global: \"%s\"\n", (char *)astr.data);
1391+ printf("asm_global: \"%s\"\n", (char *)astr->data);
13851392 #endif
13861393 cur_text_section = text_section;
13871394 ind = cur_text_section->data_offset;
tccelf.c+43−38
@@ -90,6 +90,8 @@ ST_FUNC void tccelf_new(TCCState *s) · 89 unmodified lines
9090 }
9191
9292 #if TCC_EH_FRAME
93+ if (s->output_format != TCC_OUTPUT_FORMAT_ELF)
94+ s->unwind_tables = 0;
9395 tcc_eh_frame_start(s);
9496 #endif
9597
@@ -101,6 +103,13 @@ ST_FUNC void tccelf_new(TCCState *s) · 5 unmodified lines
101103 lbounds_section = new_section(s, ".lbounds", SHT_PROGBITS, shf_RELRO);
102104 }
103105 #endif
106+
107+#ifdef TCC_TARGET_PE
108+ /* to make sure that -ltcc1 -Wl,-e,_start will grab the startup code
109+ from libtcc1.a (unless _start defined) */
110+ if (s->elf_entryname)
111+ set_global_sym(s, s->elf_entryname, NULL, 0); /* SHN_UNDEF */
112+#endif
104113 }
105114
106115 ST_FUNC void free_section(Section *s)
@@ -2157,10 +2166,8 @@ static int sort_sections(TCCState *s1, int *sec_order, struct dyn_inf *d) · 2050 unmodified lines
21572166 } else {
21582167 j = 0x700;
21592168 }
2160− if (s1->output_format != TCC_OUTPUT_FORMAT_ELF) {
2161− if (j >= 0x700 || 0 == strncmp(s->name, ".eh_frame", 9))
2162− s->sh_size = 0, j = 0x900;
2163− }
2169+ if (j >= 0x700 && s1->output_format != TCC_OUTPUT_FORMAT_ELF)
2170+ s->sh_size = 0, j = 0x900;
21642171
21652172 if (s->sh_type == SHT_SYMTAB || s->sh_type == SHT_DYNSYM) {
21662173 k = 0x10;
@@ -3149,23 +3156,24 @@ invalid: · 982 unmodified lines
31493156 if (sh->sh_type == SHT_RELX)
31503157 sh = &shdr[sh->sh_info];
31513158 /* ignore sections types we do not handle (plus relocs to those) */
3152− if (0 == strncmp(strsec + sh->sh_name, ".debug_", 7)
3153− || 0 == strncmp(strsec + sh->sh_name, ".stab", 5)) {
3159+ sh_name = strsec + sh->sh_name;
3160+ if (0 == strncmp(sh_name, ".debug_", 7)
3161+ || 0 == strncmp(sh_name, ".stab", 5)) {
31543162 if (!s1->do_debug || seencompressed)
31553163 continue;
3164+ } else if (0 == strncmp(sh_name, ".eh_frame", 9)) {
3165+ if (NULL == eh_frame_section)
3166+ continue;
31563167 } else
31573168 if (sh->sh_type != SHT_PROGBITS &&
3158−#ifdef TCC_ARM_EABI
3159− sh->sh_type != SHT_ARM_EXIDX &&
3160−#endif
3161−#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
3162− sh->sh_type != SHT_X86_64_UNWIND &&
3163−#endif
31643169 sh->sh_type != SHT_NOTE &&
31653170 sh->sh_type != SHT_NOBITS &&
31663171 sh->sh_type != SHT_PREINIT_ARRAY &&
31673172 sh->sh_type != SHT_INIT_ARRAY &&
31683173 sh->sh_type != SHT_FINI_ARRAY
3174+#ifdef TCC_ARM_EABI
3175+ && sh->sh_type != SHT_ARM_EXIDX
3176+#endif
31693177 )
31703178 continue;
31713179
@@ -3176,24 +3184,29 @@ invalid: · 4 unmodified lines
31763184 /* find corresponding section, if any */
31773185 for(j = 1; j < s1->nb_sections;j++) {
31783186 s = s1->sections[j];
3179− if (!strcmp(s->name, sh_name)) {
3180− if (!strncmp(sh_name, ".gnu.linkonce",
3181− sizeof(".gnu.linkonce") - 1)) {
3182− /* if a 'linkonce' section is already present, we
3183− do not add it again. It is a little tricky as
3184− symbols can still be defined in
3185− it. */
3186− sm_table[i].link_once = 1;
3187− goto next;
3188− }
3189− if (stab_section) {
3190− if (s == stab_section)
3191− stab_index = i;
3192− if (s == stab_section->link)
3193− stabstr_index = i;
3194− }
3195− goto found;
3187+ if (strcmp(s->name, sh_name))
3188+ continue;
3189+ if (sh->sh_type != s->sh_type
3190+ && s != eh_frame_section
3191+ ) {
3192+ tcc_error_noabort("section type conflict: %s %02x <> %02x", s->name, sh->sh_type, s->sh_type);
3193+ goto the_end;
31963194 }
3195+ if (!strncmp(sh_name, ".gnu.linkonce", 13)) {
3196+ /* if a 'linkonce' section is already present, we
3197+ do not add it again. It is a little tricky as
3198+ symbols can still be defined in
3199+ it. */
3200+ sm_table[i].link_once = 1;
3201+ goto next;
3202+ }
3203+ if (stab_section) {
3204+ if (s == stab_section)
3205+ stab_index = i;
3206+ if (s == stab_section->link)
3207+ stabstr_index = i;
3208+ }
3209+ goto found;
31973210 }
31983211 /* not found: create new section */
31993212 s = new_section(s1, sh_name, sh->sh_type, sh->sh_flags & ~SHF_GROUP);
@@ -3203,14 +3216,6 @@ invalid: · 3 unmodified lines
32033216 s->sh_entsize = sh->sh_entsize;
32043217 sm_table[i].new_section = 1;
32053218 found:
3206− if (sh->sh_type != s->sh_type
3207−#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
3208− && strcmp (s->name, ".eh_frame")
3209−#endif
3210− ) {
3211− tcc_error_noabort("invalid section type");
3212− goto the_end;
3213− }
32143219 /* align start of section */
32153220 s->data_offset += -s->data_offset & (sh->sh_addralign - 1);
32163221 if (sh->sh_addralign > s->sh_addralign)
@@ -3907,7 +3912,7 @@ static int ld_add_file(TCCState *s1, const char filename[]) · 690 unmodified lines
39073912
39083913 static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
39093914 {
3910− char filename[1024], libname[1024];
3915+ char filename[1024], libname[1016];
39113916 int t, group, nblibs = 0, ret = 0;
39123917 char **libs = NULL;
39133918
tccgen.c+8−2
@@ -157,6 +157,7 @@ static void gv_dup(void); · 156 unmodified lines
157157 static int get_temp_local_var(int size,int align,int *r2);
158158 static void cast_error(CType *st, CType *dt);
159159 static void end_switch(void);
160+static void do_Static_assert(void);
160161
161162 /* ------------------------------------------------------------------------- */
162163 /* Automagical code suppression */
@@ -4340,8 +4341,6 @@ static void struct_layout(CType *type, AttributeDef *ad) · 4177 unmodified lines
43404341 }
43414342 }
43424343
4343−static void do_Static_assert(void);
4344−
43454344 /* enum/struct/union declaration. u is VT_ENUM/VT_STRUCT/VT_UNION */
43464345 static void struct_decl(CType *type, int u)
43474346 {
@@ -6027,6 +6026,13 @@ special_math_val: · 1679 unmodified lines
60276026
60286027 if (r & VT_SYM) {
60296028 vtop->c.i = 0;
6029+#ifdef TCC_TARGET_PE
6030+ if (s->a.dllimport) {
6031+ mk_pointer(&vtop->type);
6032+ vtop->r |= VT_LVAL;
6033+ indir();
6034+ }
6035+#endif
60306036 } else if (r == VT_CONST && IS_ENUM_VAL(s->type.t)) {
60316037 vtop->c.i = s->enum_val;
60326038 }
tccpe.c+48−130
@@ -384,47 +384,6 @@ static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym) · 383 unmodified lines
384384 return name;
385385 }
386386
387−static int pe_find_import(TCCState * s1, ElfW(Sym) *sym)
388−{
389− char buffer[200];
390− const char *s, *p;
391− int sym_index = 0, n = 0;
392− int a, err = 0;
393−
394− do {
395− s = pe_export_name(s1, sym);
396− a = 0;
397− if (n) {
398− /* second try: */
399− if (sym->st_other & ST_PE_STDCALL) {
400− /* try w/0 stdcall deco (windows API convention) */
401− p = strrchr(s, '@');
402− if (!p || s[0] != '_')
403− break;
404− strcpy(buffer, s+1)[p-s-1] = 0;
405− } else if (s[0] != '_') { /* try non-ansi function */
406− buffer[0] = '_', strcpy(buffer + 1, s);
407− } else if (0 == memcmp(s, "__imp_", 6)) { /* mingw 2.0 */
408− strcpy(buffer, s + 6), a = 1;
409− } else if (0 == memcmp(s, "_imp__", 6)) { /* mingw 3.7 */
410− strcpy(buffer, s + 6), a = 1;
411− } else {
412− continue;
413− }
414− s = buffer;
415− }
416− sym_index = find_elf_sym(s1->dynsymtab_section, s);
417− // printf("find (%d) %d %s\n", n, sym_index, s);
418− if (sym_index
419− && ELFW(ST_TYPE)(sym->st_info) == STT_OBJECT
420− && 0 == (sym->st_other & ST_PE_IMPORT)
421− && 0 == a
422− ) err = -1, sym_index = 0;
423− } while (0 == sym_index && ++n < 2);
424− return n == 2 ? err : sym_index;
425−}
426−
427−/*----------------------------------------------------------------------------*/
428387
429388 static int dynarray_assoc(void **pp, int n, int key)
430389 {
@@ -905,12 +864,16 @@ static void pe_build_imports(struct pe_info *pe) · 474 unmodified lines
905864 int iat_index = p->symbols[k]->iat_index;
906865 int sym_index = p->symbols[k]->sym_index;
907866 ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;
908− ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index;
909867 const char *name = (char*)pe->s1->dynsymtab_section->link->data + imp_sym->st_name;
910868 int ordinal;
911869
912− org_sym->st_value = thk_ptr;
913− org_sym->st_shndx = pe->thunk->sh_num;
870+ /* patch symbol (and possibly its underscored alias) */
871+ do {
872+ ElfW(Sym) *esym = (ElfW(Sym) *)symtab_section->data + iat_index;
873+ iat_index = esym->st_value;
874+ esym->st_value = thk_ptr;
875+ esym->st_shndx = pe->thunk->sh_num;
876+ } while (iat_index);
914877
915878 if (dllref)
916879 v = 0, ordinal = imp_sym->st_value; /* ordinal from pe_load_def */
@@ -1276,34 +1239,9 @@ add_section: · 359 unmodified lines
12761239 return 0;
12771240 }
12781241
1279−/*----------------------------------------------------------------------------*/
1280−
1281−static int pe_isafunc(TCCState *s1, int sym_index)
1282−{
1283− Section *sr = text_section->reloc;
1284− ElfW_Rel *rel, *rel_end;
1285− ElfW(Addr)info = ELFW(R_INFO)(sym_index, R_XXX_FUNCCALL);
1286−#ifdef R_XXX_FUNCCALL2
1287− ElfW(Addr)info2 = ELFW(R_INFO)(sym_index, R_XXX_FUNCCALL2);
1288−#endif
1289− if (!sr)
1290− return 0;
1291− rel_end = (ElfW_Rel *)(sr->data + sr->data_offset);
1292− for (rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) {
1293− if (rel->r_info == info)
1294− return 1;
1295−#ifdef R_XXX_FUNCCALL2
1296− if (rel->r_info == info2)
1297− return 1;
1298−#endif
1299− }
1300− return 0;
1301−}
1302−
13031242 /*----------------------------------------------------------------------------*/
13041243 static int pe_check_symbols(struct pe_info *pe)
13051244 {
1306− ElfW(Sym) *sym;
13071245 int sym_index, sym_end;
13081246 int ret = 0;
13091247 TCCState *s1 = pe->s1;
@@ -1312,34 +1250,54 @@ static int pe_check_symbols(struct pe_info *pe) · 2 unmodified lines
13121250
13131251 sym_end = symtab_section->data_offset / sizeof(ElfW(Sym));
13141252 for (sym_index = 1; sym_index < sym_end; ++sym_index) {
1315−
1316− sym = (ElfW(Sym) *)symtab_section->data + sym_index;
1253+ ElfW(Sym) *sym = (ElfW(Sym) *)symtab_section->data + sym_index;
13171254 if (sym->st_shndx == SHN_UNDEF) {
1318−
13191255 const char *name = (char*)symtab_section->link->data + sym->st_name;
13201256 unsigned type = ELFW(ST_TYPE)(sym->st_info);
1321− int imp_sym = pe_find_import(pe->s1, sym);
1257+ int imp_sym;
13221258 struct import_symbol *is;
13231259
1324− if (imp_sym <= 0)
1325− goto not_found;
1260+ int _imp_, n;
1261+ char buffer[200];
1262+ const char *s, *p;
13261263
1327− if (type == STT_NOTYPE) {
1328− /* symbols from assembler have no type, find out which */
1329− if (pe_isafunc(s1, sym_index))
1330− type = STT_FUNC;
1331− else
1332− type = STT_OBJECT;
1333− }
1264+ n = _imp_ = 0;
1265+ do {
1266+ s = pe_export_name(s1, sym);
1267+ if (n) {
1268+ /* second try: */
1269+ if (sym->st_other & ST_PE_STDCALL) {
1270+ /* try w/0 stdcall deco (windows API convention) */
1271+ p = strrchr(s, '@');
1272+ if (!p || s[0] != '_')
1273+ break;
1274+ strcpy(buffer, s+1)[p-s-1] = 0, s = buffer;
1275+ } else if (s[0] != '_') { /* try non-ansi function */
1276+ buffer[0] = '_', strcpy(buffer + 1, s), s = buffer;
1277+ } else if (0 == memcmp(s, "_imp__", 6)) { /* mingw 3.7 */
1278+ s += 6, _imp_ = 1;
1279+ } else if (0 == memcmp(s, "__imp_", 6)) { /* mingw 2.0 */
1280+ s += 6, _imp_ = 1;
1281+ } else {
1282+ break;
1283+ }
1284+ }
1285+ imp_sym = find_elf_sym(s1->dynsymtab_section, s);
1286+ } while (0 == imp_sym && ++n < 2);
1287+
1288+ //printf("pe_find_export (%d) %4x %s\n", n, imp_sym, name);
1289+ if (0 == imp_sym)
1290+ continue; /* will throw the 'undefined' error in relocate_syms() */
13341291
13351292 is = pe_add_import(pe, imp_sym);
13361293
1337− if (type == STT_FUNC) {
1294+ if (type == STT_FUNC
1295+ /* symbols from assembler often have no type */
1296+ || type == STT_NOTYPE) {
13381297 unsigned offset = is->thk_offset;
13391298 if (offset) {
13401299 /* got aliased symbol, like stricmp and _stricmp */
13411300 } else {
1342− char buffer[100];
13431301 unsigned char *p;
13441302
13451303 /* add a helper symbol, will be patched later in
@@ -1372,29 +1330,19 @@ static int pe_check_symbols(struct pe_info *pe) · 26 unmodified lines
13721330 }
13731331 /* tcc_realloc might have altered sym's address */
13741332 sym = (ElfW(Sym) *)symtab_section->data + sym_index;
1375−
13761333 /* patch the original symbol */
13771334 sym->st_value = offset;
13781335 sym->st_shndx = text_section->sh_num;
13791336 sym->st_other &= ~ST_PE_EXPORT; /* do not export */
1380− continue;
1381− }
13821337
1383− if (type == STT_OBJECT) { /* data, ptr to that should be */
1384− if (0 == is->iat_index) {
1385− /* original symbol will be patched later in pe_build_imports */
1386− is->iat_index = sym_index;
1387− continue;
1388− }
1338+ } else { /* STT_OBJECT */
1339+ if (0 == _imp_ && 0 == (sym->st_other & ST_PE_IMPORT))
1340+ ret = tcc_error_noabort("symbol '%s' is missing __declspec(dllimport)", name);
1341+ /* original symbol will be patched later in pe_build_imports */
1342+ sym->st_value = is->iat_index; /* chain potential alias */
1343+ is->iat_index = sym_index;
13891344 }
13901345
1391− not_found:
1392− if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK)
1393− /* STB_WEAK undefined symbols are accepted */
1394− continue;
1395− ret = tcc_error_noabort("undefined symbol '%s'%s", name,
1396− imp_sym < 0 ? ", missing __declspec(dllimport)?":"");
1397−
13981346 } else if (pe->s1->rdynamic
13991347 && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
14001348 /* if -rdynamic option, then export all non local symbols */
@@ -1544,36 +1492,6 @@ static void pe_print_sections(TCCState *s1, const char *fname) · 143 unmodified lines
15441492 #endif
15451493
15461494 /* ------------------------------------------------------------- */
1547−/* helper function for load/store to insert one more indirection */
1548−
1549−#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1550−ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2)
1551−{
1552− int r2;
1553− if ((sv->r & (VT_VALMASK|VT_SYM)) != (VT_CONST|VT_SYM) || (sv->r2 != VT_CONST))
1554− return sv;
1555− if (!sv->sym->a.dllimport)
1556− return sv;
1557− // printf("import %04x %04x %04x %s\n", sv->type.t, sv->sym->type.t, sv->r, get_tok_str(sv->sym->v, NULL));
1558− memset(v2, 0, sizeof *v2);
1559− v2->type.t = VT_PTR;
1560− v2->r = VT_CONST | VT_SYM | VT_LVAL;
1561− v2->sym = sv->sym;
1562−
1563− r2 = get_reg(RC_INT);
1564− load(r2, v2);
1565− v2->r = r2;
1566− if ((uint32_t)sv->c.i) {
1567− vpushv(v2);
1568− vpushi(sv->c.i);
1569− gen_opi('+');
1570− *v2 = *vtop--;
1571− }
1572− v2->type.t = sv->type.t;
1573− v2->r |= sv->r & VT_LVAL;
1574− return v2;
1575−}
1576−#endif
15771495
15781496 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value)
15791497 {
tccpp.c+7−6
@@ -1927,15 +1927,18 @@ ST_FUNC void preprocess(int is_bof) · 1926 unmodified lines
19271927 tok_flags |= TOK_FLAG_ENDIF;
19281928 }
19291929 break;
1930+
19301931 case TOK_LINE:
19311932 next_nomacro();
19321933 if (tok != TOK_PPNUM) {
19331934 _line_err:
1934− if (parse_flags & PARSE_FLAG_ASM_FILE)
1935− goto ignore;
19361935 tcc_error("wrong #line format");
19371936 }
1937+ goto _line_num;
19381938 case TOK_PPNUM:
1939+ if (parse_flags & PARSE_FLAG_ASM_FILE)
1940+ goto ignore;
1941+ _line_num:
19391942 for (n = 0, q = tokc.str.data; *q; ++q) {
19401943 if (!isnum(*q))
19411944 goto _line_err;
@@ -1948,9 +1951,7 @@ ST_FUNC void preprocess(int is_bof) · 6 unmodified lines
19481951 tccpp_putfile(tokc.str.data + 1);
19491952 } else
19501953 goto _line_err;
1951− next_nomacro();
1952− } else if (parse_flags & PARSE_FLAG_ASM_FILE)
1953− goto ignore;
1954+ }
19541955 if (file->fd > 0)
19551956 total_lines += file->line_num - n;
19561957 file->line_num = n;
@@ -3586,7 +3587,7 @@ static void putdefs(CString *cs, const char *p) · 1629 unmodified lines
35863587
35873588 static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
35883589 {
3589− cstr_printf(cs, "#define __TINYC__ 9%.2s\n", TCC_VERSION + 4);
3590+ cstr_printf(cs, "#define __TINYC__ 9%.2s\n", *& TCC_VERSION + 4);
35903591 putdefs(cs, target_machine_defs);
35913592 putdefs(cs, target_os_defs);
35923593
tccrun.c+4−4
@@ -105,14 +105,14 @@ static void win64_del_function_table(void *); · 104 unmodified lines
105105 #define PAGEALIGN(n) ((addr_t)n + (-(addr_t)n & (PAGESIZE-1)))
106106
107107 #if !_WIN32 && !__APPLE__
108−//#define HAVE_SELINUX 1
108+//#define CONFIG_SELINUX 1
109109 #endif
110110
111111 static int rt_mem(TCCState *s1, int size)
112112 {
113113 void *ptr;
114114 int ptr_diff = 0;
115−#ifdef HAVE_SELINUX
115+#ifdef CONFIG_SELINUX
116116 /* Using mmap instead of malloc */
117117 void *prw;
118118 char tmpfname[] = "/tmp/.tccrunXXXXXX";
@@ -185,7 +185,7 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 66 unmodified lines
185185 return;
186186 st_unlink(s1);
187187 size = s1->run_size;
188−#ifdef HAVE_SELINUX
188+#ifdef CONFIG_SELINUX
189189 munmap(ptr, size);
190190 #else
191191 /* unprotect memory to make it usable for malloc again */
@@ -381,7 +381,7 @@ redo: · 189 unmodified lines
381381 if (copy == 2) { /* set permissions */
382382 if (n == 0) /* no data */
383383 continue;
384−#ifdef HAVE_SELINUX
384+#ifdef CONFIG_SELINUX
385385 if (k == 0) /* SHF_EXECINSTR has its own mapping */
386386 continue;
387387 #endif
tests/Makefile+23−23
@@ -4,8 +4,8 @@ · 3 unmodified lines
44
55 TOP = ..
66 include $(TOP)/Makefile
7−VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
8−CFLAGS := $(filter-out -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
7+VPATH = $(TOPSRC)/tests $(TOPSRC)
8+CFLAGS := $(filter-out -g% -O%,$(CFLAGS)) -I$(TOPSRC) -I$(TOP) $(LDFLAGS)
99
1010 # what tests to run
1111 TESTS = \
@@ -69,7 +69,7 @@ ifneq (,$(filter FreeBSD NetBSD,$(TARGETOS))) · 57 unmodified lines
6969 TESTS += test1
7070 endif
7171
72−RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
72+RUN_TCC = -run $(TOPSRC)/tcc.c $(TCCFLAGS)
7373 DISAS = objdump -d
7474 ifdef CONFIG_OSX
7575 DUMPTCC = (set -x; $(TOP)/tcc -vv; otool -L $(TOP)/tcc; exit 1)
@@ -95,13 +95,13 @@ hello-run: ../examples/ex1.c · 19 unmodified lines
9595
9696 libtes%: libtcc_tes%$(EXESUF)
9797 @echo ------------ $@ ------------
98− ./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES)
98+ ./libtcc_tes$*$(EXESUF) $(TOPSRC)/tcc.c $(TCCFLAGS)
9999
100−libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
101− $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
100+libtcc_test$(EXESUF): libtcc_test.c
101+ $(CC) -o $@ $< $(CFLAGS) $(-LTCC) $(LIBS)
102102
103−libtcc_test_mt$(EXESUF): libtcc_test_mt.c $(LIBTCC)
104− $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
103+libtcc_test_mt$(EXESUF): libtcc_test_mt.c
104+ $(CC) -o $@ $< $(CFLAGS) $(-LTCC) $(LIBS)
105105
106106 %-dir:
107107 @echo ------------ $@ ------------
@@ -109,7 +109,7 @@ libtcc_test_mt$(EXESUF): libtcc_test_mt.c $(LIBTCC) · 1 unmodified line
109109
110110 # test.ref - generate using cc
111111 test.ref: tcctest.c
112− $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
112+ $(CC) -o tcctest.gcc $< $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
113113 ./tcctest.gcc > $@
114114
115115 # auto test
@@ -161,23 +161,23 @@ test4_static: tcctest.c test.ref · 45 unmodified lines
161161 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
162162 dlltest:
163163 @echo ------------ $@ ------------
164− $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
165− $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
164+ $(TCC) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
165+ $(TCC) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
166166 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
167167 ifeq (,$(filter Darwin WIN32,$(TARGETOS)))
168168 @echo ------------ $@ with PIC ------------
169− $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
169+ $(CC) $(CFLAGS) -fPIC -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
170170 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
171− $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
171+ $(TCC) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
172172 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
173173 endif
174174 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
175175
176176 memtest:
177177 @echo ------------ $@ ------------
178− $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
179− ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
180− ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
178+ $(CC) $(CFLAGS) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
179+ ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(TOPSRC)/tcc.c $(LIBS)
180+ ./memtest-tcc$(EXESUF) $(TCCFLAGS) -run $(TOPSRC)/tcc.c $(TCCFLAGS) -w $(TOPSRC)/tests/tcctest.c
181181 @echo OK
182182
183183 # memory and bound check auto test
@@ -204,9 +204,9 @@ btest: boundtest.c · 20 unmodified lines
204204
205205 tccb:
206206 @echo ------------ $@ ------------
207− $(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
207+ $(TCC) -b $(TOPSRC)/tcc.c $(TCCFLAGS) -o tccb1.exe
208208 mv tccb1.exe tccb2.exe
209− ./tccb2.exe -b $(TOPSRC)/tcc.c $(TCCFLAGS) $(NATIVE_DEFINES) -o tccb1.exe
209+ ./tccb2.exe -b $(TOPSRC)/tcc.c $(TCCFLAGS) -o tccb1.exe
210210 cmp -s tccb1.exe tccb2.exe && echo "Exe Bound-Test OK"
211211
212212
@@ -221,7 +221,7 @@ speedtest: ex2 ex3 · 8 unmodified lines
221221 weaktest: tcctest.c test.ref
222222 @echo ------------ $@ ------------
223223 $(TCC) -c $< -o weaktest.tcc.o
224− $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
224+ $(CC) -c $< -o weaktest.gcc.o $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
225225 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
226226 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
227227 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
@@ -250,11 +250,11 @@ asmtest2: MAYBE_RUN_TCC = $(RUN_TCC) · 22 unmodified lines
250250
251251 # Check that code generated by libtcc is binary compatible with
252252 # that generated by CC
253−abitest-cc.exe: abitest.c $(LIBTCC)
254− $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
253+abitest-cc.exe: abitest.c
254+ $(CC) -o $@ $^ $(CFLAGS) $(-LTCC) $(LIBS) -w
255255
256256 abitest-tcc.exe: abitest.c libtcc.c
257− $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
257+ $(TCC) -o $@ $^ $(LIBS)
258258
259259 abitest-% : abitest-%.exe
260260 @echo ------------ $@ ------------
@@ -318,7 +318,7 @@ CROSS-TGTS = \ · 57 unmodified lines
318318
319319 define CROSS-COMPILE
320320 @echo " . $(1)"
321− $(TCC) $(DEF-$1) -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
321+ $(TCC) $(DEF-$1) -DCONFIG_TCC_CROSS -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
322322 -c $(if $(findstring c67,$1),$(filter %/ex3.c,$^),$<) -w $(TCCFLAGS)
323323
324324 endef
x86_64-gen.c+0−10
@@ -364,11 +364,6 @@ void load(int r, SValue *sv) · 363 unmodified lines
364364 int v, t, ft, fc, fr;
365365 SValue v1;
366366
367−#ifdef TCC_TARGET_PE
368− SValue v2;
369− sv = pe_getimport(sv, &v2);
370−#endif
371−
372367 fr = sv->r;
373368 ft = sv->type.t & ~VT_DEFSIGN;
374369 fc = sv->c.i;
@@ -573,11 +568,6 @@ void store(int r, SValue *v) · 198 unmodified lines
573568 /* store the REX prefix in this variable when PIC is enabled */
574569 int pic = 0;
575570
576−#ifdef TCC_TARGET_PE
577− SValue v2;
578− v = pe_getimport(v, &v2);
579−#endif
580−
581571 fr = v->r & VT_VALMASK;
582572 ft = v->type.t;
583573 fc = v->c.i;

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