Skip to content

Commit 0fb5430

Browse files
committed
Make bound checking faster.
With this commit bound checking will be about 20% .. 25% faster. (Tested with running testsuites with bound checking. About 1000 files.) The speedup is made possible because of TLS implementation. TLS is not possible with -run so create a new bcheck_run.o Makefile:lib/Makefile:win32/build-tcc.bat - Compile new bcheck_run.o tccelf.c:tccpe.c - Use bcheck_run.o lib/bcheck.c - Use TLS code
1 parent 1bcec04 commit 0fb5430

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ IR = $(IM) mkdir -p $2 && cp -r $1/. $2
372372
IM = @echo "-> $2 : $1" ;
373373
BINCHECK = $(if $(wildcard $(PROGS) *-tcc$(EXESUF)),,@echo "Makefile: nothing found to install" && exit 1)
374374

375-
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
375+
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o bcheck_run.o
376376

377377
# install progs & libs
378378
install-unx:

‎lib/Makefile‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ Cbc = $(Cbt)$(subst yes,,$(CONFIG_bcheck))
5353
$(Nat)COMMON_O += runmain.o tcov.o
5454
$(Cbt)COMMON_O += bt-exe.o bt-log.o
5555
$(Cbt)WIN_O += bt-dll.o
56-
$(Cbc)COMMON_O += bcheck.o
56+
$(Cbc)COMMON_O += bcheck.o bcheck_run.o
5757

5858
# not in libtcc1.a
59-
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
59+
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o bcheck_run.o
6060

6161
OBJ-i386 = $(I386_O) pic86.o $(LIN_O)
6262
OBJ-x86_64 = $(X86_64_O) va_list.o $(LIN_O)
@@ -95,6 +95,8 @@ $(TOP)/%.o : %.c $(TCC)
9595
$S$(XCC) -c $< -o $@ $(XFLAGS)
9696

9797
$(TOP)/bcheck.o : XFLAGS += $(BFLAGS)
98+
$(TOP)/bcheck_run.o : bcheck.c $(TCC)
99+
$S$(XCC) -c bcheck.c -o $@ $(XFLAGS) $(BFLAGS) -DBCHECK_RUN
98100

99101
$(X)crt1w.o : crt1.c
100102
$(X)wincrt1w.o : wincrt1.c

‎lib/bcheck.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
/* an __attribute__ macro is defined in the system headers */
5454
#undef __attribute__
5555
#endif
56+
#ifdef __i386__
5657
#define FASTCALL __attribute__((regparm(3)))
58+
#else
59+
#define FASTCALL
60+
#endif
5761

5862
#ifdef _WIN32
5963
# define DLL_EXPORT __declspec(dllexport)
@@ -157,12 +161,12 @@ static pthread_spinlock_t bounds_spin;
157161
#define HAVE_SIGNAL (1)
158162
#define HAVE_SIGACTION (1)
159163
#define HAVE_FORK (1)
160-
#if !defined(__APPLE__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
161-
#define HAVE_TLS_FUNC (0)
162-
#define HAVE_TLS_VAR (1)
163-
#else
164+
#if defined(__APPLE__) || defined(__arm__) || defined(__GNUC__) || defined(BCHECK_RUN)
164165
#define HAVE_TLS_FUNC (1)
165166
#define HAVE_TLS_VAR (0)
167+
#else
168+
#define HAVE_TLS_FUNC (0)
169+
#define HAVE_TLS_VAR (1)
166170
#endif
167171
#if defined CONFIG_TCC_MUSL || defined __ANDROID__
168172
# undef HAVE_CTYPE

‎tccelf.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,10 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
18391839

18401840
#ifdef CONFIG_TCC_BCHECK
18411841
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
1842-
tcc_add_support(s1, "bcheck.o");
1842+
if (s1->output_type == TCC_OUTPUT_MEMORY)
1843+
tcc_add_support(s1, "bcheck_run.o");
1844+
else
1845+
tcc_add_support(s1, "bcheck.o");
18431846
# if !(TARGETOS_OpenBSD || TARGETOS_NetBSD)
18441847
tcc_add_library(s1, "dl");
18451848
# endif

‎tccpe.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,8 +2131,12 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe)
21312131
#ifdef CONFIG_TCC_BACKTRACE
21322132
if (s1->do_backtrace) {
21332133
#ifdef CONFIG_TCC_BCHECK
2134-
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL)
2135-
tcc_add_support(s1, "bcheck.o");
2134+
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
2135+
if (s1->output_type == TCC_OUTPUT_MEMORY)
2136+
tcc_add_support(s1, "bcheck_run.o");
2137+
else
2138+
tcc_add_support(s1, "bcheck.o");
2139+
}
21362140
#endif
21372141
if (s1->output_type == TCC_OUTPUT_EXE)
21382142
tcc_add_support(s1, "bt-exe.o");

‎win32/build-tcc.bat‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ exit /B %ERRORLEVEL%
201201
.\%1tcc -B. -c ../lib/builtin.c
202202
.\%1tcc -ar lib/%1libtcc1.a %LIBTCC1%.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o winex.o chkstk.o alloca.o alloca-bt.o stdatomic.o atomic.o builtin.o
203203
.\%1tcc -B. -c ../lib/bcheck.c -o lib/%1bcheck.o -bt -I..
204+
.\%1tcc -B. -c ../lib/bcheck.c -o lib/%1bcheck_run.o -bt -I.. -DBCHECK_RUN
204205
.\%1tcc -B. -c ../lib/bt-exe.c -o lib/%1bt-exe.o
205206
.\%1tcc -B. -c ../lib/bt-log.c -o lib/%1bt-log.o
206207
.\%1tcc -B. -c ../lib/bt-dll.c -o lib/%1bt-dll.o

0 commit comments

Comments
 (0)