Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Josh Poimboeuf and committed by
Peter Zijlstra
6568f14c 5eccd322

+22 -6
+22 -6
include/asm-generic/vmlinux.lds.h
··· 88 88 89 89 /* 90 90 * Support -ffunction-sections by matching .text and .text.*, 91 - * but exclude '.text..*'. 91 + * but exclude '.text..*', .text.startup[.*], and .text.exit[.*]. 92 92 * 93 - * Special .text.* sections that are typically grouped separately, such as 93 + * .text.startup and .text.startup.* are matched later by INIT_TEXT. 94 + * .text.exit and .text.exit.* are matched later by EXIT_TEXT. 95 + * 96 + * Other .text.* sections that are typically grouped separately, such as 94 97 * .text.unlikely or .text.hot, must be matched explicitly before using 95 98 * TEXT_MAIN. 96 99 */ 97 - #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* 100 + #define TEXT_MAIN \ 101 + .text \ 102 + .text.[_0-9A-Za-df-rt-z]* \ 103 + .text.s[_0-9A-Za-su-z]* \ 104 + .text.st[_0-9A-Zb-z]* \ 105 + .text.sta[_0-9A-Za-qs-z]* \ 106 + .text.star[_0-9A-Za-su-z]* \ 107 + .text.start[_0-9A-Za-tv-z]* \ 108 + .text.startu[_0-9A-Za-oq-z]* \ 109 + .text.startup[_0-9A-Za-z]* \ 110 + .text.e[_0-9A-Za-wy-z]* \ 111 + .text.ex[_0-9A-Za-hj-z]* \ 112 + .text.exi[_0-9A-Za-su-z]* \ 113 + .text.exit[_0-9A-Za-z]* 98 114 99 115 /* 100 116 * Support -fdata-sections by matching .data, .data.*, and others, ··· 729 713 730 714 #define INIT_TEXT \ 731 715 *(.init.text .init.text.*) \ 732 - *(.text.startup) 716 + *(.text.startup .text.startup.*) 733 717 734 718 #define EXIT_DATA \ 735 719 *(.exit.data .exit.data.*) \ 736 720 *(.fini_array .fini_array.*) \ 737 - *(.dtors .dtors.*) \ 721 + *(.dtors .dtors.*) 738 722 739 723 #define EXIT_TEXT \ 740 724 *(.exit.text) \ 741 - *(.text.exit) \ 725 + *(.text.exit .text.exit.*) 742 726 743 727 #define EXIT_CALL \ 744 728 *(.exitcall.exit)