[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] PE target: shorter function prologs
From: |
Zdenek Pavlas |
Subject: |
[Tinycc-devel] PE target: shorter function prologs |
Date: |
Wed, 16 May 2007 10:22:08 +0200 |
User-agent: |
Thunderbird 1.5.0.10 (X11/20070301) |
Hello everybody,
Because of Windows' draconic handling of page faults 'sub esp, 4096' is
a no-no. Rare functions needing page or more of stack space must call
chkstk(stacksize) first. TCC needs 10 bytes for such call while the
standard function prolog was only 9 so it pads them to 10 bytes.
This patch uses a shorter chkstk() calling convention that fits in 9
bytes so no more padding. Please check and apply if ok.
regards
--
Zdenek Pavlas
diff -ur tinycc-1eefdf914c2d/i386/i386-gen.c tinycc/i386/i386-gen.c
--- tinycc-1eefdf914c2d/i386/i386-gen.c 2007-05-12 06:33:24.000000000 +0200
+++ tinycc/i386/i386-gen.c 2007-05-14 11:52:58.000000000 +0200
@@ -407,11 +407,7 @@
vtop--;
}
-#ifdef TCC_TARGET_PE
-#define FUNC_PROLOG_SIZE 10
-#else
#define FUNC_PROLOG_SIZE 9
-#endif
/* generate function prolog of type 't' */
void gfunc_prolog(CType *func_type)
@@ -541,7 +537,6 @@
#ifdef TCC_TARGET_PE
if (v >= 4096) {
Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0);
- oad(0xb8, v); /* mov stacksize, %eax */
oad(0xe8, -4); /* call __chkstk, (does the stackframe too) */
greloc(cur_text_section, sym, ind-4, R_386_PC32);
} else
@@ -549,11 +544,8 @@
{
o(0xe58955); /* push %ebp, mov %esp, %ebp */
o(0xec81); /* sub esp, stacksize */
- gen_le32(v);
-#if FUNC_PROLOG_SIZE == 10
- o(0x90); /* adjust to FUNC_PROLOG_SIZE */
-#endif
}
+ gen_le32(v);
ind = saved_ind;
}
diff -ur tinycc-1eefdf914c2d/win32/lib/chkstk.S tinycc/win32/lib/chkstk.S
--- tinycc-1eefdf914c2d/win32/lib/chkstk.S 2007-05-12 06:33:24.000000000
+0200
+++ tinycc/win32/lib/chkstk.S 2007-05-14 11:52:29.000000000 +0200
@@ -6,6 +6,8 @@
__chkstk:
xchg (%esp), %ebp // store ebp, get ret.addr
+ mov (%ebp), %eax // get stacksize
+ lea 4(%ebp), %ebp // skip it
push %ebp // push ret.addr
lea 4(%esp), %ebp // setup frame ptr
push %ecx // save ecx
- [Tinycc-devel] PE target: shorter function prologs,
Zdenek Pavlas <=