Add -ba option for bounds_checking

This commit is contained in:
herman ten brugge 2019-12-12 13:29:45 +01:00
parent 4a2e33d160
commit 75145ddc1a
5 changed files with 12 additions and 1 deletions

View File

@ -1482,6 +1482,7 @@ enum {
TCC_OPTION_bench,
TCC_OPTION_bt,
TCC_OPTION_b,
TCC_OPTION_ba,
TCC_OPTION_g,
TCC_OPTION_c,
TCC_OPTION_dumpversion,
@ -1544,6 +1545,7 @@ static const TCCOption tcc_options[] = {
#endif
#ifdef CONFIG_TCC_BCHECK
{ "b", TCC_OPTION_b, 0 },
{ "ba", TCC_OPTION_ba, 0 },
#endif
{ "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "c", TCC_OPTION_c, 0 },
@ -1800,6 +1802,9 @@ reparse:
s->do_bounds_check = 1;
s->do_debug = 1;
break;
case TCC_OPTION_ba:
s->do_bounds_check_addres = 1;
break;
#endif
case TCC_OPTION_g:
s->do_debug = 1;

View File

@ -368,6 +368,9 @@ Try to continue in case of a bound checking error.
Note: @option{-b} is only available on i386 (linux and windows) and x86_64 (linux and windows) when using libtcc for the moment.
@item -ba
Generate address checking tests when using @option{-b}. This will be a lot slower but finds more errors.
@item -bt N
Display N callers in stack traces. This is useful with @option{-g} or
@option{-b}.

1
tcc.c
View File

@ -59,6 +59,7 @@ static const char help[] =
" -g generate runtime debug info\n"
#ifdef CONFIG_TCC_BCHECK
" -b compile with built-in memory and bounds checker (implies -g)\n"
" -ba Enable better addres checking with bounds checker\n"
#endif
#ifdef CONFIG_TCC_BACKTRACE
" -bt N show N callers in stack traces\n"

1
tcc.h
View File

@ -720,6 +720,7 @@ struct TCCState {
#ifdef CONFIG_TCC_BCHECK
/* compile with built-in memory and bounds checker */
unsigned char do_bounds_check;
unsigned char do_bounds_check_addres;
#endif
#ifdef TCC_TARGET_ARM
enum float_abi float_abi; /* float ABI of the generated code*/

View File

@ -2509,7 +2509,8 @@ redo:
*/
/* if evaluating constant expression, no code should be
generated, so no bound check */
if (tcc_state->do_bounds_check && !const_wanted && !nocode_wanted) {
if (tcc_state->do_bounds_check && tcc_state->do_bounds_check_addres
&& !const_wanted && !nocode_wanted) {
/* if bounded pointers, we generate a special code to
test bounds */
if (op == '-') {