summaryrefslogtreecommitdiff
path: root/common/startup.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-09-17 09:44:07 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-09-18 10:39:36 +0200
commit51f20205ed899c9b867cc0b9dcd5cd71fa16f50e (patch)
tree690b656a549311d06e348bc7c7b53ad54ae1797d /common/startup.c
parent96028fb0995a9a5ff89ba9913eb9a62bfa248cbc (diff)
downloadbarebox-51f20205ed899c9b867cc0b9dcd5cd71fa16f50e.tar.gz
Add constructor support
Call constructors (gcc-generated initcall-like functions) during barebox start. Constructors are e.g. used for kasan initialization. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/startup.c')
-rw-r--r--common/startup.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/startup.c b/common/startup.c
index 1c58e41288..6cb0588ae6 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -366,6 +366,19 @@ static int run_init(void)
return 0;
}
+typedef void (*ctor_fn_t)(void);
+
+/* Call all constructor functions linked into the kernel. */
+static void do_ctors(void)
+{
+#ifdef CONFIG_CONSTRUCTORS
+ ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
+
+ for (; fn < (ctor_fn_t *) __ctors_end; fn++)
+ (*fn)();
+#endif
+}
+
int (*barebox_main)(void);
void __noreturn start_barebox(void)
@@ -376,6 +389,8 @@ void __noreturn start_barebox(void)
if (!IS_ENABLED(CONFIG_SHELL_NONE) && IS_ENABLED(CONFIG_COMMAND_SUPPORT))
barebox_main = run_init;
+ do_ctors();
+
for (initcall = __barebox_initcalls_start;
initcall < __barebox_initcalls_end; initcall++) {
pr_debug("initcall-> %pS\n", *initcall);