Skip to contentSkip to conversation

rust: Kbuild: set frame-pointer llvm module flag for CONFIG_FRAME_POINTER

PATCH Applied Alice Ryhl 2 participants 4 messages Jun 16 – Jun 19

Subsystems (2)
lore
Share & tools
lore

Alice Ryhl

author reviewer
#0 lore raw

PATCH 1/1 rust: Kbuild: set frame-pointer llvm module flag for CONFIG_FRAME_POINTER

Due to a rustc bug, the -Cforce-frame-pointers=y flag only emits the frame-pointer annotation for functions, but not for the module. This means that functions generated by the LLVM backend such as 'asan.module_ctor' do not receive the frame-pointer annotation.

This is likely to lead to broken backtraces and may also cause issues with ftrace if these features are used with functions generated by the LLVM backend.

Thus, use -Zllvm_module_flag to work around this rustc bug if using a rustc without the fix.

Fixes 2f7ab1267dc9 ("Kbuild: add Rust support")
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 5e73bba74da3..4bfa87e2562a 100644
@@ -966,6 +966,7 @@ KBUILD_CFLAGS += $(stackp-flags-y)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
+KBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109800),,-Zllvm_module_flag=frame-pointer:u32:2:max)
 else
 # Some targets (ARM with Thumb2, for example), can't be built with frame
 # pointers.  For those, we don't have FUNCTION_TRACER automatically

---
base-commit: 0e0611827f3349d0a2ac121c023a6d3260dcecdb
change-id: 20260616-frame-ptr-fix-1c3733f3c764

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>
#1 lore raw
Quoted 3 lines · Alice Ryhl
Fixes 2f7ab1267dc9 ("Kbuild: add Rust support")

For 6.1.y, we use Rust 1.62.0, so we don't have -Zllvm_module_flag, so we cannot go that far back. I guess we will need to accept the issue there.

For 6.6.y, we use Rust 1.73.0, so we don't have it either.

For 6.12.y onward, we support Rust 1.78.0, so it is fine -- -Zllvm_module_flag got added in Rust 1.76.0.

In both 6.1.y and 6.6.y, we also don't have rustc-min-version, because the version is pinned there. That part happens to work, though, just due to how lax Make is... However, if the flag had been available, then we should probably still do it cleanly with a custom patch to avoid confusion.

So I will instead do:

Cc: [email protected] # 6.12.y and later (flag not available in pinned Rust in older LTSs).

Cheers,
Miguel

author reviewer
#2 lore raw
Quoted 21 lines · Miguel Ojeda
Quoted 3 lines · Alice Ryhl
Fixes 2f7ab1267dc9 ("Kbuild: add Rust support")

For 6.1.y, we use Rust 1.62.0, so we don't have -Zllvm_module_flag, so we cannot go that far back. I guess we will need to accept the issue there.

For 6.6.y, we use Rust 1.73.0, so we don't have it either.

For 6.12.y onward, we support Rust 1.78.0, so it is fine -- -Zllvm_module_flag got added in Rust 1.76.0.

In both 6.1.y and 6.6.y, we also don't have rustc-min-version, because the version is pinned there. That part happens to work, though, just due to how lax Make is... However, if the flag had been available, then we should probably still do it cleanly with a custom patch to avoid confusion.

Quoted 4 lines

So I will instead do:

Cc: [email protected] # 6.12.y and later (flag not available in pinned Rust in older LTSs).

Ah, I didn't know it was so new. That makes sense, thanks.

Alice

Applied
#3 lore raw
In reply to Alice Ryhl
Quoted 10 lines · Alice Ryhl

Due to a rustc bug, the -Cforce-frame-pointers=y flag only emits the frame-pointer annotation for functions, but not for the module. This means that functions generated by the LLVM backend such as 'asan.module_ctor' do not receive the frame-pointer annotation.

This is likely to lead to broken backtraces and may also cause issues with ftrace if these features are used with functions generated by the LLVM backend.

Quoted 7 lines

Thus, use -Zllvm_module_flag to work around this rustc bug if using a rustc without the fix.

Fixes 2f7ab1267dc9 ("Kbuild: add Rust support")

Applied to rust-fixes -- thanks everyone!

[ The fix [1] has landed for Rust 1.98.0 (expected release on
2026-08-20). - Miguel ]

[ - Adjusted Cc: stable@ as discussed.

- Added comment with link to the PR, similar to what we did in commit ac35b5580ace ("rust: arm64: set uwtable llvm module flag for CONFIG_UNWIND_TABLES").

- Miguel ]

By the way, as far as I understand, the vger. version of the Cc:
stable@ address is the one that should be used normally:

Use ``Cc: [email protected]`` instead when fixing unpublished vulnerabilities:
it reduces the chance of accidentally exposing the fix to the public by way of 'git send-email', as mails sent to that address are not delivered anywhere.

Cheers,
Miguel