On 12/01/2023 09:36, Amit Daniel Kachhap wrote:
This commit allows morello kselftest to be compiled from GCC toolchain. Also, Gcc toolchain complains for the missing memcpy function with -nostdlib linker option so a memcpy implementation is added.
Note: This commit requires CC to be set for Clang toolchain which was not earlier.
"not the case"?
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com
tools/testing/selftests/arm64/morello/Makefile | 12 +++++++----- tools/testing/selftests/arm64/morello/freestanding.c | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/arm64/morello/Makefile b/tools/testing/selftests/arm64/morello/Makefile index 7dbf5b140695..51e46838e345 100644 --- a/tools/testing/selftests/arm64/morello/Makefile +++ b/tools/testing/selftests/arm64/morello/Makefile @@ -1,16 +1,18 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2021 Arm Limited -# lib.mk sets CC. This switch triggers it to clang -LLVM := 1
+# Provide clang as CC otherwise defaults to gcc
This is unclear, maybe "Assume gcc by default"?
+ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) CLANG_FLAGS = --target=aarch64-linux-gnu
Looking more closely at lib.mk, it looks like it already adds both --target=... and -fintegrated-as to CC if LLVM=1 is set. Maybe we are just duplicating this mechanism needlessly by adding those flags to CFLAGS? The instructions to build the kselftests with Clang would then be to pass LLVM=1 to make.
+CFLAGS_CLANG = $(CLANG_FLAGS) -integrated-as +LDFLAGS_CLANG = -fuse-ld=lld +endif
CFLAGS_PURECAP = -march=morello+c64 -mabi=purecap CFLAGS_COMMON = -g -ffreestanding -Wall -Wextra -MMD CFLAGS_COMMON += -nostdinc -isystem $(shell $(CC) -print-file-name=include 2>/dev/null) -CFLAGS_CLANG = $(CLANG_FLAGS) -integrated-as CFLAGS += $(CFLAGS_CLANG) $(CFLAGS_PURECAP) $(CFLAGS_COMMON) -LDFLAGS := -fuse-ld=lld $(CLANG_FLAGS) -nostdlib -static +LDFLAGS := $(LDFLAGS_CLANG) $(CLANG_FLAGS) -nostdlib -static SRCS := $(wildcard *.c) $(wildcard *.S) PROGS := bootstrap clone exit mmap read_write sched signal diff --git a/tools/testing/selftests/arm64/morello/freestanding.c b/tools/testing/selftests/arm64/morello/freestanding.c index 45c0fa8b0914..81599201928d 100644 --- a/tools/testing/selftests/arm64/morello/freestanding.c +++ b/tools/testing/selftests/arm64/morello/freestanding.c @@ -185,3 +185,10 @@ int printf(const char *fmt, ...) return written; }
+void *memcpy(void *dest, const void *src, size_t n) +{
- for (size_t i = 0; i < n; i++)
((char *)dest)[i] = ((char *)src)[i];
- return dest;
+}
That's not good enough to preserve capabilities I'm afraid. We've got away without an memcpy() implementation so far (potentially relying on Clang providing its inline implementation), but if we do provide an implementation, it needs to be correct. Could we somehow reuse the code imported by "arm64: morello: Use the Morello optimized routine for memcpy"? Failing that, duplicating the implementation here would be acceptable. Either way this belongs to a separate patch.
Note that memmove() should also be implementing in a tag-preserving way (which can be the same as for memcpy(), like in the commit mentioned above), not sure why the linker complains only about memcpy().
Kevin