| @@ -51,6 +51,10 @@ · 50 unmodified lines |
| 51 | #define TCC_TARGET_I386 | 51 | #define TCC_TARGET_I386 |
| 52 | #endif | 52 | #endif |
| 53 | | 53 | |
| | 54 | #if !defined(WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_IL) |
| | 55 | #define CONFIG_TCC_BCHECK /* enable bound checking code */ |
| | 56 | #endif |
| | 57 | |
| 54 | /* amount of virtual memory associated to a section (currently, we do | 58 | /* amount of virtual memory associated to a section (currently, we do |
| 55 | not realloc them) */ | 59 | not realloc them) */ |
| 56 | #define SECTION_VSIZE (1024 * 1024) | 60 | #define SECTION_VSIZE (1024 * 1024) |
| @@ -454,6 +458,9 @@ char *tcc_keywords = · 397 unmodified lines |
| 454 | | 458 | |
| 455 | #ifdef WIN32 | 459 | #ifdef WIN32 |
| 456 | #define snprintf _snprintf | 460 | #define snprintf _snprintf |
| | 461 | #endif |
| | 462 | |
| | 463 | #if defined(WIN32) || defined(TCC_UCLIBC) |
| 457 | /* currently incorrect */ | 464 | /* currently incorrect */ |
| 458 | long double strtold(const char *nptr, char **endptr) | 465 | long double strtold(const char *nptr, char **endptr) |
| 459 | { | 466 | { |
| @@ -534,7 +541,9 @@ static inline int is_float(int t) · 74 unmodified lines |
| 534 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; | 541 | return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; |
| 535 | } | 542 | } |
| 536 | | 543 | |
| | 544 | #ifdef CONFIG_TCC_BCHECK |
| 537 | #include "bcheck.c" | 545 | #include "bcheck.c" |
| | 546 | #endif |
| 538 | | 547 | |
| 539 | #ifdef TCC_TARGET_I386 | 548 | #ifdef TCC_TARGET_I386 |
| 540 | #include "i386-gen.c" | 549 | #include "i386-gen.c" |
| @@ -797,10 +806,14 @@ static inline int toup(int c) · 256 unmodified lines |
| 797 | void printline(void) | 806 | void printline(void) |
| 798 | { | 807 | { |
| 799 | BufferedFile **f; | 808 | BufferedFile **f; |
| 800 | for(f = include_stack; f < include_stack_ptr; f++) | 809 | if (file) { |
| 801 | fprintf(stderr, "In file included from %s:%d:\n", | 810 | for(f = include_stack; f < include_stack_ptr; f++) |
| 802 | (*f)->filename, (*f)->line_num); | 811 | fprintf(stderr, "In file included from %s:%d:\n", |
| 803 | fprintf(stderr, "%s:%d: ", file->filename, file->line_num); | 812 | (*f)->filename, (*f)->line_num); |
| | 813 | fprintf(stderr, "%s:%d: ", file->filename, file->line_num); |
| | 814 | } else { |
| | 815 | fprintf(stderr, "tcc: "); |
| | 816 | } |
| 804 | } | 817 | } |
| 805 | | 818 | |
| 806 | void error(const char *fmt, ...) | 819 | void error(const char *fmt, ...) |
| @@ -2516,6 +2529,7 @@ void gaddrof(void) · 1709 unmodified lines |
| 2516 | vtop->r = (vtop->r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; | 2529 | vtop->r = (vtop->r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; |
| 2517 | } | 2530 | } |
| 2518 | | 2531 | |
| | 2532 | #ifdef CONFIG_TCC_BCHECK |
| 2519 | /* generate lvalue bound code */ | 2533 | /* generate lvalue bound code */ |
| 2520 | void gbound(void) | 2534 | void gbound(void) |
| 2521 | { | 2535 | { |
| @@ -2529,6 +2543,7 @@ void gbound(void) · 7 unmodified lines |
| 2529 | vtop->r |= VT_LVAL; | 2543 | vtop->r |= VT_LVAL; |
| 2530 | } | 2544 | } |
| 2531 | } | 2545 | } |
| | 2546 | #endif |
| 2532 | | 2547 | |
| 2533 | /* store vtop a register belonging to class 'rc'. lvalues are | 2548 | /* store vtop a register belonging to class 'rc'. lvalues are |
| 2534 | converted to values. Cannot be used if cannot be converted to | 2549 | converted to values. Cannot be used if cannot be converted to |
| @@ -2568,8 +2583,10 @@ int gv(int rc) · 33 unmodified lines |
| 2568 | data_offset += size << 2; | 2583 | data_offset += size << 2; |
| 2569 | data_section->data_ptr = (unsigned char *)data_offset; | 2584 | data_section->data_ptr = (unsigned char *)data_offset; |
| 2570 | } | 2585 | } |
| | 2586 | #ifdef CONFIG_TCC_BCHECK |
| 2571 | if (vtop->r & VT_MUSTBOUND) | 2587 | if (vtop->r & VT_MUSTBOUND) |
| 2572 | gbound(); | 2588 | gbound(); |
| | 2589 | #endif |
| 2573 | | 2590 | |
| 2574 | r = vtop->r & VT_VALMASK; | 2591 | r = vtop->r & VT_VALMASK; |
| 2575 | /* need to reload if: | 2592 | /* need to reload if: |
| @@ -3127,6 +3144,7 @@ void gen_op(int op) · 551 unmodified lines |
| 3127 | /* XXX: cast to int ? (long long case) */ | 3144 | /* XXX: cast to int ? (long long case) */ |
| 3128 | vpushi(pointed_size(vtop[-1].t)); | 3145 | vpushi(pointed_size(vtop[-1].t)); |
| 3129 | gen_op('*'); | 3146 | gen_op('*'); |
| | 3147 | #ifdef CONFIG_TCC_BCHECK |
| 3130 | /* if evaluating constant expression, no code should be | 3148 | /* if evaluating constant expression, no code should be |
| 3131 | generated, so no bound check */ | 3149 | generated, so no bound check */ |
| 3132 | if (do_bounds_check && !const_wanted) { | 3150 | if (do_bounds_check && !const_wanted) { |
| @@ -3139,7 +3157,9 @@ void gen_op(int op) · 6 unmodified lines |
| 3139 | } | 3157 | } |
| 3140 | gen_bounded_ptr_add1(); | 3158 | gen_bounded_ptr_add1(); |
| 3141 | gen_bounded_ptr_add2(0); | 3159 | gen_bounded_ptr_add2(0); |
| 3142 | } else { | 3160 | } else |
| | 3161 | #endif |
| | 3162 | { |
| 3143 | gen_opc(op); | 3163 | gen_opc(op); |
| 3144 | } | 3164 | } |
| 3145 | /* put again type if gen_opc() swaped operands */ | 3165 | /* put again type if gen_opc() swaped operands */ |
| @@ -3747,12 +3767,14 @@ void vstore(void) · 601 unmodified lines |
| 3747 | /* store result */ | 3767 | /* store result */ |
| 3748 | vstore(); | 3768 | vstore(); |
| 3749 | } else { | 3769 | } else { |
| | 3770 | #ifdef CONFIG_TCC_BCHECK |
| 3750 | /* bound check case */ | 3771 | /* bound check case */ |
| 3751 | if (vtop[-1].r & VT_MUSTBOUND) { | 3772 | if (vtop[-1].r & VT_MUSTBOUND) { |
| 3752 | vswap(); | 3773 | vswap(); |
| 3753 | gbound(); | 3774 | gbound(); |
| 3754 | vswap(); | 3775 | vswap(); |
| 3755 | } | 3776 | } |
| | 3777 | #endif |
| 3756 | rc = RC_INT; | 3778 | rc = RC_INT; |
| 3757 | if (is_float(ft)) | 3779 | if (is_float(ft)) |
| 3758 | rc = RC_FLOAT; | 3780 | rc = RC_FLOAT; |
| @@ -5854,12 +5876,14 @@ void open_dll(char *libname) · 2095 unmodified lines |
| 5854 | | 5876 | |
| 5855 | static void *resolve_sym(const char *sym) | 5877 | static void *resolve_sym(const char *sym) |
| 5856 | { | 5878 | { |
| 5857 | void *ptr; | 5879 | #ifdef CONFIG_TCC_BCHECK |
| 5858 | if (do_bounds_check) { | 5880 | if (do_bounds_check) { |
| | 5881 | void *ptr; |
| 5859 | ptr = bound_resolve_sym(sym); | 5882 | ptr = bound_resolve_sym(sym); |
| 5860 | if (ptr) | 5883 | if (ptr) |
| 5861 | return ptr; | 5884 | return ptr; |
| 5862 | } | 5885 | } |
| | 5886 | #endif |
| 5863 | return dlsym(NULL, sym); | 5887 | return dlsym(NULL, sym); |
| 5864 | } | 5888 | } |
| 5865 | | 5889 | |
| @@ -6269,10 +6293,8 @@ int launch_exe(int argc, char **argv) · 403 unmodified lines |
| 6269 | #endif | 6293 | #endif |
| 6270 | } | 6294 | } |
| 6271 | | 6295 | |
| | 6296 | #ifdef CONFIG_TCC_BCHECK |
| 6272 | if (do_bounds_check) { | 6297 | if (do_bounds_check) { |
| 6273 | #ifdef WIN32 | | |
| 6274 | error("bound checking currently not available for Windows"); | | |
| 6275 | #else | | |
| 6276 | int *p, *p_end; | 6298 | int *p, *p_end; |
| 6277 | __bound_init(); | 6299 | __bound_init(); |
| 6278 | /* add all known static regions */ | 6300 | /* add all known static regions */ |
| @@ -6282,8 +6304,8 @@ int launch_exe(int argc, char **argv) · 3 unmodified lines |
| 6282 | __bound_new_region((void *)p[0], p[1]); | 6304 | __bound_new_region((void *)p[0], p[1]); |
| 6283 | p += 2; | 6305 | p += 2; |
| 6284 | } | 6306 | } |
| 6285 | #endif | | |
| 6286 | } | 6307 | } |
| | 6308 | #endif |
| 6287 | | 6309 | |
| 6288 | t = (int (*)())s->c; | 6310 | t = (int (*)())s->c; |
| 6289 | return (*t)(argc, argv); | 6311 | return (*t)(argc, argv); |
| @@ -6292,7 +6314,7 @@ int launch_exe(int argc, char **argv) · 2 unmodified lines |
| 6292 | | 6314 | |
| 6293 | void help(void) | 6315 | void help(void) |
| 6294 | { | 6316 | { |
| 6295 | printf("tcc version 0.9.4 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | 6317 | printf("tcc version 0.9.5 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" |
| 6296 | "usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]\n" | 6318 | "usage: tcc [-Idir] [-Dsym[=val]] [-Usym] [-llib] [-g] [-b]\n" |
| 6297 | " [-i infile] infile [infile_args...]\n" | 6319 | " [-i infile] infile [infile_args...]\n" |
| 6298 | "\n" | 6320 | "\n" |
| @@ -6301,7 +6323,9 @@ void help(void) · 2 unmodified lines |
| 6301 | "-Usym : undefine 'sym'\n" | 6323 | "-Usym : undefine 'sym'\n" |
| 6302 | "-llib : link with dynamic library 'lib'\n" | 6324 | "-llib : link with dynamic library 'lib'\n" |
| 6303 | "-g : generate runtime debug info\n" | 6325 | "-g : generate runtime debug info\n" |
| | 6326 | #ifdef CONFIG_TCC_BCHECK |
| 6304 | "-b : compile with built-in memory and bounds checker (implies -g)\n" | 6327 | "-b : compile with built-in memory and bounds checker (implies -g)\n" |
| | 6328 | #endif |
| 6305 | "-i infile : compile infile\n" | 6329 | "-i infile : compile infile\n" |
| 6306 | ); | 6330 | ); |
| 6307 | } | 6331 | } |
| @@ -6368,6 +6392,7 @@ int main(int argc, char **argv) · 60 unmodified lines |
| 6368 | tcc_compile_file(argv[optind++]); | 6392 | tcc_compile_file(argv[optind++]); |
| 6369 | } else if (!strcmp(r + 1, "bench")) { | 6393 | } else if (!strcmp(r + 1, "bench")) { |
| 6370 | do_bench = 1; | 6394 | do_bench = 1; |
| | 6395 | #ifdef CONFIG_TCC_BCHECK |
| 6371 | } else if (r[1] == 'b') { | 6396 | } else if (r[1] == 'b') { |
| 6372 | if (!do_bounds_check) { | 6397 | if (!do_bounds_check) { |
| 6373 | do_bounds_check = 1; | 6398 | do_bounds_check = 1; |
| @@ -6381,8 +6406,11 @@ int main(int argc, char **argv) · 7 unmodified lines |
| 6381 | /* debug is implied */ | 6406 | /* debug is implied */ |
| 6382 | goto debug_opt; | 6407 | goto debug_opt; |
| 6383 | } | 6408 | } |
| | 6409 | #endif |
| 6384 | } else if (r[1] == 'g') { | 6410 | } else if (r[1] == 'g') { |
| | 6411 | #ifdef CONFIG_TCC_BCHECK |
| 6385 | debug_opt: | 6412 | debug_opt: |
| | 6413 | #endif |
| 6386 | if (!do_debug) { | 6414 | if (!do_debug) { |
| 6387 | do_debug = 1; | 6415 | do_debug = 1; |
| 6388 | | 6416 | |
| @@ -6409,8 +6437,7 @@ int main(int argc, char **argv) · 20 unmodified lines |
| 6409 | goto show_help; | 6437 | goto show_help; |
| 6410 | outfile = argv[optind++]; | 6438 | outfile = argv[optind++]; |
| 6411 | } else { | 6439 | } else { |
| 6412 | fprintf(stderr, "invalid option -- '%s'\n", r); | 6440 | error("invalid option -- '%s'", r); |
| 6413 | exit(1); | | |
| 6414 | } | 6441 | } |
| 6415 | } | 6442 | } |
| 6416 | | 6443 | |