mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN
@ 2025-10-31  1:01 Josh Poimboeuf
  2025-10-31  4:57 ` Venkat Rao Bagalkote
  2025-10-31 11:04 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
  0 siblings, 2 replies; 3+ messages in thread
From: Josh Poimboeuf @ 2025-10-31  1:01 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Peter Zijlstra, Venkat Rao Bagalkote, Hari Bathini

An ftrace warning was reported in ftrace_init_ool_stub():

   WARNING: arch/powerpc/kernel/trace/ftrace.c:234 at ftrace_init_ool_stub+0x188/0x3f4, CPU#0: swapper/0

The problem is that the linker script is placing .text.startup in .text
rather than in .init.text, due to an inadvertent match of the TEXT_MAIN
'.text.[0-9a-zA-Z_]*' pattern.

This bug existed for some configurations before, but is only now coming
to light due to the TEXT_MAIN macro unification in commit 1ba9f8979426
("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros").

The .text.startup section consists of constructors which are used by
KASAN, KCSAN, and GCOV.  The constructors are only called during boot,
so .text.startup is supposed to match the INIT_TEXT pattern so it can be
placed in .init.text and freed after init.  But since INIT_TEXT comes
*after* TEXT_MAIN in the linker script, TEXT_MAIN needs to manually
exclude .text.startup.

Update TEXT_MAIN to exclude .text.startup (and its .text.startup.*
variant from -ffunction-sections), along with .text.exit and
.text.exit.* which should match EXIT_TEXT.

Specifically, use a series of more specific glob patterns to match
generic .text.* sections (for -ffunction-sections) while explicitly
excluding .text.startup[.*] and .text.exit[.*].

Also update INIT_TEXT and EXIT_TEXT to explicitly match their
-ffunction-sections variants (.text.startup.* and .text.exit.*).

Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
Closes: https://lore.kernel.org/72469502-ca37-4287-90b9-a751cecc498c@linux.ibm.com
Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Debugged-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
For tip/objtool/core.

 include/asm-generic/vmlinux.lds.h | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 5facbc994634..9de1d900fa15 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -88,13 +88,29 @@
 
 /*
  * Support -ffunction-sections by matching .text and .text.*,
- * but exclude '.text..*'.
+ * but exclude '.text..*', .text.startup[.*], and .text.exit[.*].
  *
- * Special .text.* sections that are typically grouped separately, such as
+ * .text.startup and .text.startup.* are matched later by INIT_TEXT.
+ * .text.exit and .text.exit.* are matched later by EXIT_TEXT.
+ *
+ * Other .text.* sections that are typically grouped separately, such as
  * .text.unlikely or .text.hot, must be matched explicitly before using
  * TEXT_MAIN.
  */
-#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
+#define TEXT_MAIN							\
+	.text								\
+	.text.[_0-9A-Za-df-rt-z]*					\
+	.text.s[_0-9A-Za-su-z]*						\
+	.text.st[_0-9A-Zb-z]*						\
+	.text.sta[_0-9A-Za-qs-z]*					\
+	.text.star[_0-9A-Za-su-z]*					\
+	.text.start[_0-9A-Za-tv-z]*					\
+	.text.startu[_0-9A-Za-oq-z]*					\
+	.text.startup[_0-9A-Za-z]*					\
+	.text.e[_0-9A-Za-wy-z]*						\
+	.text.ex[_0-9A-Za-hj-z]*					\
+	.text.exi[_0-9A-Za-su-z]*					\
+	.text.exit[_0-9A-Za-z]*
 
 /*
  * Support -fdata-sections by matching .data, .data.*, and others,
@@ -713,16 +729,16 @@
 
 #define INIT_TEXT							\
 	*(.init.text .init.text.*)					\
-	*(.text.startup)
+	*(.text.startup .text.startup.*)
 
 #define EXIT_DATA							\
 	*(.exit.data .exit.data.*)					\
 	*(.fini_array .fini_array.*)					\
-	*(.dtors .dtors.*)						\
+	*(.dtors .dtors.*)
 
 #define EXIT_TEXT							\
 	*(.exit.text)							\
-	*(.text.exit)							\
+	*(.text.exit .text.exit.*)
 
 #define EXIT_CALL							\
 	*(.exitcall.exit)
-- 
2.51.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN
  2025-10-31  1:01 [PATCH] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN Josh Poimboeuf
@ 2025-10-31  4:57 ` Venkat Rao Bagalkote
  2025-10-31 11:04 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
  1 sibling, 0 replies; 3+ messages in thread
From: Venkat Rao Bagalkote @ 2025-10-31  4:57 UTC (permalink / raw)
  To: Josh Poimboeuf, x86; +Cc: linux-kernel, Peter Zijlstra, Hari Bathini


