| @@ -398,6 +398,12 @@ void gfunc_call(int nb_args) · 397 unmodified lines |
| 398 | 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 | 407 | /* generate function prolog of type 't' */ |
| 402 | 408 | void gfunc_prolog(CType *func_type) |
| 403 | 409 | { |
| @@ -417,9 +423,8 @@ void gfunc_prolog(CType *func_type) · 13 unmodified lines |
| 417 | 423 | } |
| 418 | 424 | param_index = 0; |
| 419 | 425 | |
| 420 | | − o(0xe58955); /* push %ebp, mov %esp, %ebp */ |
| 421 | | − func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */ |
| 422 | | − |
| 426 | + ind += FUNC_PROLOG_SIZE; |
| 427 | + func_sub_sp_offset = ind; |
| 423 | 428 | /* if the function returns a structure, then add an |
| 424 | 429 | implicit pointer parameter */ |
| 425 | 430 | func_vt = sym->type; |
| @@ -470,6 +475,8 @@ void gfunc_prolog(CType *func_type) · 44 unmodified lines |
| 470 | 475 | /* generate function epilog */ |
| 471 | 476 | void gfunc_epilog(void) |
| 472 | 477 | { |
| 478 | + int v, saved_ind; |
| 479 | + |
| 473 | 480 | #ifdef CONFIG_TCC_BCHECK |
| 474 | 481 | if (do_bounds_check && func_bound_offset != lbounds_section->data_offset) { |
| 475 | 482 | int saved_ind; |
| @@ -480,7 +487,7 @@ void gfunc_epilog(void) · 4 unmodified lines |
| 480 | 487 | *bounds_ptr = 0; |
| 481 | 488 | /* generate bound local allocation */ |
| 482 | 489 | saved_ind = ind; |
| 483 | | − ind = func_sub_sp_offset + 4; |
| 490 | + ind = func_sub_sp_offset; |
| 484 | 491 | sym_data = get_sym_ref(&char_pointer_type, lbounds_section, |
| 485 | 492 | func_bound_offset, lbounds_section->data_offset); |
| 486 | 493 | greloc(cur_text_section, sym_data, |
| @@ -512,7 +519,27 @@ void gfunc_epilog(void) · 25 unmodified lines |
| 512 | 519 | g(func_ret_sub >> 8); |
| 513 | 520 | } |
| 514 | 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 | 545 | /* generate a jump to a label */ |