Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf build: Add clang and llvm compile and linking support

Add necessary c++ flags and link libraries to support builtin clang and
LLVM. Add all llvm and clang libraries, so don't need to worry about
clang changes its libraries setting. However, linking perf would take
much longer than usual.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Joe Stringer <joe@ovn.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/20161126070354.141764-10-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
d58ac0bf c7fb4f62

+59 -1
+35
tools/perf/Makefile.config
··· 136 136 # Treat warnings as errors unless directed not to 137 137 ifneq ($(WERROR),0) 138 138 CFLAGS += -Werror 139 + CXXFLAGS += -Werror 139 140 endif 140 141 141 142 ifndef DEBUG ··· 182 181 CFLAGS += -Wall 183 182 CFLAGS += -Wextra 184 183 CFLAGS += -std=gnu99 184 + 185 + CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti 186 + CXXFLAGS += -Wall 187 + CXXFLAGS += -fno-omit-frame-pointer 188 + CXXFLAGS += -ggdb3 189 + CXXFLAGS += -funwind-tables 190 + CXXFLAGS += -Wno-strict-aliasing 185 191 186 192 # Enforce a non-executable stack, as we may regress (again) in the future by 187 193 # adding assembler files missing the .GNU-stack linker note. ··· 788 780 else 789 781 $(warning No openjdk development package found, please install JDK package) 790 782 NO_JVMTI := 1 783 + endif 784 + endif 785 + 786 + USE_CXX = 0 787 + USE_CLANGLLVM = 0 788 + ifdef LIBCLANGLLVM 789 + $(call feature_check,cxx) 790 + ifneq ($(feature-cxx), 1) 791 + msg := $(warning No g++ found, disable clang and llvm support. Please install g++) 792 + else 793 + $(call feature_check,llvm) 794 + ifneq ($(feature-llvm), 1) 795 + msg := $(warning No libLLVM found, disable clang and llvm support. Please install llvm-dev) 796 + else 797 + $(call feature_check,clang) 798 + ifneq ($(feature-clang), 1) 799 + msg := $(warning No libclang found, disable clang and llvm support. Please install libclang-dev) 800 + else 801 + CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT 802 + CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir) 803 + $(call detected,CONFIG_CXX) 804 + $(call detected,CONFIG_CLANGLLVM) 805 + USE_CXX = 1 806 + USE_LLVM = 1 807 + USE_CLANG = 1 808 + endif 809 + endif 791 810 endif 792 811 endif 793 812
+22 -1
tools/perf/Makefile.perf
··· 88 88 # and bypass the feature detection 89 89 # 90 90 # Define NO_JVMTI if you do not want jvmti agent built 91 + # 92 + # Define LIBCLANGLLVM if you DO want builtin clang and llvm support. 93 + # When selected, pass LLVM_CONFIG=/path/to/llvm-config to `make' if 94 + # llvm-config is not in $PATH. 91 95 92 96 # As per kernel Makefile, avoid funny character set dependencies 93 97 unexport LC_ALL ··· 147 143 $(call allow-override,CC,$(CROSS_COMPILE)gcc) 148 144 $(call allow-override,AR,$(CROSS_COMPILE)ar) 149 145 $(call allow-override,LD,$(CROSS_COMPILE)ld) 146 + $(call allow-override,CXX,$(CROSS_COMPILE)g++) 150 147 151 148 LD += $(EXTRA_LDFLAGS) 152 149 ··· 156 151 HOSTAR ?= ar 157 152 158 153 PKG_CONFIG = $(CROSS_COMPILE)pkg-config 154 + LLVM_CONFIG ?= llvm-config 159 155 160 156 RM = rm -f 161 157 LN = ln -f ··· 344 338 345 339 LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group 346 340 341 + ifeq ($(USE_CLANG), 1) 342 + CLANGLIBS_LIST = AST Basic CodeGen Driver Frontend Lex Tooling Edit Sema Analysis Parse Serialization 343 + LIBCLANG = $(foreach l,$(CLANGLIBS_LIST),$(wildcard $(shell $(LLVM_CONFIG) --libdir)/libclang$(l).a)) 344 + LIBS += -Wl,--start-group $(LIBCLANG) -Wl,--end-group 345 + endif 346 + 347 + ifeq ($(USE_LLVM), 1) 348 + LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) 349 + LIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) 350 + endif 351 + 352 + ifeq ($(USE_CXX), 1) 353 + LIBS += -lstdc++ 354 + endif 355 + 347 356 export INSTALL SHELL_PATH 348 357 349 358 ### Build rules ··· 377 356 378 357 PERF_IN := $(OUTPUT)perf-in.o 379 358 380 - export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK 359 + export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK 381 360 export HOSTCC HOSTLD HOSTAR 382 361 include $(srctree)/tools/build/Makefile.include 383 362
+2
tools/perf/tests/make
··· 83 83 make_no_libcrypto := NO_LIBCRYPTO=1 84 84 make_with_babeltrace:= LIBBABELTRACE=1 85 85 make_no_sdt := NO_SDT=1 86 + make_with_clangllvm := LIBCLANGLLVM=1 86 87 make_tags := tags 87 88 make_cscope := cscope 88 89 make_help := help ··· 140 139 run += make_no_auxtrace 141 140 run += make_no_libbpf 142 141 run += make_with_babeltrace 142 + run += make_with_clangllvm 143 143 run += make_help 144 144 run += make_doc 145 145 run += make_perf_o