On 31/10/25 6:31 am, Josh Poimboeuf wrote:
> An ftrace warning was reported in ftrace_init_ool_stub():
>
>     WARNING: arch/powerpc/kernel/trace/ftrace.c:234 at ftrace_init_ool_stub+0x188/0x3f4, CPU#0: swapper/0
>
> The problem is that the linker script is placing .text.startup in .text
> rather than in .init.text, due to an inadvertent match of the TEXT_MAIN
> '.text.[0-9a-zA-Z_]*' pattern.
>
> This bug existed for some configurations before, but is only now coming
> to light due to the TEXT_MAIN macro unification in commit 1ba9f8979426
> ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros").
>
> The .text.startup section consists of constructors which are used by
> KASAN, KCSAN, and GCOV.  The constructors are only called during boot,
> so .text.startup is supposed to match the INIT_TEXT pattern so it can be
> placed in .init.text and freed after init.  But since INIT_TEXT comes
> *after* TEXT_MAIN in the linker script, TEXT_MAIN needs to manually
> exclude .text.startup.
>
> Update TEXT_MAIN to exclude .text.startup (and its .text.startup.*
> variant from -ffunction-sections), along with .text.exit and
> .text.exit.* which should match EXIT_TEXT.
>
> Specifically, use a series of more specific glob patterns to match
> generic .text.* sections (for -ffunction-sections) while explicitly
> excluding .text.startup[.*] and .text.exit[.*].
>
> Also update INIT_TEXT and EXIT_TEXT to explicitly match their
> -ffunction-sections variants (.text.startup.* and .text.exit.*).
>
> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> Closes: https://lore.kernel.org/72469502-ca37-4287-90b9-a751cecc498c@linux.ibm.com
> Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
> Debugged-by: Hari Bathini <hbathini@linux.ibm.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---


Thanks for the patch. Tested this patch by applying on top of 
next-20251030, and it fixes the reported issue.


Please add below tag.


Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>



Regards,

Venkat.


