[PATCH] vmlinux.lds: Fix TEXT_MAIN to include .text.start and friends

Josh Poimboeuf posted 1 patch 3 months ago
There is a newer version of this series
include/asm-generic/vmlinux.lds.h | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
[PATCH] vmlinux.lds: Fix TEXT_MAIN to include .text.start and friends
Posted by Josh Poimboeuf 3 months ago
Since commit 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and
.text.exit from TEXT_MAIN"), the TEXT_MAIN macro uses a series of
patterns to prevent the .text.startup[.*] and .text.exit[.*] sections
from getting linked into vmlinux runtime .text.

That commit is a tad too aggressive: it also inadvertently filters out
valid runtime text sections like .text.start and
.text.start.constprop.0, which can be generated for a function named
start() when -ffunction-sections is enabled.

As a result, those sections become orphans when building with
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION for arm:

  arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/usb/host/sl811-hcd.o' being placed in section `.text.start.constprop.0'
  arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/dvb-frontends/drxk_hard.o' being placed in section `.text.start.constprop.0'
  arm-linux-gnueabi-ld: warning: orphan section `.text.start' from `drivers/media/dvb-frontends/stv0910.o' being placed in section `.text.start'
  arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/pci/ddbridge/ddbridge-sx8.o' being placed in section `.text.start.constprop.0'

Fix that by explicitly adding the partial "substring" sections (.text.s,
.text.st, .text.sta, etc) and their cloned derivatives.

While this unfortunately means that TEXT_MAIN continues to grow, these
changes are ultimately necessary for proper support of
-ffunction-sections.

Fixes: 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202511040812.DFGedJiy-lkp@intel.com/
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
For tip/objtool/core.

 include/asm-generic/vmlinux.lds.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 9de1d900fa15..e93460cd1066 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -100,16 +100,16 @@
 #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.s[_0-9A-Za-su-z]*		.text.s		.text.s.*	\
+	.text.st[_0-9A-Zb-z]*		.text.st	.text.st.*	\
+	.text.sta[_0-9A-Za-qs-z]*	.text.sta	.text.sta.*	\
+	.text.star[_0-9A-Za-su-z]*	.text.star	.text.star.*	\
+	.text.start[_0-9A-Za-tv-z]*	.text.start	.text.start.*	\
+	.text.startu[_0-9A-Za-oq-z]*	.text.startu	.text.startu.*	\
 	.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.e[_0-9A-Za-wy-z]*		.text.e		.text.e.*	\
+	.text.ex[_0-9A-Za-hj-z]*	.text.ex	.text.ex.*	\
+	.text.exi[_0-9A-Za-su-z]*	.text.exi	.text.exi.*	\
 	.text.exit[_0-9A-Za-z]*
 
 /*
-- 
2.51.0
Re: [PATCH] vmlinux.lds: Fix TEXT_MAIN to include .text.start and friends
Posted by Josh Poimboeuf 3 months ago
On Tue, Nov 04, 2025 at 10:11:42PM -0800, Josh Poimboeuf wrote:
> Since commit 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and
> .text.exit from TEXT_MAIN"), the TEXT_MAIN macro uses a series of
> patterns to prevent the .text.startup[.*] and .text.exit[.*] sections
> from getting linked into vmlinux runtime .text.
> 
> That commit is a tad too aggressive: it also inadvertently filters out
> valid runtime text sections like .text.start and
> .text.start.constprop.0, which can be generated for a function named
> start() when -ffunction-sections is enabled.
> 
> As a result, those sections become orphans when building with
> CONFIG_LD_DEAD_CODE_DATA_ELIMINATION for arm:
> 
>   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/usb/host/sl811-hcd.o' being placed in section `.text.start.constprop.0'
>   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/dvb-frontends/drxk_hard.o' being placed in section `.text.start.constprop.0'
>   arm-linux-gnueabi-ld: warning: orphan section `.text.start' from `drivers/media/dvb-frontends/stv0910.o' being placed in section `.text.start'
>   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/pci/ddbridge/ddbridge-sx8.o' being placed in section `.text.start.constprop.0'
> 
> Fix that by explicitly adding the partial "substring" sections (.text.s,
> .text.st, .text.sta, etc) and their cloned derivatives.
> 
> While this unfortunately means that TEXT_MAIN continues to grow, these
> changes are ultimately necessary for proper support of
> -ffunction-sections.
> 
> Fixes: 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202511040812.DFGedJiy-lkp@intel.com/
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
> For tip/objtool/core.

Nack.

There are still some additional headaches that need fixing.

For example, .text.startup is ambiguous: it could be constructor code
(for .init.text) or it could be a function named startup() which was
compiled with -ffunction-sections.

And we also have to deal with .text.startup.constprop.0 and
.text.startup.isra.0.

So the unification isn't quite working out, I'll come back with a new
set of patches to fix all this up again.

-- 
Josh
Re: [PATCH] vmlinux.lds: Fix TEXT_MAIN to include .text.start and friends
Posted by Peter Zijlstra 3 months ago
On Wed, Nov 05, 2025 at 10:55:19PM -0800, Josh Poimboeuf wrote:
> On Tue, Nov 04, 2025 at 10:11:42PM -0800, Josh Poimboeuf wrote:
> > Since commit 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and
> > .text.exit from TEXT_MAIN"), the TEXT_MAIN macro uses a series of
> > patterns to prevent the .text.startup[.*] and .text.exit[.*] sections
> > from getting linked into vmlinux runtime .text.
> > 
> > That commit is a tad too aggressive: it also inadvertently filters out
> > valid runtime text sections like .text.start and
> > .text.start.constprop.0, which can be generated for a function named
> > start() when -ffunction-sections is enabled.
> > 
> > As a result, those sections become orphans when building with
> > CONFIG_LD_DEAD_CODE_DATA_ELIMINATION for arm:
> > 
> >   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/usb/host/sl811-hcd.o' being placed in section `.text.start.constprop.0'
> >   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/dvb-frontends/drxk_hard.o' being placed in section `.text.start.constprop.0'
> >   arm-linux-gnueabi-ld: warning: orphan section `.text.start' from `drivers/media/dvb-frontends/stv0910.o' being placed in section `.text.start'
> >   arm-linux-gnueabi-ld: warning: orphan section `.text.start.constprop.0' from `drivers/media/pci/ddbridge/ddbridge-sx8.o' being placed in section `.text.start.constprop.0'
> > 
> > Fix that by explicitly adding the partial "substring" sections (.text.s,
> > .text.st, .text.sta, etc) and their cloned derivatives.
> > 
> > While this unfortunately means that TEXT_MAIN continues to grow, these
> > changes are ultimately necessary for proper support of
> > -ffunction-sections.
> > 
> > Fixes: 6568f14cb5ae ("vmlinux.lds: Exclude .text.startup and .text.exit from TEXT_MAIN")
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202511040812.DFGedJiy-lkp@intel.com/
> > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> > ---
> > For tip/objtool/core.
> 
> Nack.
> 
> There are still some additional headaches that need fixing.

Hah, good thing I was otherwise pre-occupied yesterday.

I'll await a new version then!