The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [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; 4+ 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] 4+ 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; 4+ 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] 4+ 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  4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison
  2 siblings, 0 replies; 4+ 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] 4+ 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
  2 siblings, 0 replies; 4+ 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] 4+ messages in thread

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

Thread overview: 4+ 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  4:56 ` [PATCH 3/3] perf x86: Add .note.gnu.property to assembly linked into perf Trevor Allison

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