Make bound checking faster.
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-arm64-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
build and test / test-i386-linux (push) Has been cancelled

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
This commit is contained in:
herman ten brugge 2026-09-04 18:46:13 +02:00
parent 1bcec040d0
commit 0fb54300b5
6 changed files with 24 additions and 10 deletions

View File

@ -372,7 +372,7 @@ IR = $(IM) mkdir -p $2 && cp -r $1/. $2
IM = @echo "-> $2 : $1" ;
BINCHECK = $(if $(wildcard $(PROGS) *-tcc$(EXESUF)),,@echo "Makefile: nothing found to install" && exit 1)
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o bcheck_run.o
# install progs & libs
install-unx:

View File

@ -53,10 +53,10 @@ Cbc = $(Cbt)$(subst yes,,$(CONFIG_bcheck))
$(Nat)COMMON_O += runmain.o tcov.o
$(Cbt)COMMON_O += bt-exe.o bt-log.o
$(Cbt)WIN_O += bt-dll.o
$(Cbc)COMMON_O += bcheck.o
$(Cbc)COMMON_O += bcheck.o bcheck_run.o
# not in libtcc1.a
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o
EXTRA_O = runmain.o bt-exe.o bt-dll.o bt-log.o bcheck.o bcheck_run.o
OBJ-i386 = $(I386_O) pic86.o $(LIN_O)
OBJ-x86_64 = $(X86_64_O) va_list.o $(LIN_O)
@ -95,6 +95,8 @@ $(TOP)/%.o : %.c $(TCC)
$S$(XCC) -c $< -o $@ $(XFLAGS)
$(TOP)/bcheck.o : XFLAGS += $(BFLAGS)
$(TOP)/bcheck_run.o : bcheck.c $(TCC)
$S$(XCC) -c bcheck.c -o $@ $(XFLAGS) $(BFLAGS) -DBCHECK_RUN
$(X)crt1w.o : crt1.c
$(X)wincrt1w.o : wincrt1.c

View File

@ -53,7 +53,11 @@
/* an __attribute__ macro is defined in the system headers */
#undef __attribute__
#endif
#ifdef __i386__
#define FASTCALL __attribute__((regparm(3)))
#else
#define FASTCALL
#endif
#ifdef _WIN32
# define DLL_EXPORT __declspec(dllexport)
@ -157,12 +161,12 @@ static pthread_spinlock_t bounds_spin;
#define HAVE_SIGNAL (1)
#define HAVE_SIGACTION (1)
#define HAVE_FORK (1)
#if !defined(__APPLE__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define HAVE_TLS_FUNC (0)
#define HAVE_TLS_VAR (1)
#else
#if defined(__APPLE__) || defined(__arm__) || defined(__GNUC__) || defined(BCHECK_RUN)
#define HAVE_TLS_FUNC (1)
#define HAVE_TLS_VAR (0)
#else
#define HAVE_TLS_FUNC (0)
#define HAVE_TLS_VAR (1)
#endif
#if defined CONFIG_TCC_MUSL || defined __ANDROID__
# undef HAVE_CTYPE

View File

@ -1839,6 +1839,9 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
if (s1->output_type == TCC_OUTPUT_MEMORY)
tcc_add_support(s1, "bcheck_run.o");
else
tcc_add_support(s1, "bcheck.o");
# if !(TARGETOS_OpenBSD || TARGETOS_NetBSD)
tcc_add_library(s1, "dl");

View File

@ -2131,8 +2131,12 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe)
#ifdef CONFIG_TCC_BACKTRACE
if (s1->do_backtrace) {
#ifdef CONFIG_TCC_BCHECK
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL)
if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
if (s1->output_type == TCC_OUTPUT_MEMORY)
tcc_add_support(s1, "bcheck_run.o");
else
tcc_add_support(s1, "bcheck.o");
}
#endif
if (s1->output_type == TCC_OUTPUT_EXE)
tcc_add_support(s1, "bt-exe.o");

View File

@ -201,6 +201,7 @@ exit /B %ERRORLEVEL%
.\%1tcc -B. -c ../lib/builtin.c
.\%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
.\%1tcc -B. -c ../lib/bcheck.c -o lib/%1bcheck.o -bt -I..
.\%1tcc -B. -c ../lib/bcheck.c -o lib/%1bcheck_run.o -bt -I.. -DBCHECK_RUN
.\%1tcc -B. -c ../lib/bt-exe.c -o lib/%1bt-exe.o
.\%1tcc -B. -c ../lib/bt-log.c -o lib/%1bt-log.o
.\%1tcc -B. -c ../lib/bt-dll.c -o lib/%1bt-dll.o