From 75145ddc1a820fa85add69b69aacad021ea6b2b3 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Thu, 12 Dec 2019 13:29:45 +0100 Subject: [PATCH] Add -ba option for bounds_checking --- libtcc.c | 5 +++++ tcc-doc.texi | 3 +++ tcc.c | 1 + tcc.h | 1 + tccgen.c | 3 ++- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libtcc.c b/libtcc.c index dec552ca..682f831e 100644 --- a/libtcc.c +++ b/libtcc.c @@ -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; diff --git a/tcc-doc.texi b/tcc-doc.texi index 205ffcab..4409546f 100644 --- a/tcc-doc.texi +++ b/tcc-doc.texi @@ -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}. diff --git a/tcc.c b/tcc.c index 63250c69..ac1aa59b 100644 --- a/tcc.c +++ b/tcc.c @@ -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" diff --git a/tcc.h b/tcc.h index ca0eef88..2bccf215 100644 --- a/tcc.h +++ b/tcc.h @@ -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*/ diff --git a/tccgen.c b/tccgen.c index 63d1ae23..b6c35240 100644 --- a/tccgen.c +++ b/tccgen.c @@ -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 == '-') {