2023-03-16 15:51:35

by Marco Elver

[permalink] [raw]
Subject: [PATCH] kfence, kcsan: avoid passing -g for tests

Nathan reported that when building with GNU as and a version of clang
that defaults to DWARF5:

$ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \
LLVM=1 LLVM_IAS=0 O=build \
mrproper allmodconfig mm/kfence/kfence_test.o
/tmp/kfence_test-08a0a0.s: Assembler messages:
/tmp/kfence_test-08a0a0.s:14627: Error: non-constant .uleb128 is not supported
/tmp/kfence_test-08a0a0.s:14628: Error: non-constant .uleb128 is not supported
/tmp/kfence_test-08a0a0.s:14632: Error: non-constant .uleb128 is not supported
/tmp/kfence_test-08a0a0.s:14633: Error: non-constant .uleb128 is not supported
/tmp/kfence_test-08a0a0.s:14639: Error: non-constant .uleb128 is not supported
...

This is because `-g` defaults to the compiler debug info default. If the
assembler does not support some of the directives used, the above errors
occur. To fix, remove the explicit passing of `-g`.

All these tests want is that stack traces print valid function names,
and debug info is not required for that. I currently cannot recall why I
added the explicit `-g`.

Reported-by: Nathan Chancellor <[email protected]>
Signed-off-by: Marco Elver <[email protected]>
---
kernel/kcsan/Makefile | 2 +-
mm/kfence/Makefile | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/kcsan/Makefile b/kernel/kcsan/Makefile
index 8cf70f068d92..a45f3dfc8d14 100644
--- a/kernel/kcsan/Makefile
+++ b/kernel/kcsan/Makefile
@@ -16,6 +16,6 @@ obj-y := core.o debugfs.o report.o
KCSAN_INSTRUMENT_BARRIERS_selftest.o := y
obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o

-CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -g -fno-omit-frame-pointer
+CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -fno-omit-frame-pointer
CFLAGS_kcsan_test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
obj-$(CONFIG_KCSAN_KUNIT_TEST) += kcsan_test.o
diff --git a/mm/kfence/Makefile b/mm/kfence/Makefile
index 0bb95728a784..2de2a58d11a1 100644
--- a/mm/kfence/Makefile
+++ b/mm/kfence/Makefile
@@ -2,5 +2,5 @@

obj-y := core.o report.o

-CFLAGS_kfence_test.o := -g -fno-omit-frame-pointer -fno-optimize-sibling-calls
+CFLAGS_kfence_test.o := -fno-omit-frame-pointer -fno-optimize-sibling-calls
obj-$(CONFIG_KFENCE_KUNIT_TEST) += kfence_test.o
--
2.40.0.rc1.284.g88254d51c5-goog



2023-03-16 16:05:32

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kfence, kcsan: avoid passing -g for tests

On Thu, Mar 16, 2023 at 04:51:04PM +0100, Marco Elver wrote:
> Nathan reported that when building with GNU as and a version of clang
> that defaults to DWARF5:
>
> $ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \
> LLVM=1 LLVM_IAS=0 O=build \
> mrproper allmodconfig mm/kfence/kfence_test.o
> /tmp/kfence_test-08a0a0.s: Assembler messages:
> /tmp/kfence_test-08a0a0.s:14627: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14628: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14632: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14633: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14639: Error: non-constant .uleb128 is not supported
> ...
>
> This is because `-g` defaults to the compiler debug info default. If the
> assembler does not support some of the directives used, the above errors
> occur. To fix, remove the explicit passing of `-g`.
>
> All these tests want is that stack traces print valid function names,
> and debug info is not required for that. I currently cannot recall why I
> added the explicit `-g`.
>
> Reported-by: Nathan Chancellor <[email protected]>
> Signed-off-by: Marco Elver <[email protected]>

Thanks for the quick patch!

Reviewed-by: Nathan Chancellor <[email protected]>