> For tip/objtool/core.
>
>   include/asm-generic/vmlinux.lds.h | 28 ++++++++++++++++++++++------
>   1 file changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 5facbc994634..9de1d900fa15 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -88,13 +88,29 @@
>   
>   /*
>    * Support -ffunction-sections by matching .text and .text.*,
> - * but exclude '.text..*'.
> + * but exclude '.text..*', .text.startup[.*], and .text.exit[.*].
>    *
> - * Special .text.* sections that are typically grouped separately, such as
> + * .text.startup and .text.startup.* are matched later by INIT_TEXT.
> + * .text.exit and .text.exit.* are matched later by EXIT_TEXT.
> + *
> + * Other .text.* sections that are typically grouped separately, such as
>    * .text.unlikely or .text.hot, must be matched explicitly before using
>    * TEXT_MAIN.
>    */
> -#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
> +#define TEXT_MAIN							\
> +	.text								\
> +	.text.[_0-9A-Za-df-rt-z]*					\
> +	.text.s[_0-9A-Za-su-z]*						\
> +	.text.st[_0-9A-Zb-z]*						\
> +	.text.sta[_0-9A-Za-qs-z]*					\
> +	.text.star[_0-9A-Za-su-z]*					\
> +	.text.start[_0-9A-Za-tv-z]*					\
> +	.text.startu[_0-9A-Za-oq-z]*					\
> +	.text.startup[_0-9A-Za-z]*					\
> +	.text.e[_0-9A-Za-wy-z]*						\
> +	.text.ex[_0-9A-Za-hj-z]*					\
> +	.text.exi[_0-9A-Za-su-z]*					\
> +	.text.exit[_0-9A-Za-z]*
>   
>   /*
>    * Support -fdata-sections by matching .data, .data.*, and others,
> @@ -713,16 +729,16 @@
>   
>   #define INIT_TEXT							\
>   	*(.init.text .init.text.*)					\
> -	*(.text.startup)
> +	*(.text.startup .text.startup.*)
>   
>   #define EXIT_DATA							\
>   	*(.exit.data .exit.data.*)					\
>   	*(.fini_array .fini_array.*)					\
> -	*(.dtors .dtors.*)						\
> +	*(.dtors .dtors.*)
>   
>   #define EXIT_TEXT							\
>   	*(.exit.text)							\
> -	*(.text.exit)							\
> +	*(.text.exit .text.exit.*)
>   
>   #define EXIT_CALL							\
>   	*(.exitcall.exit)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: objtool/core] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN
  2025-10-31  1:01 [PATCH] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN Josh Poimboeuf
  2025-10-31  4:57 ` Venkat Rao Bagalkote
@ 2025-10-31 11:04 ` tip-bot2 for Josh Poimboeuf
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Josh Poimboeuf @ 2025-10-31 11:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Venkat Rao Bagalkote, Josh Poimboeuf, Peter Zijlstra (Intel),
	x86, linux-kernel

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     6568f14cb5ae68cd6c612604ca0c89301cf3a0d0
Gitweb:        https://git.kernel.org/tip/6568f14cb5ae68cd6c612604ca0c89301cf3a0d0
Author:        Josh Poimboeuf <jpoimboe@kernel.org>
AuthorDate:    Thu, 30 Oct 2025 18:01:54 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 31 Oct 2025 11:19:21 +01:00

vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN

An ftrace warning was reported in ftrace_init_ool_stub():

   WARNING: arch/powerpc/kernel/trace/ftrace.c:234 at ftrace_init_ool_stub+0x188/0x3f4, CPU#0: swapper/0

The problem is that the linker script is placing .text.startup in .text
rather than in .init.text, due to an inadvertent match of the TEXT_MAIN
'.text.[0-9a-zA-Z_]*' pattern.

This bug existed for some configurations before, but is only now coming
to light due to the TEXT_MAIN macro unification in commit 1ba9f8979426
("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros").

The .text.startup section consists of constructors which are used by
KASAN, KCSAN, and GCOV.  The constructors are only called during boot,
so .text.startup is supposed to match the INIT_TEXT pattern so it can be
placed in .init.text and freed after init.  But since INIT_TEXT comes
*after* TEXT_MAIN in the linker script, TEXT_MAIN needs to manually
exclude .text.startup.

Update TEXT_MAIN to exclude .text.startup (and its .text.startup.*
variant from -ffunction-sections), along with .text.exit and
.text.exit.* which should match EXIT_TEXT.

Specifically, use a series of more specific glob patterns to match
generic .text.* sections (for -ffunction-sections) while explicitly
excluding .text.startup[.*] and .text.exit[.*].

Also update INIT_TEXT and EXIT_TEXT to explicitly match their
-ffunction-sections variants (.text.startup.* and .text.exit.*).

Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
Closes: https://lore.kernel.org/72469502-ca37-4287-90b9-a751cecc498c@linux.ibm.com
Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Debugged-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Link: https://patch.msgid.link/07f74b4e5c43872572b7def30f2eac45f28675d9.1761872421.git.jpoimboe@kernel.org
---
 include/asm-generic/vmlinux.lds.h | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 5facbc9..9de1d90 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -88,13 +88,29 @@
 
 /*
  * Support -ffunction-sections by matching .text and .text.*,
- * but exclude '.text..*'.
+ * but exclude '.text..*', .text.startup[.*], and .text.exit[.*].
  *
- * Special .text.* sections that are typically grouped separately, such as
+ * .text.startup and .text.startup.* are matched later by INIT_TEXT.
+ * .text.exit and .text.exit.* are matched later by EXIT_TEXT.
+ *
+ * Other .text.* sections that are typically grouped separately, such as
  * .text.unlikely or .text.hot, must be matched explicitly before using
  * TEXT_MAIN.
  */
-#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
+#define TEXT_MAIN							\
+	.text								\
+	.text.[_0-9A-Za-df-rt-z]*					\
+	.text.s[_0-9A-Za-su-z]*						\
+	.text.st[_0-9A-Zb-z]*						\
+	.text.sta[_0-9A-Za-qs-z]*					\
+	.text.star[_0-9A-Za-su-z]*					\
+	.text.start[_0-9A-Za-tv-z]*					\
+	.text.startu[_0-9A-Za-oq-z]*					\
+	.text.startup[_0-9A-Za-z]*					\
+	.text.e[_0-9A-Za-wy-z]*						\
+	.text.ex[_0-9A-Za-hj-z]*					\
+	.text.exi[_0-9A-Za-su-z]*					\
+	.text.exit[_0-9A-Za-z]*
 
 /*
  * Support -fdata-sections by matching .data, .data.*, and others,
@@ -713,16 +729,16 @@
 
 #define INIT_TEXT							\
 	*(.init.text .init.text.*)					\
-	*(.text.startup)
+	*(.text.startup .text.startup.*)
 
 #define EXIT_DATA							\
 	*(.exit.data .exit.data.*)					\
 	*(.fini_array .fini_array.*)					\
-	*(.dtors .dtors.*)						\
+	*(.dtors .dtors.*)
 
 #define EXIT_TEXT							\
 	*(.exit.text)							\
-	*(.text.exit)							\
+	*(.text.exit .text.exit.*)
 
 #define EXIT_CALL							\
 	*(.exitcall.exit)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-31 11:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-31  1:01 [PATCH] vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN Josh Poimboeuf
2025-10-31  4:57 ` Venkat Rao Bagalkote
2025-10-31 11:04 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®