From 7ce85ab712ccb9dae9a0a29c42b5a89aaa42d6b8 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 12 May 2004 00:58:38 +0000 Subject: [PATCH] Fixes for gcc 3.4 (-funit-at-a-time). Reduced size of stubs a little bit. committer: mfx 1084323518 +0000 --- src/stub/Makefile | 3 +-- src/stub/l_lx_elf.c | 7 +++++-- src/stub/l_lx_exec.c | 6 +++++- src/stub/l_lx_sep.c | 4 ++-- src/stub/l_lx_sh.c | 4 ++-- src/stub/linux.hh | 19 +++++++++++++++++++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/stub/Makefile b/src/stub/Makefile index 47d2b4e7..48a98857 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -100,13 +100,12 @@ CC_LINUX_I386_GCC295 += -Os -fno-omit-frame-pointer CC_LINUX_I386_GCC295 += -malign-functions=0 -malign-jumps=0 -malign-loops=0 CC_LINUX_I386_GCC295 += -Werror -# gcc 3.4.0 (fold_*.bin: 1541 / 931 / 1236) +# gcc 3.4.0 (fold_*.bin: 1482 / 931 / 1173) CC_LINUX_I386_GCC340 = gcc-3.4 -march=i386 -mtune=k6 -fno-exceptions CC_LINUX_I386_GCC340 += -Os -fno-omit-frame-pointer CC_LINUX_I386_GCC340 += -momit-leaf-frame-pointer CC_LINUX_I386_GCC340 += -fno-align-functions -fno-align-jumps -fno-align-labels -fno-align-loops ##CC_LINUX_I386_GCC340 += -fweb -CC_LINUX_I386_GCC340 += -fno-unit-at-a-time CC_LINUX_I386_GCC340 += -Werror CC_LINUX_I386 = $(CC_LINUX_I386_GCC272) diff --git a/src/stub/l_lx_elf.c b/src/stub/l_lx_elf.c index faab6fc5..a34f7c64 100644 --- a/src/stub/l_lx_elf.c +++ b/src/stub/l_lx_elf.c @@ -55,6 +55,9 @@ struct Extent { static void +#if (ACC_CC_GNUC >= 0x030300) +__attribute__((__noinline__, __used__, regparm(3), stdcall)) +#endif xread(struct Extent *x, char *buf, size_t count) { char *p=x->buf, *q=buf; @@ -94,7 +97,7 @@ do_brk(void *addr) } static char * -__attribute__((cdecl)) +__attribute_cdecl do_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { (void)len; (void)prot; (void)flags; (void)fd; (void)offset; @@ -177,7 +180,7 @@ ERR_LAB // Create (or find) an escape hatch to use when munmapping ourselves the stub. // Called by do_xmap to create it, and by assembler code to find it. -void * +static void * make_hatch(Elf32_Phdr const *const phdr) { unsigned *hatch = 0; diff --git a/src/stub/l_lx_exec.c b/src/stub/l_lx_exec.c index a4a999e4..e36b1c60 100644 --- a/src/stub/l_lx_exec.c +++ b/src/stub/l_lx_exec.c @@ -128,7 +128,7 @@ static uint32_t ascii5(char *p, uint32_t v, unsigned n) static char * -__attribute__((cdecl)) +__attribute_cdecl do_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { (void)len; (void)prot; (void)flags; (void)fd; (void)offset; @@ -158,6 +158,9 @@ do_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) // which causes too many offsets to expand from 1 byte to 4. static int +#if (ACC_CC_GNUC >= 0x030300) +__attribute__((__noinline__, __used__, __stdcall__)) +#endif go_self(char const *tmpname, char *argv[], char *envp[]) { // Old FreeBSD does not have /proc/self, so use /proc/ instead. @@ -198,6 +201,7 @@ go_self(char const *tmpname, char *argv[], char *envp[]) return fdi; } + /************************************************************************* // UPX & NRV stuff **************************************************************************/ diff --git a/src/stub/l_lx_sep.c b/src/stub/l_lx_sep.c index f38f82d8..928d3283 100644 --- a/src/stub/l_lx_sep.c +++ b/src/stub/l_lx_sep.c @@ -112,7 +112,7 @@ do_brk(void *addr) } static char * -__attribute__((cdecl)) +__attribute_cdecl do_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { (void)len; (void)prot; (void)flags; (void)fd; (void)offset; @@ -196,7 +196,7 @@ ERR_LAB // Create (or find) an escape hatch to use when munmapping ourselves the stub. // Called by do_xmap to create it, and by assembler code to find it. -void * +static void * make_hatch(Elf32_Phdr const *const phdr) { if (phdr->p_type==PT_LOAD && phdr->p_flags & PF_X) { diff --git a/src/stub/l_lx_sh.c b/src/stub/l_lx_sh.c index 8a294d97..43b308ff 100644 --- a/src/stub/l_lx_sh.c +++ b/src/stub/l_lx_sh.c @@ -94,7 +94,7 @@ do_brk(void *addr) } static char * -__attribute__((cdecl)) +__attribute_cdecl do_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { (void)len; (void)prot; (void)flags; (void)fd; (void)offset; @@ -251,7 +251,7 @@ ERR_LAB } -Elf32_Addr // entry address +static Elf32_Addr // entry address getexec(char const *const fname, Elf32_Ehdr *const ehdr, Elf32_auxv_t *const av) { int const fdi = open(fname, O_RDONLY, 0); diff --git a/src/stub/linux.hh b/src/stub/linux.hh index 5e18f1ca..a19985fe 100644 --- a/src/stub/linux.hh +++ b/src/stub/linux.hh @@ -470,6 +470,25 @@ struct p_info // 12-byte packed program header follows stub loader ((type) ((uintptr_t) (var))) +#if defined(__GNUC__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# elif defined(__GNUC_MINOR__) +# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# else +# define ACC_CC_GNUC (__GNUC__ * 0x10000L) +# endif +#endif + +#if (ACC_CC_GNUC >= 0x030300) +# define __attribute_cdecl __attribute__((__cdecl__, __used__)) +#elif (ACC_CC_GNUC >= 0x020700) +# define __attribute_cdecl __attribute__((__cdecl__)) +#else +# define __attribute_cdecl +#endif + + /* vi:ts=4:et:nowrap */