mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf build: Only enable context analysis with Clang 23 or later
@ 2026-11-23 16:46 James Clark
  2026-11-23 18:44 ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: James Clark @ 2026-11-23 16:46 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter
  Cc: linux-perf-users, linux-kernel, James Clark

Context analysis requires Clang 23 or later (see
Documentation/dev-tools/context-analysis.rst), otherwise the build fails
on older versions, e.g. Clang 18:

  util/env.h:142:39: error: use of undeclared identifier 'lock'
    142 |    struct rb_root          infos __guarded_by(&lock);

Only enable it when the Clang version is supported. Leave the other
thread safety options enabled if they exist because they don't cause
build failures at the moment, and might provide benefits even without
-DWARN_CONTEXT_ANALYSIS.

Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags")
Signed-off-by: James Clark <james.clark@linaro.org>
---
Assisted by Claude Opus 5.5
---
 tools/perf/Makefile.config | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index aed2e952c8f3..f5adceee5589 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0)
     CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
   endif
 
-  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
-  # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks.
-  CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety
+  CFLAGS += -Wthread-safety
   CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
-  CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
+
+  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
+  # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later.
+  CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null)
+  ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y)
+    CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes
+  endif
 endif
 
 include $(srctree)/tools/scripts/Makefile.arch

---
base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
change-id: 20261123-james-perf-late-parse-attr-4e996381859f

Best regards,
--  
James Clark <james.clark@linaro.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-23 16:46 [PATCH] perf build: Only enable context analysis with Clang 23 or later James Clark
@ 2026-11-23 18:44 ` Ian Rogers
  2026-11-23 19:55   ` Arnaldo Melo
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-23 18:44 UTC (permalink / raw)
  To: James Clark
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Jiri Olsa, Adrian Hunter, linux-perf-users,
	linux-kernel

On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote:
>
> Context analysis requires Clang 23 or later (see
> Documentation/dev-tools/context-analysis.rst), otherwise the build fails
> on older versions, e.g. Clang 18:
>
>   util/env.h:142:39: error: use of undeclared identifier 'lock'
>     142 |    struct rb_root          infos __guarded_by(&lock);
>
> Only enable it when the Clang version is supported. Leave the other
> thread safety options enabled if they exist because they don't cause
> build failures at the moment, and might provide benefits even without
> -DWARN_CONTEXT_ANALYSIS.

So we've had -Wthread-safety for a long time in the perf tree, I'm
guessing __guarded_by is missing on older clang versions. Can we just
stub out the __guarded_by for these old clang versions and keep the
lock checking?

Thanks,
Ian

> Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags")
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
> Assisted by Claude Opus 5.5
> ---
>  tools/perf/Makefile.config | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index aed2e952c8f3..f5adceee5589 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0)
>      CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
>    endif
>
> -  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
> -  # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks.
> -  CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety
> +  CFLAGS += -Wthread-safety
>    CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
> -  CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
> +
> +  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
> +  # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later.
> +  CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null)
> +  ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y)
> +    CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes
> +  endif
>  endif
>
>  include $(srctree)/tools/scripts/Makefile.arch
>
> ---
> base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
> change-id: 20261123-james-perf-late-parse-attr-4e996381859f
>
> Best regards,
> --
> James Clark <james.clark@linaro.org>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-23 18:44 ` Ian Rogers
@ 2026-11-23 19:55   ` Arnaldo Melo
  2026-11-23 21:23     ` Namhyung Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Melo @ 2026-11-23 19:55 UTC (permalink / raw)
  To: linux-perf-users, Ian Rogers, James Clark
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Jiri Olsa, Adrian Hunter, linux-kernel



On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote:
>On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote:
>>
>> Context analysis requires Clang 23 or later (see
>> Documentation/dev-tools/context-analysis.rst), otherwise the build fails
>> on older versions, e.g. Clang 18:
>>
>>   util/env.h:142:39: error: use of undeclared identifier 'lock'
>>     142 |    struct rb_root          infos __guarded_by(&lock);
>>
>> Only enable it when the Clang version is supported. Leave the other
>> thread safety options enabled if they exist because they don't cause
>> build failures at the moment, and might provide benefits even without
>> -DWARN_CONTEXT_ANALYSIS.
>
>So we've had -Wthread-safety for a long time in the perf tree, I'm
>guessing __guarded_by is missing on older clang versions. Can we just
>stub out the __guarded_by for these old clang versions and keep the
>lock checking?

Looks way more reasonable, and no need for a feature test since we know the compiler version when __guarded_by was introduced, right? 

Regards,

- Arnaldo
>
>Thanks,
>Ian
>
>> Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags")
>> Signed-off-by: James Clark <james.clark@linaro.org>
>> ---
>> Assisted by Claude Opus 5.5
>> ---
>>  tools/perf/Makefile.config | 12 ++++++++----
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
>> index aed2e952c8f3..f5adceee5589 100644
>> --- a/tools/perf/Makefile.config
>> +++ b/tools/perf/Makefile.config
>> @@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0)
>>      CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
>>    endif
>>
>> -  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
>> -  # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks.
>> -  CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety
>> +  CFLAGS += -Wthread-safety
>>    CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
>> -  CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
>> +
>> +  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
>> +  # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later.
>> +  CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null)
>> +  ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y)
>> +    CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes
>> +  endif
>>  endif
>>
>>  include $(srctree)/tools/scripts/Makefile.arch
>>
>> ---
>> base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
>> change-id: 20261123-james-perf-late-parse-attr-4e996381859f
>>
>> Best regards,
>> --
>> James Clark <james.clark@linaro.org>
>>
>

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-23 19:55   ` Arnaldo Melo
@ 2026-11-23 21:23     ` Namhyung Kim
  2026-11-24 11:24       ` James Clark
  0 siblings, 1 reply; 7+ messages in thread
From: Namhyung Kim @ 2026-11-23 21:23 UTC (permalink / raw)
  To: Arnaldo Melo
  Cc: linux-perf-users, Ian Rogers, James Clark, Peter Zijlstra,
	Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	linux-kernel

Hello,

On Mon, Nov 23, 2026 at 04:55:16PM -0300, Arnaldo Melo wrote:
> 
> 
> On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote:
> >On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote:
> >>
> >> Context analysis requires Clang 23 or later (see
> >> Documentation/dev-tools/context-analysis.rst), otherwise the build fails
> >> on older versions, e.g. Clang 18:
> >>
> >>   util/env.h:142:39: error: use of undeclared identifier 'lock'
> >>     142 |    struct rb_root          infos __guarded_by(&lock);
> >>
> >> Only enable it when the Clang version is supported. Leave the other
> >> thread safety options enabled if they exist because they don't cause
> >> build failures at the moment, and might provide benefits even without
> >> -DWARN_CONTEXT_ANALYSIS.
> >
> >So we've had -Wthread-safety for a long time in the perf tree, I'm
> >guessing __guarded_by is missing on older clang versions. Can we just
> >stub out the __guarded_by for these old clang versions and keep the
> >lock checking?
> 
> Looks way more reasonable, and no need for a feature test since we know
> the compiler version when __guarded_by was introduced, right? 

Sorry for the trouble.  I checked with clang 21 and it didn't have a
problem.

