Re: [PATCH v3 1/4] perf build: enable -fno-strict-aliasing
From: Namhyung Kim
Date: Fri Jun 27 2025 - 12:39:00 EST
On Wed, Jun 25, 2025 at 01:23:08PM -0700, Eric Biggers wrote:
> perf pulls in code from kernel headers that assumes it is being built
> with -fno-strict-aliasing, namely put_unaligned_*() from
> <linux/unaligned.h> which write the data using packed structs that lack
> the may_alias attribute. Enable -fno-strict-aliasing to prevent
> miscompilations in sha1.c which would otherwise occur due to this issue.
>
> Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
> ---
> tools/perf/Makefile.config | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 24736b0bbb302..70a3e771c7c08 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -17,10 +17,14 @@ 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))
> HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
>
> +# This is required because the kernel is built with this and some of the code
> +# borrowed from kernel headers depends on it, e.g. put_unaligned_*().
> +CFLAGS += -fno-strict-aliasing
This makes a build error with REFCNT_CHECKING=1.
In file included from util/symbol.c:27:
In function ‘dso__set_symbol_names_len’,
inlined from ‘dso__sort_by_name’ at util/symbol.c:638:4:
util/dso.h:654:46: error: ‘len’ may be used uninitialized [-Werror=maybe-uninitialized]
654 | RC_CHK_ACCESS(dso)->symbol_names_len = len;
| ^
util/symbol.c: In function ‘dso__sort_by_name’:
util/symbol.c:634:24: note: ‘len’ was declared here
634 | size_t len;
| ^~~
I'll simply add this to work around it:
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 8b30c6f16a9eeac1..73dab94fab74e829 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -631,7 +631,7 @@ void dso__sort_by_name(struct dso *dso)
{
mutex_lock(dso__lock(dso));
if (!dso__sorted_by_name(dso)) {
- size_t len;
+ size_t len = 0;
dso__set_symbol_names(dso, symbols__sort_by_name(dso__symbols(dso), &len));
if (dso__symbol_names(dso)) {
Thanks,
Namhyung
> +
> # Enabled Wthread-safety analysis for clang builds.
> ifeq ($(CC_NO_CLANG), 0)
> CFLAGS += -Wthread-safety
> endif
>
> --
> 2.50.0
>