Skip to content

Commit

Permalink
init/gcov: allow CONFIG_CONSTRUCTORS on UML to fix module gcov
Browse files Browse the repository at this point in the history
On ARCH=um, loading a module doesn't result in its constructors getting
called, which breaks module gcov since the debugfs files are never
registered.  On the other hand, in-kernel constructors have already been
called by the dynamic linker, so we can't call them again.

Get out of this conundrum by allowing CONFIG_CONSTRUCTORS to be
selected, but avoiding the in-kernel constructor calls.

Also remove the "if !UML" from GCOV selecting CONSTRUCTORS now, since we
really do want CONSTRUCTORS, just not kernel binary ones.

Link: https://lkml.kernel.org/r/20210120172041.c246a2cac2fb.I1358f584b76f1898373adfed77f4462c8705b736@changeid
Signed-off-by: Johannes Berg <[email protected]>
Reviewed-by: Peter Oberparleiter <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Jessica Yu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jmberg-intel authored and torvalds committed Feb 5, 2021
1 parent 4f6ec86 commit 55b6f76
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ config CC_HAS_ASM_INLINE

config CONSTRUCTORS
bool
depends on !UML

config IRQ_WORK
bool
Expand Down
8 changes: 7 additions & 1 deletion init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,13 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
/* Call all constructor functions linked into the kernel. */
static void __init do_ctors(void)
{
#ifdef CONFIG_CONSTRUCTORS
/*
* For UML, the constructors have already been called by the
* normal setup code as it's just a normal ELF binary, so we
* cannot do it again - but we do need CONFIG_CONSTRUCTORS
* even on UML for modules.
*/
#if defined(CONFIG_CONSTRUCTORS) && !defined(CONFIG_UML)
ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;

for (; fn < (ctor_fn_t *) __ctors_end; fn++)
Expand Down
2 changes: 1 addition & 1 deletion kernel/gcov/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55b6f76

Please sign in to comment.