diff --git a/lib/bcheck.c b/lib/bcheck.c index 064fb5d4..968cdf4c 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -418,6 +418,13 @@ void __bound_init(void) } } +void __bound_main_arg(void **p) +{ + void *start = p; + while (*p++); + __bound_new_region(start, (void *) p - start); +} + void __bound_exit(void) { restore_malloc_hooks(); diff --git a/tccgen.c b/tccgen.c index b4f97f4c..fa03dafe 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5770,6 +5770,21 @@ static void gen_function(Sym *sym) /* push a dummy symbol to enable local sym storage */ sym_push2(&local_stack, SYM_FIELD, 0, 0); gfunc_prolog(&sym->type); +#ifdef CONFIG_TCC_BCHECK + if (tcc_state->do_bound_check + && !strcmp(get_tok_str(sym->v, NULL), "main")) { + int i; + + sym = local_stack; + for (i = 0, sym = local_stack; i < 2; i++, sym = sym->prev) { + if (sym->v & SYM_FIELD || sym->prev->v & SYM_FIELD) + break; + vpush_global_sym(&func_old_type, TOK___bound_main_arg); + vset(&sym->type, sym->r, sym->c); + gfunc_call(1); + } + } +#endif rsym = 0; block(NULL, NULL, NULL, NULL, 0, 0); gsym(rsym); diff --git a/tcctok.h b/tcctok.h index 73b0cf94..c17711f3 100644 --- a/tcctok.h +++ b/tcctok.h @@ -237,6 +237,7 @@ DEF(TOK___bound_ptr_indir8, "__bound_ptr_indir8") DEF(TOK___bound_ptr_indir12, "__bound_ptr_indir12") DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16") + DEF(TOK___bound_main_arg, "__bound_main_arg") DEF(TOK___bound_local_new, "__bound_local_new") DEF(TOK___bound_local_delete, "__bound_local_delete") # ifdef TCC_TARGET_PE