* [PATCH AUTOSEL 6.14 03/10] rust: module: place cleanup_module() in .exit.text section
[not found] <20250608125447.933686-1-sashal@kernel.org>
@ 2025-06-08 12:54 ` Sasha Levin
2025-06-08 16:58 ` Miguel Ojeda
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 04/10] rust: arm: fix unknown (to Clang) argument '-mno-fdpic' Sasha Levin
1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2025-06-08 12:54 UTC (permalink / raw)
To: patches, stable
Cc: FUJITA Tomonori, Jarkko Sakkinen, Miguel Ojeda, Sasha Levin,
alex.gaynor, lossin, aliceryhl, gary, dakr, boqun.feng, walmeida,
igor.korotin.linux, anisse, rust-for-linux
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
[ Upstream commit 249c3a0e53acefc2b06d3b3e1fc28fb2081f878d ]
Place cleanup_module() in .exit.text section. Currently,
cleanup_module() is likely placed in the .text section. It's
inconsistent with the layout of C modules, where cleanup_module() is
placed in .exit.text.
[ Boqun asked for an example of how the section changed to be
put in the log. Tomonori provided the following examples:
C module:
$ objdump -t ~/build/x86/drivers/block/loop.o|grep clean
0000000000000000 l O .exit.data 0000000000000008 __UNIQUE_ID___addressable_cleanup_module412
0000000000000000 g F .exit.text 000000000000009c cleanup_module
Rust module without this patch:
$ objdump -t ~/build/x86/samples/rust/rust_minimal.o|grep clean
00000000000002b0 g F .text 00000000000000c6 cleanup_module
0000000000000000 g O .exit.data 0000000000000008 _R...___UNIQUE_ID___addressable_cleanup_module
Rust module with this patch:
$ objdump -t ~/build/x86/samples/rust/rust_minimal.o|grep clean
0000000000000000 g F .exit.text 00000000000000c6 cleanup_module
0000000000000000 g O .exit.data 0000000000000008 _R...___UNIQUE_ID___addressable_cleanup_module
- Miguel ]
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20250308044506.14458-1-fujita.tomonori@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
**YES**
This commit should be backported to stable kernel trees.
**Analysis:**
This commit adds a single line `#[link_section = ".exit.text"]` to the
`cleanup_module()` function in `rust/macros/module.rs`, making Rust
modules consistent with C modules by placing cleanup code in the
`.exit.text` section instead of the default `.text` section.
**Key factors supporting backporting:**
1. **Consistency fix**: The commit aligns Rust module behavior with
established C module conventions. From examining
`/home/sasha/linux/include/linux/init.h:56`, C modules use `#define
__exit __section(".exit.text")` to place cleanup functions in
`.exit.text`.
2. **Minimal and contained**: This is an extremely small change - adding
just one line to specify the link section. The risk of regression is
essentially zero.
3. **Follows established pattern**: This commit mirrors Similar Commit
#1 which was marked "YES" for backporting. That commit placed
`init_module()` in `.init.text` for consistency with C modules, and
this commit does the same for `cleanup_module()` with `.exit.text`.
4. **Correctness improvement**: The current code places
`cleanup_module()` in `.text` while the corresponding C code uses
`.exit.text`. This inconsistency could affect tools that rely on
standard kernel module section layouts.
5. **Low risk, clear benefit**: The change has no functional impact on
module operation but improves kernel consistency and correctness. The
commit message includes clear examples showing the section placement
before and after the fix.
The commit follows the stable tree criteria of being an important
correctness fix with minimal risk, similar to the approved Similar
Commit #1 that addressed the same inconsistency for `init_module()`.
rust/macros/module.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 3f462e71ff0ef..59739f625ce69 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -266,6 +266,7 @@ mod __module_init {{
#[cfg(MODULE)]
#[doc(hidden)]
#[no_mangle]
+ #[link_section = \".exit.text\"]
pub extern \"C\" fn cleanup_module() {{
// SAFETY:
// - This function is inaccessible to the outside due to the double
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH AUTOSEL 6.14 04/10] rust: arm: fix unknown (to Clang) argument '-mno-fdpic'
[not found] <20250608125447.933686-1-sashal@kernel.org>
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 03/10] rust: module: place cleanup_module() in .exit.text section Sasha Levin
@ 2025-06-08 12:54 ` Sasha Levin
2025-06-08 16:25 ` Miguel Ojeda
1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2025-06-08 12:54 UTC (permalink / raw)
To: patches, stable
Cc: Rudraksha Gupta, Linux Kernel Functional Testing, Miguel Ojeda,
Naresh Kamboju, Sasha Levin, alex.gaynor, nathan, rust-for-linux,
llvm
From: Rudraksha Gupta <guptarud@gmail.com>
[ Upstream commit 977c4308ee4270cf46e2c66b37de8e04670daa0c ]
Currently rust on arm fails to compile due to '-mno-fdpic'. This flag
disables a GCC feature that we don't want for kernel builds, so let's
skip it as it doesn't apply to Clang.
UPD include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
RUSTC L rust/core.o
BINDGEN rust/bindings/bindings_generated.rs
BINDGEN rust/bindings/bindings_helpers_generated.rs
CC rust/helpers/helpers.o
Unable to generate bindings: clang diagnosed error: error: unknown argument: '-mno-fdpic'
make[2]: *** [rust/Makefile:369: rust/bindings/bindings_helpers_generated.rs] Error 1
make[2]: *** Deleting file 'rust/bindings/bindings_helpers_generated.rs'
make[2]: *** Waiting for unfinished jobs....
Unable to generate bindings: clang diagnosed error: error: unknown argument: '-mno-fdpic'
make[2]: *** [rust/Makefile:349: rust/bindings/bindings_generated.rs] Error 1
make[2]: *** Deleting file 'rust/bindings/bindings_generated.rs'
make[1]: *** [/home/pmos/build/src/linux-next-next-20250521/Makefile:1285: prepare] Error 2
make: *** [Makefile:248: __sub-make] Error 2
[ Naresh provided the draft diff [1].
Ben explained [2]:
FDPIC is only relevant with no-MMU targets, and then only for userspace.
When configured for the arm-*-uclinuxfdpiceabi target, GCC enables FDPIC
by default to facilitate compiling userspace programs. FDPIC is never
used for the kernel, and we pass -mno-fdpic when building the kernel to
override the default and make sure FDPIC is disabled.
and [3]:
-mno-fdpic disables a GCC feature that we don't want for kernel builds.
clang does not support this feature, so it always behaves as though
-mno-fdpic is passed. Therefore, it should be fine to mix the two, at
least as far as FDPIC is concerned.
[1] https://lore.kernel.org/rust-for-linux/CA+G9fYt4otQK4pHv8pJBW9e28yHSGCDncKquwuJiJ_1ou0pq0w@mail.gmail.com/
[2] https://lore.kernel.org/rust-for-linux/aAKrq2InExQk7f_k@dell-precision-5540/
[3] https://lore.kernel.org/rust-for-linux/aAo_F_UP1Gd4jHlZ@dell-precision-5540/
- Miguel ]
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/all/CA+G9fYvOanQBYXKSg7C6EU30k8sTRC0JRPJXYu7wWK51w38QUQ@mail.gmail.com/
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Rudraksha Gupta <guptarud@gmail.com>
Link: https://lore.kernel.org/r/20250522-rust-mno-fdpic-arm-fix-v2-1-a6f691d9c198@gmail.com
[ Reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
**YES**
This commit should be backported to stable kernel trees. Here's my
extensive analysis:
## Build Fix Characteristics
This commit fixes a concrete build failure affecting ARM Rust builds.
The error message is clear and specific:
```
Unable to generate bindings: clang diagnosed error: error: unknown
argument: '-mno-fdpic'
```
This represents a fundamental build breakage where Rust compilation
completely fails on ARM when using Clang-based bindgen.
## Code Change Analysis
The fix is surgically precise - it adds `-mno-fdpic` to the
`bindgen_skip_c_flags` list in `/rust/Makefile:276`. This follows the
exact same pattern as numerous other similar fixes that have been
successfully backported.
Looking at the context from `/home/sasha/linux/rust/Makefile:255-277`,
the `bindgen_skip_c_flags` mechanism exists specifically to handle GCC
flags that Clang doesn't understand. The comment explains this is "a
hack" but necessary because "bindgen relies on libclang to parse C" and
there are compatibility issues.
## Historical Precedent from Similar Commits
The provided examples show a clear pattern:
1. **Similar Commit #1 (Backported: YES)** - LoongArch GCC build fix
adding flags to bindgen skip list
2. **Similar Commit #3 (Backported: NO)** - fstrict-flex-arrays bindgen
fix
3. **Similar Commit #4 (Backported: YES)** - fzero-init-padding-bits
bindgen fix
Examining the kernel history, I found additional precedent:
- `a9c621a21712` - Recent commit adding `-fzero-init-padding-bits` to
bindgen skip flags
- `869b5016e94e` - Added `-fmin-function-alignment` to bindgen skip
flags
These demonstrate that bindgen compatibility fixes are regularly
backported.
## Technical Context
From `/home/sasha/linux/arch/arm/Makefile:26`, I can see that `-mno-
fdpic` is used in ARM kernel builds:
```makefile
# Disable FDPIC ABI
KBUILD_CFLAGS += $(call cc-option,-mno-fdpic)
```
The commit message explains that FDPIC is a GCC feature for no-MMU
userspace targets that should never be used for kernel builds. Clang
doesn't support this feature and always behaves as if `-mno-fdpic` is
passed. Therefore, filtering it out for bindgen is safe and correct.
## Stable Tree Criteria Compliance
- ✅ **Fixes important bug**: ARM Rust builds completely fail without
this
- ✅ **Small and contained**: Single line addition to skip flag list
- ✅ **No architectural changes**: Follows established pattern for
bindgen flag filtering
- ✅ **Minimal regression risk**: Only affects bindgen flag filtering, no
functional changes
- ✅ **Clear side effects**: None beyond fixing the build failure
## Impact Assessment
This fix enables ARM Rust support to work properly with the standard
toolchain configuration. Without it, any ARM platform wanting to use
Rust features would hit a hard build failure. The change is completely
backward compatible and only affects the flag filtering logic for
bindgen.
The fix matches the exact same pattern as Similar Commits #1 and #4
which were both backported, and addresses the same category of issue -
GCC/Clang toolchain compatibility for Rust builds.
rust/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/Makefile b/rust/Makefile
index a84c6d4b6ca21..5d33c812835fc 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -245,7 +245,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
-fzero-call-used-regs=% -fno-stack-clash-protection \
-fno-inline-functions-called-once -fsanitize=bounds-strict \
-fstrict-flex-arrays=% -fmin-function-alignment=% \
- -fzero-init-padding-bits=% \
+ -fzero-init-padding-bits=% -mno-fdpic \
--param=% --param asan-%
# Derived from `scripts/Makefile.clang`.
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH AUTOSEL 6.14 04/10] rust: arm: fix unknown (to Clang) argument '-mno-fdpic'
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 04/10] rust: arm: fix unknown (to Clang) argument '-mno-fdpic' Sasha Levin
@ 2025-06-08 16:25 ` Miguel Ojeda
0 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2025-06-08 16:25 UTC (permalink / raw)
To: Sasha Levin
Cc: patches, stable, Rudraksha Gupta, Linux Kernel Functional Testing,
Miguel Ojeda, Naresh Kamboju, alex.gaynor, nathan, rust-for-linux,
llvm
On Sun, Jun 8, 2025 at 2:54 PM Sasha Levin <sashal@kernel.org> wrote:
>
> **YES**
This does not need to be backported to 6.14 since there is no support
for arm (32-bit) before 6.15.
However, it should not hurt either.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH AUTOSEL 6.14 03/10] rust: module: place cleanup_module() in .exit.text section
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 03/10] rust: module: place cleanup_module() in .exit.text section Sasha Levin
@ 2025-06-08 16:58 ` Miguel Ojeda
0 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2025-06-08 16:58 UTC (permalink / raw)
To: Sasha Levin
Cc: patches, stable, FUJITA Tomonori, Jarkko Sakkinen, Miguel Ojeda,
alex.gaynor, lossin, aliceryhl, gary, dakr, boqun.feng, walmeida,
igor.korotin.linux, anisse, rust-for-linux
On Sun, Jun 8, 2025 at 2:54 PM Sasha Levin <sashal@kernel.org> wrote:
>
> **YES**
Same as: https://lore.kernel.org/rust-for-linux/CANiq72kEoavu3UOxBxjYx3XwnOStPkUmVaeKRrLSRgghar3L5w@mail.gmail.com/
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-08 16:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250608125447.933686-1-sashal@kernel.org>
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 03/10] rust: module: place cleanup_module() in .exit.text section Sasha Levin
2025-06-08 16:58 ` Miguel Ojeda
2025-06-08 12:54 ` [PATCH AUTOSEL 6.14 04/10] rust: arm: fix unknown (to Clang) argument '-mno-fdpic' Sasha Levin
2025-06-08 16:25 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).