Thanks,
Namhyung


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-23 21:23     ` Namhyung Kim
@ 2026-11-24 11:24       ` James Clark
  2026-11-24 13:08         ` Arnaldo Melo
  0 siblings, 1 reply; 7+ messages in thread
From: James Clark @ 2026-11-24 11:24 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Melo, Ian Rogers
  Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel



On 23/11/2026 21:23, Namhyung Kim wrote:
> Hello,
> 
> On Mon, Nov 23, 2026 at 04:55:16PM -0300, Arnaldo Melo wrote:
>>
>>
>> On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote:
>>> On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote:
>>>>
>>>> Context analysis requires Clang 23 or later (see
>>>> Documentation/dev-tools/context-analysis.rst), otherwise the build fails
>>>> on older versions, e.g. Clang 18:
>>>>
>>>>    util/env.h:142:39: error: use of undeclared identifier 'lock'
>>>>      142 |    struct rb_root          infos __guarded_by(&lock);
>>>>
>>>> Only enable it when the Clang version is supported. Leave the other
>>>> thread safety options enabled if they exist because they don't cause
>>>> build failures at the moment, and might provide benefits even without
>>>> -DWARN_CONTEXT_ANALYSIS.
>>>
>>> So we've had -Wthread-safety for a long time in the perf tree, I'm
>>> guessing __guarded_by is missing on older clang versions. Can we just
>>> stub out the __guarded_by for these old clang versions and keep the
>>> lock checking?
>>
>> Looks way more reasonable, and no need for a feature test since we know
>> the compiler version when __guarded_by was introduced, right?
> 
> Sorry for the trouble.  I checked with clang 21 and it didn't have a
> problem.
> 
> Thanks,
> Namhyung
> 

Looks like __guarded_by() has also been around since at least clang 18, 
so that wasn't the issue. The problem is that it's not supported on 
struct _members_ specifically until clang 19.

I sent another version that stubs it out for < 19 which works. The 
commit summary changed to "perf build: Stub out __guarded_by() on older 
Clang versions".

The header diverges from the kernel one which isn't great, but I suppose 
that's better than someone on clang 17 or 18 missing out on all of the 
lock analysis.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-24 11:24       ` James Clark
@ 2026-11-24 13:08         ` Arnaldo Melo
  2026-11-24 13:43           ` James Clark
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Melo @ 2026-11-24 13:08 UTC (permalink / raw)
  To: James Clark, Namhyung Kim, Ian Rogers
  Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel



On November 24, 2026 8:24:37 AM GMT-03:00, James Clark <james.clark@linaro.org> wrote:

>Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19.

>I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions".

>The header diverges from the kernel one which isn't great, but I suppose that's better

Right, but you changed how check-headers.sh treats it to cope with the difference and I'll make sure that tools/perf/scripts/sync-headers.sh handles this case as well, namely if check-headers.sh detects drift, sync-headers.sh will update the tools copy while keeping the tools specific parts. 

acme@number:~/git/perf-tools-next$ make -C tools/perf help | grep headers
  check-headers         - check which header copies are out of sync with the kernel
  sync-headers          - sync those header copies with the kernel, creating commits
acme@number:~/git/perf-tools-next$ tools/perf/scripts/sync-headers.sh --helpUsage: sync-headers.sh [OPTIONS]

Sync tools/ header copies with the kernel sources and create commits.

Options:
  -n, --dry-run       Show what would be done without making changes
  -N, --no-build      Skip the perf build verification step
  -C, --no-commit     Copy files but do not create git commits
  -f, --filter PAT    Only process headers matching PAT (substring match
                      against the kernel-side path)
  -F, --force         Sync also when both copies have content the other
                      lacks, after manual investigation; tools/ additions
                      dropped are recorded in the commit
  -o, --output DIR    Build output directory (default: /tmp/build/perf-tools-1000)
  -v, --verbose       Show more details
  -h, --help          Show this help

Environment:
  SIGN_OFF_NAME       Override git user.name for Signed-off-by
  SIGN_OFF_EMAIL      Override git user.email for Signed-off-by
  OUTPUT_DIR          Build output directory

Through make:
  SYNC_HEADERS_ARGS   Options to pass to this script, e.g.:
                      make -C tools/perf sync-headers SYNC_HEADERS_ARGS='-n'

The script:
  1. Runs 'make -C tools/perf check-headers' to find stale copies.
  2. For each stale header, identifies the kernel commits that changed it,
     including the merges that brought content of their own.
  3. Copies the kernel header into the tools/ tree, skipping it when only
     the tools/ copy changed (it is ahead) or when it carries intentional
     edits, and stopping for manual investigation when both sides have
     content the other lacks.
  4. For beauty headers, runs the relevant beauty script(s) before and
     after, showing new/changed string table entries.
  5. Builds perf and the other consumers of the header to verify nothing
     breaks.
  6. Creates a git commit per header (or group) with the standard commit
     message format.

acme@number:~/git/perf-tools-next$

I.e. the limitation in point number three, about intentional edits, needs to be lifted.

- Arnaldo

> than someone on clang 17 or 18 missing out on all of the lock analysis.

