diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2004-01-08 14:59:16 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2004-01-08 14:59:16 +0000 |
commit | ee965a2aca1805ec888386d19f46b76ec0a1479b (patch) | |
tree | 56068ca11fc5db16973e51abb322a07523d7403b /lib | |
parent | 5d03c0ab9c064018d530e22db6b8f261a4e649ba (diff) |
__init/__fini handling on ELF has not been correct. It is supposed to
be a section which code stubs (branches) can be added to initialize/destructor
This adds MD stubs to allow this to operate as expected. should fix wine
and behave according to ELF specs. ok miod@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csu/crtbegin.c | 37 | ||||
-rw-r--r-- | lib/csu/crtbeginS.c | 18 | ||||
-rw-r--r-- | lib/csu/crtend.c | 8 | ||||
-rw-r--r-- | lib/csu/crtendS.c | 6 |
4 files changed, 48 insertions, 21 deletions
diff --git a/lib/csu/crtbegin.c b/lib/csu/crtbegin.c index cb7da3b2a14..6399d6c8075 100644 --- a/lib/csu/crtbegin.c +++ b/lib/csu/crtbegin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crtbegin.c,v 1.6 2002/02/16 21:27:20 millert Exp $ */ +/* $OpenBSD: crtbegin.c,v 1.7 2004/01/08 14:59:15 drahn Exp $ */ /* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */ /* @@ -41,11 +41,12 @@ */ #include <stdlib.h> +#include "md_init.h" #include "os-note-elf.h" -static void (*__CTOR_LIST__[1])(void) +static const void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */ -static void (*__DTOR_LIST__[1])(void) +static const void (*__DTOR_LIST__[1])(void) __attribute__((section(".dtors"))) = { (void *)-1 }; /* XXX */ static void __dtors(void); @@ -55,7 +56,7 @@ static void __dtors() { unsigned long i = (unsigned long) __DTOR_LIST__[0]; - void (**p)(void); + void const (**p)(void); if (i == -1) { for (i = 1; __DTOR_LIST__[i] != NULL; i++) @@ -70,17 +71,27 @@ __dtors() static void __ctors() { - void (**p)(void) = __CTOR_LIST__ + 1; + void const (**p)(void) = __CTOR_LIST__ + 1; while (*p) (**p++)(); } -void __init(void) __attribute__((section(".init"))); -void __fini(void) __attribute__((section(".fini"))); +void __init(void); +void __fini(void); +static void __do_init(void); +static void __do_fini(void); + +MD_SECTION_PROLOGUE(".init", __init); + +MD_SECTION_PROLOGUE(".fini", __fini); + +MD_SECT_CALL_FUNC(".init", __do_init); +MD_SECT_CALL_FUNC(".fini", __do_fini); + void -__init() +__do_init() { static int initialized = 0; @@ -90,18 +101,18 @@ __init() */ if (!initialized) { initialized = 1; - __ctors(); - } + (__ctors)(); - atexit(__fini); + atexit(__fini); + } } void -__fini() +__do_fini() { /* * Call global destructors. */ - __dtors(); + (__dtors)(); } diff --git a/lib/csu/crtbeginS.c b/lib/csu/crtbeginS.c index da66081dae3..08ec27bb21c 100644 --- a/lib/csu/crtbeginS.c +++ b/lib/csu/crtbeginS.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crtbeginS.c,v 1.4 2003/12/28 04:11:52 drahn Exp $ */ +/* $OpenBSD: crtbeginS.c,v 1.5 2004/01/08 14:59:15 drahn Exp $ */ /* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */ /* @@ -41,6 +41,7 @@ */ #include <stdlib.h> +#include "md_init.h" static void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */ @@ -76,9 +77,20 @@ __ctors(void) (**p++)(); } } +void _init(void); +void _fini(void); +static void _do_init(void); +static void _do_fini(void); + +MD_SECTION_PROLOGUE(".init", _init); + +MD_SECTION_PROLOGUE(".fini", _fini); + +MD_SECT_CALL_FUNC(".init", _do_init); +MD_SECT_CALL_FUNC(".fini", _do_fini); void -_init(void) +_do_init(void) { static int initialized = 0; @@ -93,7 +105,7 @@ _init(void) } void -_fini(void) +_do_fini(void) { /* * since the _init() function sets up the destructors to be called diff --git a/lib/csu/crtend.c b/lib/csu/crtend.c index e81d17481f2..484ca3cc5d3 100644 --- a/lib/csu/crtend.c +++ b/lib/csu/crtend.c @@ -1,13 +1,13 @@ -/* $OpenBSD: crtend.c,v 1.2 2002/02/16 21:27:20 millert Exp $ */ +/* $OpenBSD: crtend.c,v 1.3 2004/01/08 14:59:15 drahn Exp $ */ /* $NetBSD: crtend.c,v 1.1 1996/09/12 16:59:04 cgd Exp $ */ -#ifndef ECOFF_COMPAT - #include <sys/cdefs.h> +#include "md_init.h" static void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */ static void (*__DTOR_LIST__[1])(void) __attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */ -#endif /* !ECOFF_COMPAT */ +MD_SECTION_EPILOGUE(".init"); +MD_SECTION_EPILOGUE(".fini"); diff --git a/lib/csu/crtendS.c b/lib/csu/crtendS.c index 264189126e8..dd957d071fc 100644 --- a/lib/csu/crtendS.c +++ b/lib/csu/crtendS.c @@ -1,9 +1,13 @@ -/* $OpenBSD: crtendS.c,v 1.2 2002/02/16 21:27:20 millert Exp $ */ +/* $OpenBSD: crtendS.c,v 1.3 2004/01/08 14:59:15 drahn Exp $ */ /* $NetBSD: crtend.c,v 1.1 1997/04/16 19:38:24 thorpej Exp $ */ #include <sys/cdefs.h> +#include "md_init.h" static void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */ static void (*__DTOR_LIST__[1])(void) __attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */ + +MD_SECTION_EPILOGUE(".init"); +MD_SECTION_EPILOGUE(".fini"); |