summaryrefslogtreecommitdiff
path: root/lib/csu/common_elf
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2004-01-08 14:59:16 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2004-01-08 14:59:16 +0000
commit58b037aa2a117fe4c474549ee14e4c6bfbba585d (patch)
treef5d8f4fd6ca0aa5131b9bc178009e1cae0a1bae3 /lib/csu/common_elf
parent6e07118b4073b7f92810dfdf7b6a0ea317d3ae5f (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/csu/common_elf')
-rw-r--r--lib/csu/common_elf/crtbegin.c37
-rw-r--r--lib/csu/common_elf/crtbeginS.c18
-rw-r--r--lib/csu/common_elf/crtend.c8
-rw-r--r--lib/csu/common_elf/crtendS.c6
4 files changed, 48 insertions, 21 deletions
diff --git a/lib/csu/common_elf/crtbegin.c b/lib/csu/common_elf/crtbegin.c
index cb7da3b2a14..6399d6c8075 100644
--- a/lib/csu/common_elf/crtbegin.c
+++ b/lib/csu/common_elf/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/common_elf/crtbeginS.c b/lib/csu/common_elf/crtbeginS.c
index da66081dae3..08ec27bb21c 100644
--- a/lib/csu/common_elf/crtbeginS.c
+++ b/lib/csu/common_elf/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/common_elf/crtend.c b/lib/csu/common_elf/crtend.c
index e81d17481f2..484ca3cc5d3 100644
--- a/lib/csu/common_elf/crtend.c
+++ b/lib/csu/common_elf/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/common_elf/crtendS.c b/lib/csu/common_elf/crtendS.c
index 264189126e8..dd957d071fc 100644
--- a/lib/csu/common_elf/crtendS.c
+++ b/lib/csu/common_elf/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");