Linux-kselftest Archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: Fix asan linkage to work with clang
@ 2024-04-17 16:07 Ryan Roberts
  2024-04-19 16:47 ` Muhammad Usama Anjum
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Roberts @ 2024-04-17 16:07 UTC (permalink / raw
  To: Shuah Khan, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt
  Cc: Ryan Roberts, linux-kselftest, llvm, kernel test robot,
	Arnd Bergmann

Both fchmodat2 and openat2 statically link against libasan (for
explanation of why, look at the fixes commit). This is done using
`-static-libasan`. However, it turns out that clang uses a different
option, `-static-libsan`. This caused clang to fail to compile the
tests.

Fix this by using cc-option to figure out which variant to use.

While we are at it, stop passing helpers.h as a compilation unit. This
was causing another clang error due to name conflict with helpers.c's
object file. This header shouldn't be directly compiled anyway.

Fixes: c652df8a4a9d ("selftests: link libasan statically for tests with -fsanitize=address")
Reported-by: kernel test robot <yujie.liu@intel.com>
Closes: https://lore.kernel.org/r/202404141807.LgsqXPY5-lkp@intel.com/
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---

Applies on v6.9-rc4.

Thanks,
Ryan

 tools/testing/selftests/fchmodat2/Makefile | 5 ++++-
 tools/testing/selftests/openat2/Makefile   | 7 +++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/fchmodat2/Makefile b/tools/testing/selftests/fchmodat2/Makefile
index 71ec34bf1501..a68bb5a00797 100644
--- a/tools/testing/selftests/fchmodat2/Makefile
+++ b/tools/testing/selftests/fchmodat2/Makefile
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
+# We need this for the "cc-option" macro.
+include ../../../build/Build.include

-CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan $(KHDR_INCLUDES)
+CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined $(KHDR_INCLUDES)
+CFLAGS += $(call cc-option, -static-libasan) $(call cc-option, -static-libsan)
 TEST_GEN_PROGS := fchmodat2_test

 include ../lib.mk
diff --git a/tools/testing/selftests/openat2/Makefile b/tools/testing/selftests/openat2/Makefile
index 254d676a2689..02af9b6ca5eb 100644
--- a/tools/testing/selftests/openat2/Makefile
+++ b/tools/testing/selftests/openat2/Makefile
@@ -1,8 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
+# We need this for the "cc-option" macro.
+include ../../../build/Build.include

-CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan
+CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined
+CFLAGS += $(call cc-option, -static-libasan) $(call cc-option, -static-libsan)
 TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test

 include ../lib.mk

-$(TEST_GEN_PROGS): helpers.c helpers.h
+$(TEST_GEN_PROGS): helpers.c
--
2.25.1


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

* Re: [PATCH] selftests: Fix asan linkage to work with clang
  2024-04-17 16:07 [PATCH] selftests: Fix asan linkage to work with clang Ryan Roberts
@ 2024-04-19 16:47 ` Muhammad Usama Anjum
  0 siblings, 0 replies; 2+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-19 16:47 UTC (permalink / raw
  To: Ryan Roberts, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt
  Cc: Muhammad Usama Anjum, linux-kselftest, llvm, kernel test robot,
	Arnd Bergmann

Thanks for the fix.

On 4/17/24 9:07 PM, Ryan Roberts wrote:
> Both fchmodat2 and openat2 statically link against libasan (for
> explanation of why, look at the fixes commit). This is done using
> `-static-libasan`. However, it turns out that clang uses a different
> option, `-static-libsan`. This caused clang to fail to compile the
> tests.
> 
> Fix this by using cc-option to figure out which variant to use.
> 
> While we are at it, stop passing helpers.h as a compilation unit. This
> was causing another clang error due to name conflict with helpers.c's
> object file. This header shouldn't be directly compiled anyway.
> 
> Fixes: c652df8a4a9d ("selftests: link libasan statically for tests with -fsanitize=address")
> Reported-by: kernel test robot <yujie.liu@intel.com>
> Closes: https://lore.kernel.org/r/202404141807.LgsqXPY5-lkp@intel.com/
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
> 
> Applies on v6.9-rc4.
> 
> Thanks,
> Ryan
> 
>  tools/testing/selftests/fchmodat2/Makefile | 5 ++++-
>  tools/testing/selftests/openat2/Makefile   | 7 +++++--
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/fchmodat2/Makefile b/tools/testing/selftests/fchmodat2/Makefile
> index 71ec34bf1501..a68bb5a00797 100644
> --- a/tools/testing/selftests/fchmodat2/Makefile
> +++ b/tools/testing/selftests/fchmodat2/Makefile
> @@ -1,6 +1,9 @@
>  # SPDX-License-Identifier: GPL-2.0-or-later
> +# We need this for the "cc-option" macro.
> +include ../../../build/Build.include
> 
> -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan $(KHDR_INCLUDES)
> +CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined $(KHDR_INCLUDES)
> +CFLAGS += $(call cc-option, -static-libasan) $(call cc-option, -static-libsan)
>  TEST_GEN_PROGS := fchmodat2_test
> 
>  include ../lib.mk
> diff --git a/tools/testing/selftests/openat2/Makefile b/tools/testing/selftests/openat2/Makefile
> index 254d676a2689..02af9b6ca5eb 100644
> --- a/tools/testing/selftests/openat2/Makefile
> +++ b/tools/testing/selftests/openat2/Makefile
> @@ -1,8 +1,11 @@
>  # SPDX-License-Identifier: GPL-2.0-or-later
> +# We need this for the "cc-option" macro.
> +include ../../../build/Build.include
> 
> -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan
> +CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined
> +CFLAGS += $(call cc-option, -static-libasan) $(call cc-option, -static-libsan)
>  TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test
> 
>  include ../lib.mk
> 
> -$(TEST_GEN_PROGS): helpers.c helpers.h
> +$(TEST_GEN_PROGS): helpers.c
> --
> 2.25.1
> 
> 

-- 
BR,
Muhammad Usama Anjum

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

end of thread, other threads:[~2024-04-19 16:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-17 16:07 [PATCH] selftests: Fix asan linkage to work with clang Ryan Roberts
2024-04-19 16:47 ` Muhammad Usama Anjum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).