[Skiboot] [PATCH 05/11] Run gcc constructors

Stewart Smith stewart at linux.vnet.ibm.com
Thu May 7 17:11:44 AEST 2015


As part of setting up GCOV data structures correctly, GCC/GCOV generates
a bunch of constructor routines that the C runtime is expected to run
really early on.

skiboot was not running GCC generated constructors. Luckily, it's really
easy to do so.

This patch will run GCC constructors very early on during boot (if there
are any)

Signed-off-by: Stewart Smith <stewart at linux.vnet.ibm.com>
---
 core/init.c   |   13 +++++++++++++
 skiboot.lds.S |    8 ++++++++
 2 files changed, 21 insertions(+)

diff --git a/core/init.c b/core/init.c
index e35c885..ab1a156 100644
--- a/core/init.c
+++ b/core/init.c
@@ -520,6 +520,17 @@ static void setup_branch_null_catcher(void)
 /* Called from head.S, thus no prototype. */
 void __noreturn main_cpu_entry(const void *fdt, u32 master_cpu);
 
+typedef void (*ctorcall_t)(void);
+
+static void do_ctors(void)
+{
+	extern ctorcall_t __ctors_start[], __ctors_end[];
+	ctorcall_t *call;
+
+	for (call = __ctors_start; call < __ctors_end; call++)
+		(*call)();
+}
+
 void __noreturn main_cpu_entry(const void *fdt, u32 master_cpu)
 {
 	/*
@@ -548,6 +559,8 @@ void __noreturn main_cpu_entry(const void *fdt, u32 master_cpu)
 	 */
 	setup_branch_null_catcher();
 
+	do_ctors();
+
 	printf("SkiBoot %s starting...\n", version);
 	printf("initial console log level: memory %d, driver %d\n",
 	       (debug_descriptor.console_log_levels >> 4),
diff --git a/skiboot.lds.S b/skiboot.lds.S
index bdc2c2c..8cb88bd 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -76,6 +76,14 @@ SECTIONS
 		*(.toc1)
 		*(.branch_lt)
 	}
+
+	. = ALIGN(0x10);
+	.init : {
+		__ctors_start = .;
+		*(.ctors)
+		*(.init_array)
+		__ctors_end = .;
+	}
  
 	. = ALIGN(0x10);
 	.opd : {
-- 
1.7.10.4



More information about the Skiboot mailing list