mbox series

[v1,00/13] tools header compiler.h update

Message ID 20240310020509.647319-1-irogers@google.com
Headers show
Series tools header compiler.h update | expand

Message

Ian Rogers March 10, 2024, 2:04 a.m. UTC
Update tools/include/linux/compiler.h so that the definition of
noinline can be updated to avoid an LLVM libc breakage. Fix build
issues and try to synchronize other pieces on the way. For atomic.h,
don't try to synchronize and just punt to stdatomic.h that we can
assume is present since the move to C11.

Ian Rogers (13):
  tools bpf: Synchronize bpf.h with kernel uapi version
  libbpf: Make __printf define conditional
  libperf xyarray: Use correct stddef.h include
  perf expr: Add missing stdbool.h include
  perf expr: Tidy up header guard
  perf debug: Add missing linux/types.h include
  perf cacheline: Add missing linux/types.h include
  perf arm-spe: Add missing linux/types.h include
  tools headers: Rewrite linux/atomic.h using C11's stdatomic.h
  asm-generic: Avoid transitive dependency for unaligned.h
  tools headers: Sync linux/overflow.h
  tools headers: Sync compiler.h headers
  tools headers: Rename noinline to __noinline

 include/asm-generic/unaligned.h               |   2 +
 tools/arch/x86/include/asm/atomic.h           |  84 ----
 tools/include/asm-generic/atomic-gcc.h        |  95 ----
 tools/include/asm-generic/bitops/non-atomic.h |   1 +
 tools/include/asm-generic/unaligned.h         |   2 +
 tools/include/asm/atomic.h                    |  11 -
 tools/include/asm/rwonce.h                    |  63 +++
 tools/include/linux/atomic.h                  | 107 ++++-
 tools/include/linux/compiler-clang.h          | 124 +++++
 tools/include/linux/compiler-gcc.h            | 145 +++++-
 tools/include/linux/compiler.h                | 221 ++-------
 tools/include/linux/compiler_attributes.h     | 449 ++++++++++++++++++
 tools/include/linux/compiler_types.h          | 171 ++++++-
 tools/include/linux/overflow.h                | 331 ++++++++++---
 tools/include/linux/rbtree.h                  |   1 +
 tools/include/linux/string.h                  |   1 +
 tools/include/linux/types.h                   |  17 +-
 tools/include/uapi/linux/bpf.h                |   1 +
 tools/lib/bpf/libbpf.c                        |   4 +-
 tools/lib/perf/include/internal/xyarray.h     |   2 +-
 tools/perf/arch/x86/tests/bp-modify.c         |   4 +-
 tools/perf/bench/find-bit-bench.c             |   2 +-
 tools/perf/check-headers.sh                   |   4 +
 tools/perf/tests/bp_account.c                 |   2 +-
 tools/perf/tests/bp_signal.c                  |   2 +-
 tools/perf/tests/bp_signal_overflow.c         |   2 +-
 tools/perf/tests/dwarf-unwind.c               |  12 +-
 tools/perf/tests/workloads/leafloop.c         |   8 +-
 tools/perf/tests/workloads/thloop.c           |   4 +-
 .../util/arm-spe-decoder/arm-spe-decoder.h    |   1 +
 .../arm-spe-decoder/arm-spe-pkt-decoder.c     |   8 +-
 tools/perf/util/cacheline.h                   |   1 +
 tools/perf/util/debug.h                       |   1 +
 tools/perf/util/expr.h                        |   8 +-
 .../selftests/kvm/include/kvm_util_base.h     |   3 +-
 35 files changed, 1388 insertions(+), 506 deletions(-)
 delete mode 100644 tools/arch/x86/include/asm/atomic.h
 delete mode 100644 tools/include/asm-generic/atomic-gcc.h
 delete mode 100644 tools/include/asm/atomic.h
 create mode 100644 tools/include/asm/rwonce.h
 create mode 100644 tools/include/linux/compiler-clang.h
 create mode 100644 tools/include/linux/compiler_attributes.h

Comments

Miguel Ojeda March 10, 2024, 11:24 a.m. UTC | #1
On Sun, Mar 10, 2024 at 3:06 AM Ian Rogers <irogers@google.com> wrote:
>
> [1] https://clang.llvm.org/docs/AttributeReference.html#noinline
> Reported-by: Christopher Di Bella <cjdb@google.com>

Out of curiosity, was this due to the `[[gnu::noinline]]` or similar
in e.g. `src/string/memset_explicit.h`?

> -#define   noinline                      __attribute__((__noinline__))
> +#define   __noinline                      __attribute__((__noinline__))

I guess it does not matter since I don't see it used in `tools/`, but
should the one inside `__fix_address` be updated too? Or is the idea
to keep the diff as minimal as possible?

Cheers,
Miguel
Michael S. Tsirkin March 11, 2024, 3:43 p.m. UTC | #2
On Sat, Mar 09, 2024 at 06:05:08PM -0800, Ian Rogers wrote:
> An issue was reported with clang and llvm libc where the noinline
> attribute [1] was being expanded due to the #define in
> linux/compiler.h (now in compiler_attributes.h). The expansion caused
> the __attribute__ to appear twice and break the build. To avoid this
> conflict, rename noinline to __noinline which is more consistent with
> other compiler attributes.
> 
> [1] https://clang.llvm.org/docs/AttributeReference.html#noinline

Following this link, I don't see __noinline there - only __noinline__ and
noinline. What's up?


Als, pls add an empty line before tags.

> Reported-by: Christopher Di Bella <cjdb@google.com>
> 
> Signed-off-by: Ian Rogers <irogers@google.com>


tags should not have empty lines between them.

> ---
>  tools/include/linux/compiler_attributes.h |  4 ++--
>  tools/perf/arch/x86/tests/bp-modify.c     |  4 ++--
>  tools/perf/bench/find-bit-bench.c         |  2 +-
>  tools/perf/tests/bp_account.c             |  2 +-
>  tools/perf/tests/bp_signal.c              |  2 +-
>  tools/perf/tests/bp_signal_overflow.c     |  2 +-
>  tools/perf/tests/dwarf-unwind.c           | 12 ++++++------
>  tools/perf/tests/workloads/leafloop.c     |  8 ++++----
>  tools/perf/tests/workloads/thloop.c       |  4 ++--
>  9 files changed, 20 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/include/linux/compiler_attributes.h b/tools/include/linux/compiler_attributes.h
> index 9bfaec783e48..1ff3d85f5af3 100644
> --- a/tools/include/linux/compiler_attributes.h
> +++ b/tools/include/linux/compiler_attributes.h
> @@ -267,12 +267,12 @@
>  # define __flatten			__attribute__((flatten))
>  
>  /*
> - * Note the missing underscores.
> + * Note, the kernel version is missing the underscores.
>   *
>   *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute
>   * clang: mentioned
>   */
> -#define   noinline                      __attribute__((__noinline__))
> +#define   __noinline                      __attribute__((__noinline__))
>  
>  /*
>   * Optional: only supported since gcc >= 8
> diff --git a/tools/perf/arch/x86/tests/bp-modify.c b/tools/perf/arch/x86/tests/bp-modify.c
> index 0924ccd9e36d..65493ff7a76f 100644
> --- a/tools/perf/arch/x86/tests/bp-modify.c
> +++ b/tools/perf/arch/x86/tests/bp-modify.c
> @@ -15,13 +15,13 @@
>  #include "tests/tests.h"
>  #include "arch-tests.h"
>  
> -static noinline int bp_1(void)
> +static __noinline int bp_1(void)
>  {
>  	pr_debug("in %s\n", __func__);
>  	return 0;
>  }
>  
> -static noinline int bp_2(void)
> +static __noinline int bp_2(void)
>  {
>  	pr_debug("in %s\n", __func__);
>  	return 0;
> diff --git a/tools/perf/bench/find-bit-bench.c b/tools/perf/bench/find-bit-bench.c
> index 7e25b0e413f6..dd97a51649bc 100644
> --- a/tools/perf/bench/find-bit-bench.c
> +++ b/tools/perf/bench/find-bit-bench.c
> @@ -31,7 +31,7 @@ static const char *const bench_usage[] = {
>  static unsigned int accumulator;
>  static unsigned int use_of_val;
>  
> -static noinline void workload(int val)
> +static __noinline void workload(int val)
>  {
>  	use_of_val += val;
>  	accumulator++;
> diff --git a/tools/perf/tests/bp_account.c b/tools/perf/tests/bp_account.c
> index 6f921db33cf9..459f61752a71 100644
> --- a/tools/perf/tests/bp_account.c
> +++ b/tools/perf/tests/bp_account.c
> @@ -34,7 +34,7 @@
>  
>  static volatile long the_var;
>  
> -static noinline int test_function(void)
> +static __noinline int test_function(void)
>  {
>  	return 0;
>  }
> diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c
> index 1f2908f02389..484a7e7f96ee 100644
> --- a/tools/perf/tests/bp_signal.c
> +++ b/tools/perf/tests/bp_signal.c
> @@ -59,7 +59,7 @@ static void __test_function(volatile long *ptr)
>  }
>  #endif
>  
> -static noinline int test_function(void)
> +static __noinline int test_function(void)
>  {
>  	__test_function(&the_var);
>  	the_var++;
> diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c
> index 4e897c2cf26b..9436bf2973f8 100644
> --- a/tools/perf/tests/bp_signal_overflow.c
> +++ b/tools/perf/tests/bp_signal_overflow.c
> @@ -30,7 +30,7 @@
>  
>  static int overflows;
>  
> -static noinline int test_function(void)
> +static __noinline int test_function(void)
>  {
>  	return time(NULL);
>  }
> diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c
> index d01aa931fe81..a669c69a9242 100644
> --- a/tools/perf/tests/dwarf-unwind.c
> +++ b/tools/perf/tests/dwarf-unwind.c
> @@ -109,7 +109,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
>  	return strcmp((const char *) symbol, funcs[idx]);
>  }
>  
> -NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__thread(struct thread *thread)
> +NO_TAIL_CALL_ATTRIBUTE __noinline int test_dwarf_unwind__thread(struct thread *thread)
>  {
>  	struct perf_sample sample;
>  	unsigned long cnt = 0;
> @@ -140,7 +140,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__thread(struct thread *thr
>  
>  static int global_unwind_retval = -INT_MAX;
>  
> -NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__compare(void *p1, void *p2)
> +NO_TAIL_CALL_ATTRIBUTE __noinline int test_dwarf_unwind__compare(void *p1, void *p2)
>  {
>  	/* Any possible value should be 'thread' */
>  	struct thread *thread = *(struct thread **)p1;
> @@ -159,7 +159,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__compare(void *p1, void *p
>  	return p1 - p2;
>  }
>  
> -NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_3(struct thread *thread)
> +NO_TAIL_CALL_ATTRIBUTE __noinline int test_dwarf_unwind__krava_3(struct thread *thread)
>  {
>  	struct thread *array[2] = {thread, thread};
>  	void *fp = &bsearch;
> @@ -178,7 +178,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_3(struct thread *th
>  	return global_unwind_retval;
>  }
>  
> -NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_2(struct thread *thread)
> +NO_TAIL_CALL_ATTRIBUTE __noinline int test_dwarf_unwind__krava_2(struct thread *thread)
>  {
>  	int ret;
>  
> @@ -187,7 +187,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_2(struct thread *th
>  	return ret;
>  }
>  
> -NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_1(struct thread *thread)
> +NO_TAIL_CALL_ATTRIBUTE __noinline int test_dwarf_unwind__krava_1(struct thread *thread)
>  {
>  	int ret;
>  
> @@ -196,7 +196,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_1(struct thread *th
>  	return ret;
>  }
>  
> -noinline int test__dwarf_unwind(struct test_suite *test __maybe_unused,
> +__noinline int test__dwarf_unwind(struct test_suite *test __maybe_unused,
>  				int subtest __maybe_unused)
>  {
>  	struct machine *machine;
> diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
> index 1bf5cc97649b..89d2cec2f461 100644
> --- a/tools/perf/tests/workloads/leafloop.c
> +++ b/tools/perf/tests/workloads/leafloop.c
> @@ -4,18 +4,18 @@
>  #include "../tests.h"
>  
>  /* We want to check these symbols in perf script */
> -noinline void leaf(volatile int b);
> -noinline void parent(volatile int b);
> +__noinline void leaf(volatile int b);
> +__noinline void parent(volatile int b);
>  
>  static volatile int a;
>  
> -noinline void leaf(volatile int b)
> +__noinline void leaf(volatile int b)
>  {
>  	for (;;)
>  		a += b;
>  }
>  
> -noinline void parent(volatile int b)
> +__noinline void parent(volatile int b)
>  {
>  	leaf(b);
>  }
> diff --git a/tools/perf/tests/workloads/thloop.c b/tools/perf/tests/workloads/thloop.c
> index 457b29f91c3e..e252efb76203 100644
> --- a/tools/perf/tests/workloads/thloop.c
> +++ b/tools/perf/tests/workloads/thloop.c
> @@ -9,14 +9,14 @@
>  static volatile sig_atomic_t done;
>  
>  /* We want to check this symbol in perf report */
> -noinline void test_loop(void);
> +__noinline void test_loop(void);
>  
>  static void sighandler(int sig __maybe_unused)
>  {
>  	done = 1;
>  }
>  
> -noinline void test_loop(void)
> +__noinline void test_loop(void)
>  {
>  	while (!done);
>  }
> -- 
> 2.44.0.278.ge034bb2e1d-goog
Nick Desaulniers March 11, 2024, 4:21 p.m. UTC | #3
On Mon, Mar 11, 2024 at 8:44 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Sat, Mar 09, 2024 at 06:05:08PM -0800, Ian Rogers wrote:
> > An issue was reported with clang and llvm libc where the noinline
> > attribute [1] was being expanded due to the #define in
> > linux/compiler.h (now in compiler_attributes.h). The expansion caused
> > the __attribute__ to appear twice and break the build. To avoid this
> > conflict, rename noinline to __noinline which is more consistent with
> > other compiler attributes.
> >
> > [1] https://clang.llvm.org/docs/AttributeReference.html#noinline
>
> Following this link, I don't see __noinline there - only __noinline__ and
> noinline. What's up?

__noinline (which is what this patch is changing the preprocessor
define to) will not be expanded in the presence of
__attribute__((__noinline__)), __attribute__((noinline)), or
[[gnu::inline]], unlike the previous macro definition.