Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/csu/common Add support for init_array/fini_array (condit...



details:   https://anonhg.NetBSD.org/src/rev/ba17db0eedb4
branches:  trunk
changeset: 780952:ba17db0eedb4
user:      matt <matt%NetBSD.org@localhost>
date:      Mon Aug 13 02:15:35 2012 +0000

description:
Add support for init_array/fini_array (conditionalized on HAVE_INITFINI_ARRAY).
[This is needed for ARM EABI.]

diffstat:

 lib/csu/common/crt0-common.c |  36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diffs (66 lines):

diff -r 972fcf608daf -r ba17db0eedb4 lib/csu/common/crt0-common.c
--- a/lib/csu/common/crt0-common.c      Mon Aug 13 01:18:31 2012 +0000
+++ b/lib/csu/common/crt0-common.c      Mon Aug 13 02:15:35 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crt0-common.c,v 1.8 2012/03/22 22:59:43 joerg Exp $ */
+/* $NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $ */
 
 /*
  * Copyright (c) 1998 Christos Zoulas
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: crt0-common.c,v 1.8 2012/03/22 22:59:43 joerg Exp $");
+__RCSID("$NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $");
 
 #include <sys/types.h>
 #include <sys/exec.h>
@@ -49,8 +49,10 @@
 
 extern int main(int, char **, char **);
 
+#ifndef HAVE_INITFINI_ARRAY
 extern void    _init(void);
 extern void    _fini(void);
+#endif
 extern void    _libc_init(void);
 
 /*
@@ -85,6 +87,36 @@
        _exit(1);                               \
 } while (0)
 
+#ifdef HAVE_INITFINI_ARRAY
+/*
+ * If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically,
+ * we have to process these instead of relying on RTLD to do it for us.
+ *
+ * Since we don't need .init or .fini sections, just code them in C
+ * to make life easier.
+ */
+static const fptr_t init_array_start[] __weak_reference(__init_array_start);
+static const fptr_t init_array_end[] __weak_reference(__init_array_end);
+static const fptr_t fini_array_start[] __weak_reference(__fini_array_start);
+static const fptr_t fini_array_end[] __weak_reference(__fini_array_end);
+
+static inline void
+_init(void)
+{
+       for (const fptr_t *f = init_array_start; f < init_array_end; f++) {
+               (*f)();
+       }
+}
+
+static void
+_fini(void)
+{
+       for (const fptr_t *f = fini_array_start; f < fini_array_end; f++) {
+               (*f)();
+       }
+}
+#endif /* HAVE_INITFINI_ARRAY */
+
 void
 ___start(void (*cleanup)(void),                        /* from shared loader */
     const Obj_Entry *obj,                      /* from shared loader */



Home | Main Index | Thread Index | Old Index