> ---
> kernel/kcsan/Makefile | 2 +-
> mm/kfence/Makefile | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/kcsan/Makefile b/kernel/kcsan/Makefile
> index 8cf70f068d92..a45f3dfc8d14 100644
> --- a/kernel/kcsan/Makefile
> +++ b/kernel/kcsan/Makefile
> @@ -16,6 +16,6 @@ obj-y := core.o debugfs.o report.o
> KCSAN_INSTRUMENT_BARRIERS_selftest.o := y
> obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
>
> -CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -g -fno-omit-frame-pointer
> +CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -fno-omit-frame-pointer
> CFLAGS_kcsan_test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
> obj-$(CONFIG_KCSAN_KUNIT_TEST) += kcsan_test.o
> diff --git a/mm/kfence/Makefile b/mm/kfence/Makefile
> index 0bb95728a784..2de2a58d11a1 100644
> --- a/mm/kfence/Makefile
> +++ b/mm/kfence/Makefile
> @@ -2,5 +2,5 @@
>
> obj-y := core.o report.o
>
> -CFLAGS_kfence_test.o := -g -fno-omit-frame-pointer -fno-optimize-sibling-calls
> +CFLAGS_kfence_test.o := -fno-omit-frame-pointer -fno-optimize-sibling-calls
> obj-$(CONFIG_KFENCE_KUNIT_TEST) += kfence_test.o
> --
> 2.40.0.rc1.284.g88254d51c5-goog
>

2023-03-16 22:34:05

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] kfence, kcsan: avoid passing -g for tests

On Thu, 16 Mar 2023 16:51:04 +0100 Marco Elver <[email protected]> wrote:

> Nathan reported that when building with GNU as and a version of clang
> that defaults to DWARF5:
>
> $ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \
> LLVM=1 LLVM_IAS=0 O=build \
> mrproper allmodconfig mm/kfence/kfence_test.o
> /tmp/kfence_test-08a0a0.s: Assembler messages:
> /tmp/kfence_test-08a0a0.s:14627: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14628: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14632: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14633: Error: non-constant .uleb128 is not supported
> /tmp/kfence_test-08a0a0.s:14639: Error: non-constant .uleb128 is not supported
> ...
>
> This is because `-g` defaults to the compiler debug info default. If the
> assembler does not support some of the directives used, the above errors
> occur. To fix, remove the explicit passing of `-g`.
>
> All these tests want is that stack traces print valid function names,
> and debug info is not required for that. I currently cannot recall why I
> added the explicit `-g`.

Does this need to be backported into earlier kernels?

If so, we'd need to do it as two patches, each with the relevant
Fixes:, which appear to be a146fed56f8 and bc8fbc5f30.


2023-03-16 22:49:11

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH] kfence, kcsan: avoid passing -g for tests

On Thu, 16 Mar 2023 at 23:33, Andrew Morton <[email protected]> wrote:
>
> On Thu, 16 Mar 2023 16:51:04 +0100 Marco Elver <[email protected]> wrote:
>
> > Nathan reported that when building with GNU as and a version of clang
> > that defaults to DWARF5:
> >
> > $ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- \
> > LLVM=1 LLVM_IAS=0 O=build \
> > mrproper allmodconfig mm/kfence/kfence_test.o
> > /tmp/kfence_test-08a0a0.s: Assembler messages:
> > /tmp/kfence_test-08a0a0.s:14627: Error: non-constant .uleb128 is not supported
> > /tmp/kfence_test-08a0a0.s:14628: Error: non-constant .uleb128 is not supported
> > /tmp/kfence_test-08a0a0.s:14632: Error: non-constant .uleb128 is not supported
> > /tmp/kfence_test-08a0a0.s:14633: Error: non-constant .uleb128 is not supported
> > /tmp/kfence_test-08a0a0.s:14639: Error: non-constant .uleb128 is not supported
> > ...
> >
> > This is because `-g` defaults to the compiler debug info default. If the
> > assembler does not support some of the directives used, the above errors
> > occur. To fix, remove the explicit passing of `-g`.
> >
> > All these tests want is that stack traces print valid function names,
> > and debug info is not required for that. I currently cannot recall why I
> > added the explicit `-g`.
>
> Does this need to be backported into earlier kernels?
>
> If so, we'd need to do it as two patches, each with the relevant
> Fixes:, which appear to be a146fed56f8 and bc8fbc5f30.

Good point - sent
https://lkml.kernel.org/r/[email protected]

Thanks,
-- Marco