Right. 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later
  2026-11-24 13:08         ` Arnaldo Melo
@ 2026-11-24 13:43           ` James Clark
  0 siblings, 0 replies; 7+ messages in thread
From: James Clark @ 2026-11-24 13:43 UTC (permalink / raw)
  To: Arnaldo Melo
  Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel,
	Namhyung Kim, Ian Rogers



On 24/11/2026 13:08, Arnaldo Melo wrote:
> 
> 
> On November 24, 2026 8:24:37 AM GMT-03:00, James Clark <james.clark@linaro.org> wrote:
> 
>> Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19.
> 
>> I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions".
> 
>> The header diverges from the kernel one which isn't great, but I suppose that's better
> 
> Right, but you changed how check-headers.sh treats it to cope with the difference and I'll make sure that tools/perf/scripts/sync-headers.sh handles this case as well, namely if check-headers.sh detects drift, sync-headers.sh will update the tools copy while keeping the tools specific parts.
> 
> acme@number:~/git/perf-tools-next$ make -C tools/perf help | grep headers
>    check-headers         - check which header copies are out of sync with the kernel
>    sync-headers          - sync those header copies with the kernel, creating commits
> acme@number:~/git/perf-tools-next$ tools/perf/scripts/sync-headers.sh --helpUsage: sync-headers.sh [OPTIONS]
> 
> Sync tools/ header copies with the kernel sources and create commits.
> 
> Options:
>    -n, --dry-run       Show what would be done without making changes
>    -N, --no-build      Skip the perf build verification step
>    -C, --no-commit     Copy files but do not create git commits
>    -f, --filter PAT    Only process headers matching PAT (substring match
>                        against the kernel-side path)
>    -F, --force         Sync also when both copies have content the other
>                        lacks, after manual investigation; tools/ additions
>                        dropped are recorded in the commit
>    -o, --output DIR    Build output directory (default: /tmp/build/perf-tools-1000)
>    -v, --verbose       Show more details
>    -h, --help          Show this help
> 
> Environment:
>    SIGN_OFF_NAME       Override git user.name for Signed-off-by
>    SIGN_OFF_EMAIL      Override git user.email for Signed-off-by
>    OUTPUT_DIR          Build output directory
> 
> Through make:
>    SYNC_HEADERS_ARGS   Options to pass to this script, e.g.:
>                        make -C tools/perf sync-headers SYNC_HEADERS_ARGS='-n'
> 
> The script:
>    1. Runs 'make -C tools/perf check-headers' to find stale copies.
>    2. For each stale header, identifies the kernel commits that changed it,
>       including the merges that brought content of their own.
>    3. Copies the kernel header into the tools/ tree, skipping it when only
>       the tools/ copy changed (it is ahead) or when it carries intentional
>       edits, and stopping for manual investigation when both sides have
>       content the other lacks.
>    4. For beauty headers, runs the relevant beauty script(s) before and
>       after, showing new/changed string table entries.
>    5. Builds perf and the other consumers of the header to verify nothing
>       breaks.
>    6. Creates a git commit per header (or group) with the standard commit
>       message format.
> 
> acme@number:~/git/perf-tools-next$
> 
> I.e. the limitation in point number three, about intentional edits, needs to be lifted.
> 
> - Arnaldo

Oh nice I hadn't noticed sync-headers.sh. What's the plan to support 
tools side edits? Something like exporting the kernel change as a patch 
and trying to apply it on top of the tools copy? Or I suppose you could 
do it the other way around and try to apply the tools diff on top of a 
new clean kernel copy.

> 
>> than someone on clang 17 or 18 missing out on all of the lock analysis.
> 
> Right.
> 
> - Arnaldo


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-24 13:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 16:46 [PATCH] perf build: Only enable context analysis with Clang 23 or later James Clark
2026-11-23 18:44 ` Ian Rogers
2026-11-23 19:55   ` Arnaldo Melo
2026-11-23 21:23     ` Namhyung Kim
2026-11-24 11:24       ` James Clark
2026-11-24 13:08         ` Arnaldo Melo
2026-11-24 13:43           ` James Clark

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

all inboxes | Powered by JetHome®