diff mbox series

arch: um: enable CONFIG_CONSTRUCTORS

Message ID 20190823130557.15870-1-johannes@sipsolutions.net
State Superseded
Headers show
Series arch: um: enable CONFIG_CONSTRUCTORS | expand

Commit Message

Johannes Berg Aug. 23, 2019, 1:05 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

We do need to call the constructors for *modules*, even
if libc calls the ones for the kernel binary itself, so
allow enabling CONFIG_CONSTRUCTORS but skip the kernel.

Tested that it indeed doesn't work in modules, and does
work after the fixes in both, with a few functions with
__attribute__((constructor)) in both dynamic and static
builds.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 init/Kconfig        | 1 -
 init/main.c         | 2 +-
 kernel/gcov/Kconfig | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

Comments

Johannes Berg Aug. 23, 2019, 1:30 p.m. UTC | #1
On Fri, 2019-08-23 at 15:05 +0200, Johannes Berg wrote:
> 
> -#ifdef CONFIG_CONSTRUCTORS
> +#if defined(CONFIG_CONSTRUCTORS) && !defined(CONFIG_UML)
>  	ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;

Hmm, no, this doesn't work. I was trying to do this for KASAN, but libc
calls this stuff WAY too early, and so KASAN just crashes.

It *does* get called (only once), but much too early.

Let's see if I can come up with a fix.

johannes
diff mbox series

Patch

diff --git a/init/Kconfig b/init/Kconfig
index bd7d650d4a99..81293d78a6ad 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -48,7 +48,6 @@  config CC_DISABLE_WARN_MAYBE_UNINITIALIZED
 
 config CONSTRUCTORS
 	bool
-	depends on !UML
 
 config IRQ_WORK
 	bool
diff --git a/init/main.c b/init/main.c
index 96f8d5af52d6..1e670be141c8 100644
--- a/init/main.c
+++ b/init/main.c
@@ -788,7 +788,7 @@  asmlinkage __visible void __init start_kernel(void)
 /* Call all constructor functions linked into the kernel. */
 static void __init do_ctors(void)
 {
-#ifdef CONFIG_CONSTRUCTORS
+#if defined(CONFIG_CONSTRUCTORS) && !defined(CONFIG_UML)
 	ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
 
 	for (; fn < (ctor_fn_t *) __ctors_end; fn++)
diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig
index 3941a9c48f83..060e8e726755 100644
--- a/kernel/gcov/Kconfig
+++ b/kernel/gcov/Kconfig
@@ -4,7 +4,7 @@  menu "GCOV-based kernel profiling"
 config GCOV_KERNEL
 	bool "Enable gcov-based kernel profiling"
 	depends on DEBUG_FS
-	select CONSTRUCTORS if !UML
+	select CONSTRUCTORS
 	default n
 	---help---
 	This option enables gcov-based code profiling (e.g. for code coverage