* [PATCH 0/3] perf: Fix missing CET property notes on x86 with -fcf-protection
@ 2026-07-08 4:56 Trevor Allison
2026-07-08 4:56 ` [PATCH 1/3] perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf Trevor Allison
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Trevor Allison @ 2026-07-08 4:56 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, tallison, linux-perf-users, linux-kernel
When perf is built with -fcf-protection, the x86 binary can lack CET
(IBT/SHSTK) in .note.gnu.property because perf links several static
archives whole-archive: if any input object lacks matching property
notes, the linker drops CET from the final binary.
Fix libbpf EXTRA_CFLAGS handling, C++ flag propagation, and missing
.note.gnu.property sections in x86 assembly (like .note.GNU-stack).
All three are needed for CET to survive the link.
Trevor Allison (3):
perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf
perf build: Apply EXTRA_CXXFLAGS to C++ builds
perf x86: Add .note.gnu.property to assembly linked into perf
tools/perf/Makefile.config | 1 +
tools/perf/Makefile.perf | 2 +-
tools/perf/arch/x86/tests/regs_load.S | 24 ++++++++++++++++++++++++
tools/perf/bench/mem-memcpy-x86-64-asm.S | 24 ++++++++++++++++++++++++
tools/perf/bench/mem-memset-x86-64-asm.S | 24 ++++++++++++++++++++++++
5 files changed, 74 insertions(+), 1 deletion(-)
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf
2026-07-08 4:56 [PATCH 0/3] perf: Fix missing CET property notes on x86 with -fcf-protection Trevor Allison
@ 2026-07-08 4:56 ` Trevor Allison
2026-07-08 4:56 ` [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds Trevor Allison
2026-07-08 4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison
2 siblings, 0 replies; 6+ messages in thread
From: Trevor Allison @ 2026-07-08 4:56 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, tallison, linux-perf-users, linux-kernel
The libbpf sub-make passes EXTRA_CFLAGS="-fPIC", replacing the
parent EXTRA_CFLAGS. Append -fPIC instead, since libbpf.a is linked
whole-archive into perf.
Signed-off-by: Trevor Allison <tallison@redhat.com>
---
tools/perf/Makefile.perf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 2b53d9e0c73b..a59ed1d70ecc 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -706,7 +706,7 @@ $(LIBAPI)-clean:
$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
$(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \
O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= subdir= \
- EXTRA_CFLAGS="-fPIC" $@ install_headers
+ EXTRA_CFLAGS="$(EXTRA_CFLAGS) -fPIC" $@ install_headers
$(LIBBPF)-clean:
$(call QUIET_CLEAN, libbpf)
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds
2026-07-08 4:56 [PATCH 0/3] perf: Fix missing CET property notes on x86 with -fcf-protection Trevor Allison
2026-07-08 4:56 ` [PATCH 1/3] perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf Trevor Allison
@ 2026-07-08 4:56 ` Trevor Allison
2026-07-08 5:03 ` sashiko-bot
2026-07-08 4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison
2 siblings, 1 reply; 6+ messages in thread
From: Trevor Allison @ 2026-07-08 4:56 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, tallison, linux-perf-users, linux-kernel
C++ sources did not receive EXTRA_CXXFLAGS or EXTRA_CFLAGS, unlike C
sources. Initialize CXXFLAGS from both so C++ objects such as
demangle-cxx.o get the same builder flags as the rest of perf.
Signed-off-by: Trevor Allison <tallison@redhat.com>
---
tools/perf/Makefile.config | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 0ba307e78fe1..052a6cc7942f 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -17,6 +17,7 @@ detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
+CXXFLAGS := $(EXTRA_CXXFLAGS) $(EXTRA_CFLAGS)
HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
# This is required because the kernel is built with this and some of the code
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf
2026-07-08 4:56 [PATCH 0/3] perf: Fix missing CET property notes on x86 with -fcf-protection Trevor Allison
2026-07-08 4:56 ` [PATCH 1/3] perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf Trevor Allison
2026-07-08 4:56 ` [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds Trevor Allison
@ 2026-07-08 4:56 ` Trevor Allison
2026-07-08 5:08 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Trevor Allison @ 2026-07-08 4:56 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
james.clark, tallison, linux-perf-users, linux-kernel
Assembly sources do not get .note.gnu.property from the compiler.
Add the section to the x86 files that are linked into perf, using the
same approach as the existing .note.GNU-stack notes.
Signed-off-by: Trevor Allison <tallison@redhat.com>
---
tools/perf/arch/x86/tests/regs_load.S | 24 ++++++++++++++++++++++++
tools/perf/bench/mem-memcpy-x86-64-asm.S | 24 ++++++++++++++++++++++++
tools/perf/bench/mem-memset-x86-64-asm.S | 24 ++++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/tools/perf/arch/x86/tests/regs_load.S b/tools/perf/arch/x86/tests/regs_load.S
index 80f14f52e3f6..1947f95cceda 100644
--- a/tools/perf/arch/x86/tests/regs_load.S
+++ b/tools/perf/arch/x86/tests/regs_load.S
@@ -97,3 +97,27 @@ SYM_FUNC_END(perf_regs_load)
* the ELF stack should not be restricted at all and set it RWX.
*/
.section .note.GNU-stack,"",@progbits
+
+/*
+ * We need to provide .note.gnu.property section with IBT and SHSTK,
+ * saying that this object supports the same CET properties as C code
+ * built with -fcf-protection. Otherwise static linking drops CET from
+ * the final perf binary when other objects are CET-enabled.
+ */
+ .pushsection .note.gnu.property, "a"
+ .p2align 3
+ .long 1f - 0f
+ .long 4f - 1f
+ .long 5
+0:
+ .asciz "GNU"
+1:
+ .p2align 3
+ .long 0xc0000002
+ .long 3f - 2f
+2:
+ .long 3
+3:
+ .p2align 3
+4:
+ .popsection
diff --git a/tools/perf/bench/mem-memcpy-x86-64-asm.S b/tools/perf/bench/mem-memcpy-x86-64-asm.S
index 1b9fef7efcdc..e7b84aa43ab4 100644
--- a/tools/perf/bench/mem-memcpy-x86-64-asm.S
+++ b/tools/perf/bench/mem-memcpy-x86-64-asm.S
@@ -18,3 +18,27 @@
* the ELF stack should not be restricted at all and set it RWX.
*/
.section .note.GNU-stack,"",@progbits
+
+/*
+ * We need to provide .note.gnu.property section with IBT and SHSTK,
+ * saying that this object supports the same CET properties as C code
+ * built with -fcf-protection. Otherwise static linking drops CET from
+ * the final perf binary when other objects are CET-enabled.
+ */
+ .pushsection .note.gnu.property, "a"
+ .p2align 3
+ .long 1f - 0f
+ .long 4f - 1f
+ .long 5
+0:
+ .asciz "GNU"
+1:
+ .p2align 3
+ .long 0xc0000002
+ .long 3f - 2f
+2:
+ .long 3
+3:
+ .p2align 3
+4:
+ .popsection
diff --git a/tools/perf/bench/mem-memset-x86-64-asm.S b/tools/perf/bench/mem-memset-x86-64-asm.S
index abd26c95f1aa..f8002da91c3c 100644
--- a/tools/perf/bench/mem-memset-x86-64-asm.S
+++ b/tools/perf/bench/mem-memset-x86-64-asm.S
@@ -13,3 +13,27 @@
* the ELF stack should not be restricted at all and set it RWX.
*/
.section .note.GNU-stack,"",@progbits
+
+/*
+ * We need to provide .note.gnu.property section with IBT and SHSTK,
+ * saying that this object supports the same CET properties as C code
+ * built with -fcf-protection. Otherwise static linking drops CET from
+ * the final perf binary when other objects are CET-enabled.
+ */
+ .pushsection .note.gnu.property, "a"
+ .p2align 3
+ .long 1f - 0f
+ .long 4f - 1f
+ .long 5
+0:
+ .asciz "GNU"
+1:
+ .p2align 3
+ .long 0xc0000002
+ .long 3f - 2f
+2:
+ .long 3
+3:
+ .p2align 3
+4:
+ .popsection
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds
2026-07-08 4:56 ` [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds Trevor Allison
@ 2026-07-08 5:03 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-08 5:03 UTC (permalink / raw)
To: Trevor Allison; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] C++ feature detection tests do not receive `EXTRA_CFLAGS`, causing a structural mismatch between feature detection and actual build compilation flags.
- [Low] Injecting `EXTRA_CFLAGS` into `CXXFLAGS` breaks C++ builds when C-specific flags are present.
--
--- Patch [2]: [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds ---
commit 4b2b9e4dd8644e0e1fa95ec876a875596e1e9178
Author: Trevor Allison <tallison@redhat.com>
perf build: Apply EXTRA_CXXFLAGS to C++ builds
The commit initializes CXXFLAGS in tools/perf/Makefile.config with both
EXTRA_CXXFLAGS and EXTRA_CFLAGS so that C++ objects receive the same builder
flags as the rest of perf.
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 0ba307e78fe1f..052a6cc7942f9 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -17,6 +17,7 @@ detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
> detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
>
> CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
> +CXXFLAGS := $(EXTRA_CXXFLAGS) $(EXTRA_CFLAGS)
[Severity: Low]
Could this cause a build regression if EXTRA_CFLAGS contains C-only flags?
If EXTRA_CFLAGS contains flags that are only valid for C/ObjC (such as
-Wstrict-prototypes), applying them to C++ files causes compiler warnings.
With -Werror enabled, this results in a build failure.
[Severity: Medium]
Does this create a mismatch between feature detection and the main build?
While CXXFLAGS here receives EXTRA_CFLAGS, the C++ feature detection tests in
tools/build/Makefile.feature still only use:
CXXFLAGS="$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))"
If EXTRA_CFLAGS contains mandatory compiler flags like --sysroot or -m32,
the C++ feature detection tests will fail without EXTRA_CFLAGS. This causes
false negatives where the perf binary silently lacks supported features,
despite the main build succeeding.
> HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708045606.43649-1-tallison@redhat.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf
2026-07-08 4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison
@ 2026-07-08 5:08 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-08 5:08 UTC (permalink / raw)
To: Trevor Allison; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Adding .note.gnu.property asserts IBT support without providing ENDBR64 instructions, causing a #CP crash in perf memory benchmarks.
- [Medium] The .note.gnu.property section hardcodes 8-byte alignment, violating the 32-bit x86 ELF specification.
--
--- Patch [3]: [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf ---
commit b48d7edb7fb18bc3dace2af272de108eb561d69b
Author: Trevor Allison <tallison@redhat.com>
perf x86: Add .note.gnu.property to assembly linked into perf
This commit adds `.note.gnu.property` to x86 assembly files linked into
perf to indicate CET properties support. This is intended to prevent static
linking from dropping CET from the final binary.
> diff --git a/tools/perf/arch/x86/tests/regs_load.S b/tools/perf/arch/x86/tests/regs_load.S
> index 80f14f52e3f60..1947f95cceda5 100644
> --- a/tools/perf/arch/x86/tests/regs_load.S
> +++ b/tools/perf/arch/x86/tests/regs_load.S
[ ... ]
> @@ -97,3 +97,27 @@ SYM_FUNC_END(perf_regs_load)
> * the ELF stack should not be restricted at all and set it RWX.
> */
> .section .note.GNU-stack,"",@progbits
> +
> +/*
> + * We need to provide .note.gnu.property section with IBT and SHSTK,
> + * saying that this object supports the same CET properties as C code
> + * built with -fcf-protection. Otherwise static linking drops CET from
> + * the final perf binary when other objects are CET-enabled.
> + */
> + .pushsection .note.gnu.property, "a"
> + .p2align 3
[Severity: Medium]
Does this unconditionally hardcode 8-byte alignment for 32-bit x86 builds?
The assembly file `regs_load.S` can be compiled for 32-bit x86, which requires
4-byte alignment (`.p2align 2`) for ELF notes. When the linker merges these,
the forced 8-byte alignment can create zero-byte padding gaps between notes,
corrupting the contiguous ELF note structure.
Could this cause the dynamic loader or tools like `readelf` to fail to parse
the ELF notes properly?
[ ... ]
> diff --git a/tools/perf/bench/mem-memcpy-x86-64-asm.S b/tools/perf/bench/mem-memcpy-x86-64-asm.S
> index 1b9fef7efcdcc..e7b84aa43ab44 100644
> --- a/tools/perf/bench/mem-memcpy-x86-64-asm.S
> +++ b/tools/perf/bench/mem-memcpy-x86-64-asm.S
[ ... ]
> @@ -18,3 +18,27 @@
> * the ELF stack should not be restricted at all and set it RWX.
> */
> .section .note.GNU-stack,"",@progbits
> +
> +/*
> + * We need to provide .note.gnu.property section with IBT and SHSTK,
> + * saying that this object supports the same CET properties as C code
> + * built with -fcf-protection. Otherwise static linking drops CET from
> + * the final perf binary when other objects are CET-enabled.
> + */
> + .pushsection .note.gnu.property, "a"
> + .p2align 3
[Severity: Medium]
Will this cause a Control Protection Exception (#CP) crash on IBT-capable
hardware when running `perf bench mem memcpy`?
Adding this section artificially claims IBT support and forces the linker to
enable CET on the final `perf` binary. However, `perf`'s local linkage headers
do not automatically emit `endbr64` instructions for `SYM_FUNC_START`.
When `do_memcpy()` in `tools/perf/bench/mem-functions.c` indirectly calls
these assembly entry points like `memcpy_orig`:
fn(dst, src, size);
the hardware may detect the missing `endbr64` on the indirect branch target
and throw a #CP fault.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708045606.43649-1-tallison@redhat.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-08 5:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 4:56 [PATCH 0/3] perf: Fix missing CET property notes on x86 with -fcf-protection Trevor Allison
2026-07-08 4:56 ` [PATCH 1/3] perf build: Preserve EXTRA_CFLAGS when building in-tree libbpf Trevor Allison
2026-07-08 4:56 ` [PATCH 2/3] perf build: Apply EXTRA_CXXFLAGS to C++ builds Trevor Allison
2026-07-08 5:03 ` sashiko-bot
2026-07-08 4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison
2026-07-08 5:08 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox