Re: [PATCH bpf-next v3 11/14] tools build: Implement feature check for BPF atomics in Clang

From: Andrii Nakryiko
Date: Thu Dec 03 2020 - 16:03:32 EST


On Thu, Dec 3, 2020 at 8:08 AM Brendan Jackman <jackmanb@xxxxxxxxxx> wrote:
>
> Change-Id: Ia15bb76f7152fff2974e38242d7430ce2987a71e
>

See recent discussion on KP's patch set. There needs to be a commit
message, even if it's just a copy/paste of subject line. But see also
my other reply, I'm not sure it's worth it to do it this way for
selftests.

> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Quentin Monnet <quentin@xxxxxxxxxxxxx>
> Cc: "Frank Ch. Eigler" <fche@xxxxxxxxxx>
> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Thomas Hebb <tommyhebb@xxxxxxxxx>
> Change-Id: Ie2c3832eaf050d627764071d1927c7546e7c4b4b
> Signed-off-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
> ---
> tools/build/feature/Makefile | 4 ++++
> tools/build/feature/test-clang-bpf-atomics.c | 9 +++++++++
> 2 files changed, 13 insertions(+)
> create mode 100644 tools/build/feature/test-clang-bpf-atomics.c
>
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index cdde783f3018..81370d7fa193 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -70,6 +70,7 @@ FILES= \
> test-libaio.bin \
> test-libzstd.bin \
> test-clang-bpf-co-re.bin \
> + test-clang-bpf-atomics.bin \
> test-file-handle.bin \
> test-libpfm4.bin
>
> @@ -331,6 +332,9 @@ $(OUTPUT)test-clang-bpf-co-re.bin:
> $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
> grep BTF_KIND_VAR
>
> +$(OUTPUT)test-clang-bpf-atomics.bin:
> + $(CLANG) -S -g -target bpf -mcpu=v3 -Werror=implicit-function-declaration -o - $(patsubst %.bin,%.c,$(@F)) 2>&1
> +
> $(OUTPUT)test-file-handle.bin:
> $(BUILD)
>
> diff --git a/tools/build/feature/test-clang-bpf-atomics.c b/tools/build/feature/test-clang-bpf-atomics.c
> new file mode 100644
> index 000000000000..8b5fcdd4ba6f
> --- /dev/null
> +++ b/tools/build/feature/test-clang-bpf-atomics.c
> @@ -0,0 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (c) 2020 Google
> +
> +int x = 0;
> +
> +int foo(void)
> +{
> + return __sync_val_compare_and_swap(&x, 1, 2);
> +}
> --
> 2.29.2.454.gaff20da3a2-goog
>