Skip to content

Commit 46c4a02

Browse files
Leo-YanKernel Patches Daemon
authored andcommitted
perf build: Support build with clang
Add support for building perf with clang. For cross compilation, the Makefile dynamically selects target flag for corresponding arch. This patch has been verified on x86_64 machine with Ubuntu distro, it can build successfully for native target, and for cross building Arm64 and s390. Example: native build on x86_64 / Ubuntu machine: $ HOSTCC=clang CC=clang CXX=clang++ make -C tools/perf Example: cross building s390 target on x86_64 / Ubuntu machine: # Install x390x cross toolchain and headers $ sudo apt-get install gcc-s390x-linux-gnu g++-s390x-linux-gnu \ libc6-dev-s390x-cross linux-libc-dev-s390x-cross # Build with clang $ HOSTCC=clang CC=clang CXX=clang++ \ ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- \ make -C tools/perf NO_LIBELF=1 NO_LIBTRACEEVENT=1 NO_LIBPYTHON=1 Signed-off-by: Leo Yan <[email protected]>
1 parent 4430f41 commit 46c4a02

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tools/perf/Makefile.config

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,38 @@ HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
2323
# borrowed from kernel headers depends on it, e.g. put_unaligned_*().
2424
CFLAGS += -fno-strict-aliasing
2525

26-
# Enabled Wthread-safety analysis for clang builds.
26+
# Set target flag and options when using clang as compiler.
2727
ifeq ($(CC_NO_CLANG), 0)
28+
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
29+
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
30+
CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
31+
CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
32+
CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
33+
CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
34+
CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
35+
CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
36+
37+
# Default to host architecture if ARCH is not explicitly given.
38+
ifeq ($(ARCH),)
39+
CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple)
40+
else
41+
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
42+
endif
43+
44+
ifeq ($(CROSS_COMPILE),)
45+
ifeq ($(CLANG_TARGET_FLAGS),)
46+
$(error Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for $(ARCH))
47+
else
48+
CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
49+
endif # CLANG_TARGET_FLAGS
50+
else
51+
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
52+
endif # CROSS_COMPILE
53+
54+
CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
55+
CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
56+
57+
# Enabled Wthread-safety analysis for clang builds.
2858
CFLAGS += -Wthread-safety
2959
endif
3060

0 commit comments

Comments
 (0)