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
398398 vtop--;
399399 }
400400
401+#ifdef TCC_TARGET_PE
402+#define FUNC_PROLOG_SIZE 10
403+#else
404+#define FUNC_PROLOG_SIZE 9
405+#endif
406+
401407 /* generate function prolog of type 't' */
402408 void gfunc_prolog(CType *func_type)
403409 {
@@ -417,9 +423,8 @@ void gfunc_prolog(CType *func_type) · 13 unmodified lines
417423 }
418424 param_index = 0;
419425
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;
423428 /* if the function returns a structure, then add an
424429 implicit pointer parameter */
425430 func_vt = sym->type;
@@ -470,6 +475,8 @@ void gfunc_prolog(CType *func_type) · 44 unmodified lines
470475 /* generate function epilog */
471476 void gfunc_epilog(void)
472477 {
478+ int v, saved_ind;
479+
473480 #ifdef CONFIG_TCC_BCHECK
474481 if (do_bounds_check && func_bound_offset != lbounds_section->data_offset) {
475482 int saved_ind;
@@ -480,7 +487,7 @@ void gfunc_epilog(void) · 4 unmodified lines
480487 *bounds_ptr = 0;
481488 /* generate bound local allocation */
482489 saved_ind = ind;
483− ind = func_sub_sp_offset + 4;
490+ ind = func_sub_sp_offset;
484491 sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
485492 func_bound_offset, lbounds_section->data_offset);
486493 greloc(cur_text_section, sym_data,
@@ -512,7 +519,27 @@ void gfunc_epilog(void) · 25 unmodified lines
512519 g(func_ret_sub >> 8);
513520 }
514521 /* 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;
516543 }
517544
518545 /* generate a jump to a label */
tcctok.h+1−0
@@ -155,6 +155,7 @@ · 154 unmodified lines
155155 DEF(TOK___fixunssfdi, "__fixunssfdi")
156156 DEF(TOK___fixunsdfdi, "__fixunsdfdi")
157157 DEF(TOK___fixunsxfdi, "__fixunsxfdi")
158+ DEF(TOK___chkstk, "__chkstk")
158159
159160 /* bound checking symbols */
160161 #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