Question about CONFIG_DEBUG_SECTION_MISMATCH

From: Josh Poimboeuf
Date: Wed Jan 20 2021 - 13:07:23 EST


Hi Sam,

I have a question about CONFIG_DEBUG_SECTION_MISMATCH's use of
-fno-inline-functions-called-once.

- Add the option -fno-inline-functions-called-once to gcc commands.
When inlining a function annotated with __init in a non-init
function, we would lose the section information and thus
the analysis would not catch the illegal reference.
This option tells gcc to inline less (but it does result in
a larger kernel).

Is -fno-inline-functions-called-once really needed?

>From what I can tell, a .text function inlining an .init.text function
should be harmless unless the inlined function either referenced another
.init.text function, or referenced .init.data. In either case, that
would be detected by modpost.

Or am I missing another scenario where this flag would be needed?

I verified this with the following patch, it detected a mismatch even
without CONFIG_DEBUG_SECTION_MISMATCH.

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 6bd20c0de8bc..c3e41a3abc7e 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -153,6 +153,18 @@ static inline void imcr_apic_to_pic(void)
*/
static int force_enable_local_apic __initdata;

+static int __init foo(void)
+{
+ if (force_enable_local_apic)
+ return 1;
+ return 0;
+}
+
+int bar(void)
+{
+ return foo();
+}
+
/*
* APIC command line parameters
*/

--
Josh