Linux Modules
 help / color / mirror / Atom feed
* [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
@ 2026-05-30 15:46 Egg12138
  2026-05-30 15:56 ` sashiko-bot
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Egg12138 @ 2026-05-30 15:46 UTC (permalink / raw)
  To: Russell King
  Cc: Josh Poimboeuf, Petr Mladek, linux-arm-kernel, linux-modules,
	linux-kernel, Xiao Junzhe

From: Xiao Junzhe <egg12138@foxmail.com>

Commit 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN,
and related macros") made scripts/module.lds.S merge module input
.text.* sections into the output .text section.

On ARM, the paired unwind input sections keep their original names.  A
module can therefore contain .ARM.exidx.text.unlikely with sh_link
pointing at .text, while .text.unlikely no longer exists.

This is a valid ELF relationship, but ARM module_finalize() does not use
sh_link when registering module unwind tables.  It derives the target
text section from the exidx section name instead:

  .ARM.exidx.text.unlikely -> .text.unlikely

The lookup fails and the unwind table is not registered for the actual
.text range.  This can make module stack unwinding fail with:

  unwind: Index not found

Keep the ARM module unwind output names in sync with the text sections
that scripts/module.lds.S now produces.  Coalesce the .ARM.exidx/.ARM.extab
section associated with .text.*, into the
stable output names expected by the existing ARM module unwind code.

Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
Signed-off-by: Xiao Junzhe <egg12138@foxmail.com>
---
Changes in v3:
  - Apply the ARM unwind section coalescing under CONFIG_ARM_UNWIND.
  - Remove quotes around linker-script wildcard patterns so GNU ld expands
    them correctly.
  - Use conventional linker-script wildcard syntax, i.e. *(...) without a
    space after the wildcard.

 arch/arm/include/asm/module.lds.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/include/asm/module.lds.h b/arch/arm/include/asm/module.lds.h
index 0e7cb4e314b4..1d56c0375c18 100644
--- a/arch/arm/include/asm/module.lds.h
+++ b/arch/arm/include/asm/module.lds.h
@@ -1,4 +1,16 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+
+#ifdef CONFIG_ARM_UNWIND
+SECTIONS {
+	.ARM.extab		0 : {
+		*(.ARM.extab .ARM.extab.text .ARM.extab.text.[0-9a-zA-Z_]*)
+	}
+	.ARM.exidx		0 : {
+		*(.ARM.exidx .ARM.exidx.text .ARM.exidx.text.[0-9a-zA-Z_]*)
+	}
+}
+#endif
+
 #ifdef CONFIG_ARM_MODULE_PLTS
 SECTIONS {
 	.plt : { BYTE(0) }
-- 
2.43.0


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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-05-30 15:46 [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections Egg12138
@ 2026-05-30 15:56 ` sashiko-bot
  2026-07-27  7:47 ` Ju Nan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-05-30 15:56 UTC (permalink / raw)
  To: Egg12138; +Cc: linux-modules

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing NULL check on the return value of `unwind_table_add()` in `module_finalize()` causes a kernel panic on memory allocation failure.
--

commit 0098f68f3e89e8e569da9c5eaaa9486505d4ea3d
Author: Xiao Junzhe <egg12138@foxmail.com>

ARM: module.lds: fix unwind metadata for merged .text sections

Commit 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN,
and related macros") made scripts/module.lds.S merge module input
.text.* sections into the output .text section. On ARM, the paired
unwind input sections keep their original names. This commit ensures
the ARM module unwind output names stay in sync with the text sections.

> diff --git a/arch/arm/include/asm/module.lds.h b/arch/arm/include/asm/module.lds.h
> index 0e7cb4e314b48..1d56c0375c18b 100644
> --- a/arch/arm/include/asm/module.lds.h
> +++ b/arch/arm/include/asm/module.lds.h
> @@ -1,4 +1,16 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifdef CONFIG_ARM_UNWIND
> +SECTIONS {
> +	.ARM.extab		0 : {
> +		*(.ARM.extab .ARM.extab.text .ARM.extab.text.[0-9a-zA-Z_]*)
> +	}
> +	.ARM.exidx		0 : {
> +		*(.ARM.exidx .ARM.exidx.text .ARM.exidx.text.[0-9a-zA-Z_]*)
> +	}
> +}
> +#endif

[Severity: High]
This is a pre-existing issue and was not introduced by the patch under review,
but while reviewing how ARM module unwind tables are registered, I noticed a
potential concern in arch/arm/kernel/module.c:

arch/arm/kernel/module.c:module_finalize() {
    ...
		if (txt_sec) {
			struct unwind_table *table =
				unwind_table_add(s->sh_addr,
						s->sh_size,
						txt_sec->sh_addr,
						txt_sec->sh_size);

			list_add(&table->mod_list, unwind_list);
    ...
}

Does this code safely handle a null return from unwind_table_add?

If unwind_table_add fails to allocate memory, it returns a null pointer.
Passing that directly to list_add causes an offset-based dereference of null.

Could this trigger a kernel panic during module loading if the system is out
of memory?

> +
>  #ifdef CONFIG_ARM_MODULE_PLTS
>  SECTIONS {
>  	.plt : { BYTE(0) }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_08845B64E5F38EB7FA1779982A071AB4A607@qq.com?part=1

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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-05-30 15:46 [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections Egg12138
  2026-05-30 15:56 ` sashiko-bot
@ 2026-07-27  7:47 ` Ju Nan
  2026-08-06  9:34 ` Petr Pavlu
  2026-08-06 13:02 ` Xie Yuanbin
  3 siblings, 0 replies; 7+ messages in thread
From: Ju Nan @ 2026-07-27  7:47 UTC (permalink / raw)
  To: egg12138
  Cc: jpoimboe, linux-arm-kernel, linux-kernel, linux-modules, linux,
	pmladek, Ju Nan

I ran into exactly the same on a STM32MP157A-DK1 board (dual Cortex-A7,
ARMv7 AEABI, CONFIG_ARM_UNWIND=y).  An out-of-tree module whose functions
GCC had placed in .text.unlikely (merged into .text by module.lds.S) left
its .ARM.exidx.text.unlikely section unregistered, so an Oops inside the
module produced an empty backtrace:

  Call trace:
  unwind: Index not found bf102018

With this patch applied, the module's exidx is coalesced into a single
.ARM.exidx output section, module_finalize() registers it against .text,
and the full module backtrace is restored:

  Call trace:
   do_the_crash [oops_null] from level_one+0x8/0xc [oops_null]
   level_one [oops_null] from level_two+0x8/0xc [oops_null]
   level_two [oops_null] from trigger_write+0x18/0x20 [oops_null]
   trigger_write [oops_null] from full_proxy_write+0x54/0x78
   full_proxy_write from vfs_write+0xd0/0x49c
   vfs_write from ksys_write+0x6c/0xf4
   ksys_write from ret_fast_syscall+0x0/0x54

Tested on Linux 7.1.4

Tested-by: Ju Nan <junan76@163.com>


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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-05-30 15:46 [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections Egg12138
  2026-05-30 15:56 ` sashiko-bot
  2026-07-27  7:47 ` Ju Nan
@ 2026-08-06  9:34 ` Petr Pavlu
  2026-08-06 13:02 ` Xie Yuanbin
  3 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-08-06  9:34 UTC (permalink / raw)
  To: Egg12138
  Cc: Russell King, Josh Poimboeuf, Petr Mladek, linux-arm-kernel,
	linux-modules, linux-kernel

On 5/30/26 5:46 PM, Egg12138 wrote:
> From: Xiao Junzhe <egg12138@foxmail.com>
> 
> Commit 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN,
> and related macros") made scripts/module.lds.S merge module input
> .text.* sections into the output .text section.
> 
> On ARM, the paired unwind input sections keep their original names.  A
> module can therefore contain .ARM.exidx.text.unlikely with sh_link
> pointing at .text, while .text.unlikely no longer exists.
> 
> This is a valid ELF relationship, but ARM module_finalize() does not use
> sh_link when registering module unwind tables.  It derives the target
> text section from the exidx section name instead:
> 
>   .ARM.exidx.text.unlikely -> .text.unlikely
> 
> The lookup fails and the unwind table is not registered for the actual
> .text range.  This can make module stack unwinding fail with:
> 
>   unwind: Index not found
> 
> Keep the ARM module unwind output names in sync with the text sections
> that scripts/module.lds.S now produces.  Coalesce the .ARM.exidx/.ARM.extab
> section associated with .text.*, into the
> stable output names expected by the existing ARM module unwind code.
> 
> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> Signed-off-by: Xiao Junzhe <egg12138@foxmail.com>

Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>

As mentioned previously, please don't forget to put the fix in Russell's
patch tracker [1].

[1] https://www.arm.linux.org.uk/developer/patches/

-- 
Thanks,
Petr

> ---
> Changes in v3:
>   - Apply the ARM unwind section coalescing under CONFIG_ARM_UNWIND.
>   - Remove quotes around linker-script wildcard patterns so GNU ld expands
>     them correctly.
>   - Use conventional linker-script wildcard syntax, i.e. *(...) without a
>     space after the wildcard.
> 
>  arch/arm/include/asm/module.lds.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm/include/asm/module.lds.h b/arch/arm/include/asm/module.lds.h
> index 0e7cb4e314b4..1d56c0375c18 100644
> --- a/arch/arm/include/asm/module.lds.h
> +++ b/arch/arm/include/asm/module.lds.h
> @@ -1,4 +1,16 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifdef CONFIG_ARM_UNWIND
> +SECTIONS {
> +	.ARM.extab		0 : {
> +		*(.ARM.extab .ARM.extab.text .ARM.extab.text.[0-9a-zA-Z_]*)
> +	}
> +	.ARM.exidx		0 : {
> +		*(.ARM.exidx .ARM.exidx.text .ARM.exidx.text.[0-9a-zA-Z_]*)
> +	}
> +}
> +#endif
> +
>  #ifdef CONFIG_ARM_MODULE_PLTS
>  SECTIONS {
>  	.plt : { BYTE(0) }

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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-05-30 15:46 [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections Egg12138
                   ` (2 preceding siblings ...)
  2026-08-06  9:34 ` Petr Pavlu
@ 2026-08-06 13:02 ` Xie Yuanbin
  2026-08-06 14:29   ` Xiao Junzhe
  3 siblings, 1 reply; 7+ messages in thread
From: Xie Yuanbin @ 2026-08-06 13:02 UTC (permalink / raw)
  To: egg12138, pmladek, linusw, jpoimboe, rostedt, petr.pavlu
  Cc: linux-arm-kernel, linux-kernel, linux-modules, linux, Xie Yuanbin

On Sat, 30 May 2026 23:46:01 +0800, Xiao Junzhe wrote:
> +	.ARM.extab		0 : {
> +		*(.ARM.extab .ARM.extab.text .ARM.extab.text.[0-9a-zA-Z_]*)
> +	}
> +	.ARM.exidx		0 : {
> +		*(.ARM.exidx .ARM.exidx.text .ARM.exidx.text.[0-9a-zA-Z_]*)
> +	}
> +}

I think ".ARM.extab.text" and ".ARM.exidx.text" is redundant, and I
suggest that
"*(.ARM.extab .ARM.extab.text.[0-9a-zA-Z_]*)"
"*(.ARM.exidx .ARM.exidx.text.[0-9a-zA-Z_]*)"
instead.

Mapping between the text sections and exidx sections in .o files
generated by the compilers:
".text" -> ".ARM.exidx"
".text.xx" -> ".ARM.exidx.text.xx"

".ARM.extab.text" and ".ARM.exidx.text" sections will never be
generated by the compilers.

Also Cc to Linus Walleij and UNWIND:
Cc: Linus Walleij <linusw@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>

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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-08-06 13:02 ` Xie Yuanbin
@ 2026-08-06 14:29   ` Xiao Junzhe
  2026-08-07  2:13     ` Xie Yuanbin
  0 siblings, 1 reply; 7+ messages in thread
From: Xiao Junzhe @ 2026-08-06 14:29 UTC (permalink / raw)
  To: xieyuanbin1
  Cc: linux, jpoimboe, pmladek, linux-arm-kernel, linux-modules,
	linux-kernel

Thanks for the suggestion.

I had already noticed before that the current GNU binutils does not generate
.ARM.exidx.text or .ARM.extab.text for the plain .text section.

GNU as special-cases an exact .text section name in
start_unwind_section():

    text_name = segment_name(text_seg);

    if (streq(text_name, ".text"))
        text_name = "";

And after your reply, I checked LLVM founding it does the same in ARMELFStreamer::SwitchToEHSection():

    StringRef FnSecName(FnSection.getName());
    SmallString<128> EHSecName(Prefix);

    if (FnSecName != ".text")
        EHSecName += FnSecName;

So, with both current implementations, the mapping is:

    .text       -> .ARM.exidx / .ARM.extab
    .text.foo   -> .ARM.exidx.text.foo / .ARM.extab.text.foo

It's correct that .ARM.exidx.text and .ARM.extab.text are therefore not
generated by the current GNU or LLVM implementations currently.

My reason for including the exact matches is slightly different.
AAELF32 defines these section namespaces as .ARM.exidx* and
.ARM.extab*; it does not require all ABI-conforming object producers to
use the same naming convention as GNU as and LLVM.

For example, another producer or future version of GNU/LLVM impl for `as` 
could validly use:

    .text -> .ARM.exidx.text

And our topic is about text section merging in ARM32 unwind section layout.

Without the exact match, .ARM.exidx.text would be left as an orphan
output section, while .ARM.exidx.text.* inputs would be folded into
.ARM.exidx. Since the corresponding .text and .text.* inputs are all
folded into the final .text output section, this would make the unwind
section semantics a little bit asymmetric.

That is my point why prefer to keep `.ARM.exidx.text` matching.
Hear what the other reviewers' comments.


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

* Re: [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections
  2026-08-06 14:29   ` Xiao Junzhe
@ 2026-08-07  2:13     ` Xie Yuanbin
  0 siblings, 0 replies; 7+ messages in thread
From: Xie Yuanbin @ 2026-08-07  2:13 UTC (permalink / raw)
  To: egg12138
  Cc: xieyuanbin1, jpoimboe, linusw, linux-arm-kernel, linux-kernel,
	linux-modules, linux, petr.pavlu, pmladek, rostedt

On Thu, 6 Aug 2026 22:29:03 +0800, Xiao Junzhe wrote:
> My reason for including the exact matches is slightly different.
> AAELF32 defines these section namespaces as .ARM.exidx* and
> .ARM.extab*; it does not require all ABI-conforming object producers to
> use the same naming convention as GNU as and LLVM.
>
> For example, another producer or future version of GNU/LLVM impl for `as`
> could validly use:
>
>     .text -> .ARM.exidx.text

I have thought about it again. For other sections, the mapping is
as follows:
	.xxx -> .ARM.exidx.xxx

So, if there is an ".ARM.exidx.text", it must be from ".text", and adding
".ARM.exidx.text" will not cause any other harm. We only need
to ensure that the merging of the ".text*" sections is consistent
with the merging of the ".ARM.exidx*" sections, and the current patch
already satisfies this requirement.

I have no other questions about this, so:
Reviewed-by: Xie Yuanbin <xieyuanbin1@huawei.com>
Tested-by: Xie Yuanbin <xieyuanbin1@huawei.com>

Also, don't forget to submit your patch to Russell's
patch tracker:
Link: https://www.armlinux.org.uk/developer/patches/

Thanks.

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

end of thread, other threads:[~2026-08-07  2:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30 15:46 [PATCH v3] ARM: module.lds: fix unwind metadata for merged .text sections Egg12138
2026-05-30 15:56 ` sashiko-bot
2026-07-27  7:47 ` Ju Nan
2026-08-06  9:34 ` Petr Pavlu
2026-08-06 13:02 ` Xie Yuanbin
2026-08-06 14:29   ` Xiao Junzhe
2026-08-07  2:13     ` Xie Yuanbin

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