History

__chkstk support

bellard committed 21 years ago

Commit 98250111 parent 2c538d72 files · +33 −5Browse files

Unified · Split

2 files
  1. i386-gen.c +32 −5
  2. tcctok.h +1 −0
i386-gen.c+32−5
@@ -398,6 +398,12 @@ void gfunc_call(int nb_args) · 397 unmodified lines
398 vtop--;398 vtop--;
399}399}
400 400
401#ifdef TCC_TARGET_PE
402#define FUNC_PROLOG_SIZE 10
403#else
404#define FUNC_PROLOG_SIZE 9
405#endif
406
401/* generate function prolog of type 't' */407/* generate function prolog of type 't' */
402void gfunc_prolog(CType *func_type)408void gfunc_prolog(CType *func_type)
403{409{
@@ -417,9 +423,8 @@ void gfunc_prolog(CType *func_type) · 13 unmodified lines
417 }423 }
418 param_index = 0;424 param_index = 0;
419 425
420 o(0xe58955); /* push %ebp, mov %esp, %ebp */426 ind += FUNC_PROLOG_SIZE;
421 func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */427 func_sub_sp_offset = ind;
422
423 /* if the function returns a structure, then add an428 /* if the function returns a structure, then add an
424 implicit pointer parameter */429 implicit pointer parameter */
425 func_vt = sym->type;430 func_vt = sym->type;
@@ -470,6 +475,8 @@ void gfunc_prolog(CType *func_type) · 44 unmodified lines
470/* generate function epilog */475/* generate function epilog */
471void gfunc_epilog(void)476void gfunc_epilog(void)
472{477{
478 int v, saved_ind;
479
473#ifdef CONFIG_TCC_BCHECK480#ifdef CONFIG_TCC_BCHECK
474 if (do_bounds_check && func_bound_offset != lbounds_section->data_offset) {481 if (do_bounds_check && func_bound_offset != lbounds_section->data_offset) {
475 int saved_ind;482 int saved_ind;
@@ -480,7 +487,7 @@ void gfunc_epilog(void) · 4 unmodified lines
480 *bounds_ptr = 0;487 *bounds_ptr = 0;
481 /* generate bound local allocation */488 /* generate bound local allocation */
482 saved_ind = ind;489 saved_ind = ind;
483 ind = func_sub_sp_offset + 4;490 ind = func_sub_sp_offset;
484 sym_data = get_sym_ref(&char_pointer_type, lbounds_section, 491 sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
485 func_bound_offset, lbounds_section->data_offset);492 func_bound_offset, lbounds_section->data_offset);
486 greloc(cur_text_section, sym_data,493 greloc(cur_text_section, sym_data,
@@ -512,7 +519,27 @@ void gfunc_epilog(void) · 25 unmodified lines
512 g(func_ret_sub >> 8);519 g(func_ret_sub >> 8);
513 }520 }
514 /* align local size to word & save local variables */521 /* align local size to word & save local variables */
515 *(int *)(cur_text_section->data + func_sub_sp_offset) = (-loc + 3) & -4; 522
523 v = (-loc + 3) & -4;
524 saved_ind = ind;
525 ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
526#ifdef TCC_TARGET_PE
527 if (v >= 4096) {
528 Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0);
529 oad(0xb8, v); /* mov stacksize, %eax */
530 oad(0xe8, -4); /* call __chkstk, (does the stackframe too) */
531 greloc(cur_text_section, sym, ind-4, R_386_PC32);
532 } else
533#endif
534 {
535 o(0xe58955); /* push %ebp, mov %esp, %ebp */
536 o(0xec81); /* sub esp, stacksize */
537 gen_le32(v);
538#if FUNC_PROLOG_SIZE == 10
539 o(0x90); /* adjust to FUNC_PROLOG_SIZE */
540#endif
541 }
542 ind = saved_ind;
516}543}
517 544
518/* generate a jump to a label */545/* generate a jump to a label */
tcctok.h+1−0
@@ -155,6 +155,7 @@ · 154 unmodified lines
155 DEF(TOK___fixunssfdi, "__fixunssfdi")155 DEF(TOK___fixunssfdi, "__fixunssfdi")
156 DEF(TOK___fixunsdfdi, "__fixunsdfdi")156 DEF(TOK___fixunsdfdi, "__fixunsdfdi")
157 DEF(TOK___fixunsxfdi, "__fixunsxfdi")157 DEF(TOK___fixunsxfdi, "__fixunsxfdi")
158 DEF(TOK___chkstk, "__chkstk")
158 159
159/* bound checking symbols */160/* bound checking symbols */
160#ifdef CONFIG_TCC_BCHECK161#ifdef CONFIG_TCC_BCHECK

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t