From 51d2a078cef514252bd12a1dd16dcfa456b1f296 Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Sat, 6 Jun 2015 23:11:27 -0400
Subject: fix indirection of __init_array_start and __fini_array_start.

signed-off by Z. Gilboa; see copying.midipix (9cd0746c) for additional information.
---
 arch/nt32/src/crt_glue.c |  8 ++++----
 arch/nt64/src/crt_glue.c | 21 +++++++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

(limited to 'arch')

diff --git a/arch/nt32/src/crt_glue.c b/arch/nt32/src/crt_glue.c
index 07d38de..b92db1a 100644
--- a/arch/nt32/src/crt_glue.c
+++ b/arch/nt32/src/crt_glue.c
@@ -8,8 +8,8 @@
 extern struct __ldso_vtbl *	__ldso_vtbl;
 extern struct __psx_vtbl *	__psx_vtbl;
 
-extern void * __init_array_start;
-extern void * __fini_array_start;
+extern void * __init_array_start[];
+extern void * __fini_array_start[];
 
 typedef int __app_main();
 typedef int __pthread_surrogate_routine(struct pthread *);
@@ -73,8 +73,8 @@ void __libc_entry_routine(
 	__teb_libc_idx	= ctx.teb_libc_idx;
 
 	/* surrogate init/fini arrays */
-	__init_array_start = ctx.do_global_ctors_fn;
-	__fini_array_start = ctx.do_global_dtors_fn;
+	*__init_array_start = ctx.do_global_ctors_fn;
+	*__fini_array_start = ctx.do_global_dtors_fn;
 
 	/* enter libc */
 	__libc_start_main(__main,argc,argv);
diff --git a/arch/nt64/src/crt_glue.c b/arch/nt64/src/crt_glue.c
index 2913b19..7c7d8b2 100644
--- a/arch/nt64/src/crt_glue.c
+++ b/arch/nt64/src/crt_glue.c
@@ -8,13 +8,9 @@
 extern struct __ldso_vtbl *	__ldso_vtbl;
 extern struct __psx_vtbl *	__psx_vtbl;
 
-extern void * __init_array_start;
-extern void * __fini_array_start;
-
 typedef int __app_main();
 typedef int __pthread_surrogate_routine(struct pthread *);
 
-extern int _init(void);
 static int __pthread_surrogate_init(struct pthread * self);
 
 extern int __libc_start_main(
@@ -22,6 +18,19 @@ extern int __libc_start_main(
 	int	argc,
 	char **	argv);
 
+static void (*__global_ctors_fn)();
+static void (*__global_dtors_fn)();
+
+void _init()
+{
+	__global_ctors_fn();
+}
+
+void _fini()
+{
+	__global_dtors_fn();
+}
+
 struct __tls {
 	void *		pad[16/sizeof(void *)];
 	struct pthread	pt;
@@ -73,8 +82,8 @@ void __libc_entry_routine(
 	__teb_libc_idx	= ctx.teb_libc_idx;
 
 	/* surrogate init/fini arrays */
-	__init_array_start = ctx.do_global_ctors_fn;
-	__fini_array_start = ctx.do_global_dtors_fn;
+	__global_ctors_fn = ctx.do_global_ctors_fn;
+	__global_dtors_fn = ctx.do_global_dtors_fn;
 
 	/* enter libc */
 	__libc_start_main(__main,argc,argv);
-- 
cgit v1.2.3