On 4/13/21 3:13 PM, Nick Desaulniers wrote:
On Tue, Apr 13, 2021 at 3:05 PM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
On Tue, Apr 13, 2021 at 8:34 AM Yonghong Song <yhs@xxxxxx> wrote:
selftests/bpf/Makefile includes lib.mk. With the following command
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1 V=1
some files are still compiled with gcc. This patch
fixed lib.mk issue which sets CC to gcc in all cases.
Cc: Sedat Dilek <sedat.dilek@xxxxxxxxx>
Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
tools/testing/selftests/lib.mk | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index a5ce26d548e4..9a41d8bb9ff1 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -1,6 +1,10 @@
# This mimics the top-level Makefile. We do it explicitly here so that this
# Makefile can operate with or without the kbuild infrastructure.
+ifneq ($(LLVM),)
+CC := clang
Does this mean that cross-compilation with Clang doesn't work at all
or is achieved in some other way?
Right, this probably doesn't support cross compilation w/ Clang.
Rather than invoke `$(CROSS_COMPILE) clang`, you'd do `clang
--target=$(CROSS_COMPILE)`. Even then, cross linking executables is
hairy. But at least this should enable native compilation, which is a
start.
See https://clang.llvm.org/docs/CrossCompilation.html.
As Nick said, clang prefers --target=$(CROSS_COMPILE) to
indicate cross compilation. User can pass additional
flags (CFLAGS) for cross compilation for the time being.
This is the same as main kernel Makefile.
ifneq ($(LLVM),)
CC = clang
LD = ld.lld
AR = llvm-ar
NM = llvm-nm
OBJCOPY = llvm-objcopy
OBJDUMP = llvm-objdump
READELF = llvm-readelf
STRIP = llvm-strip
else
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
READELF = $(CROSS_COMPILE)readelf
STRIP = $(CROSS_COMPILE)strip
endif
+else
CC := $(CROSS_COMPILE)gcc
+endif
ifeq (0,$(MAKELEVEL))
ifeq ($(OUTPUT),)
--
2.30.2