Skip to content

Commit d58ac0b

Browse files
WangNan0acmel
authored andcommitted
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>
1 parent c7fb4f6 commit d58ac0b

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎tools/perf/Makefile.config‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ endif
136136
# Treat warnings as errors unless directed not to
137137
ifneq ($(WERROR),0)
138138
CFLAGS += -Werror
139+
CXXFLAGS += -Werror
139140
endif
140141

141142
ifndef DEBUG
@@ -182,6 +183,13 @@ CFLAGS += -Wall
182183
CFLAGS += -Wextra
183184
CFLAGS += -std=gnu99
184185

186+
CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
187+
CXXFLAGS += -Wall
188+
CXXFLAGS += -fno-omit-frame-pointer
189+
CXXFLAGS += -ggdb3
190+
CXXFLAGS += -funwind-tables
191+
CXXFLAGS += -Wno-strict-aliasing
192+
185193
# Enforce a non-executable stack, as we may regress (again) in the future by
186194
# adding assembler files missing the .GNU-stack linker note.
187195
LDFLAGS += -Wl,-z,noexecstack
@@ -783,6 +791,33 @@ ifndef NO_JVMTI
783791
endif
784792
endif
785793

794+
USE_CXX = 0
795+
USE_CLANGLLVM = 0
796+
ifdef LIBCLANGLLVM
797+
$(call feature_check,cxx)
798+
ifneq ($(feature-cxx), 1)
799+
msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
800+
else
801+
$(call feature_check,llvm)
802+
ifneq ($(feature-llvm), 1)
803+
msg := $(warning No libLLVM found, disable clang and llvm support. Please install llvm-dev)
804+
else
805+
$(call feature_check,clang)
806+
ifneq ($(feature-clang), 1)
807+
msg := $(warning No libclang found, disable clang and llvm support. Please install libclang-dev)
808+
else
809+
CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
810+
CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
811+
$(call detected,CONFIG_CXX)
812+
$(call detected,CONFIG_CLANGLLVM)
813+
USE_CXX = 1
814+
USE_LLVM = 1
815+
USE_CLANG = 1
816+
endif
817+
endif
818+
endif
819+
endif
820+
786821
# Among the variables below, these:
787822
# perfexecdir
788823
# template_dir

‎tools/perf/Makefile.perf‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ include ../scripts/utilities.mak
8888
# and bypass the feature detection
8989
#
9090
# 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.
9195

9296
# As per kernel Makefile, avoid funny character set dependencies
9397
unexport LC_ALL
@@ -143,6 +147,7 @@ endef
143147
$(call allow-override,CC,$(CROSS_COMPILE)gcc)
144148
$(call allow-override,AR,$(CROSS_COMPILE)ar)
145149
$(call allow-override,LD,$(CROSS_COMPILE)ld)
150+
$(call allow-override,CXX,$(CROSS_COMPILE)g++)
146151

147152
LD += $(EXTRA_LDFLAGS)
148153

@@ -151,6 +156,7 @@ HOSTLD ?= ld
151156
HOSTAR ?= ar
152157

153158
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
159+
LLVM_CONFIG ?= llvm-config
154160

155161
RM = rm -f
156162
LN = ln -f
@@ -338,6 +344,21 @@ endif
338344

339345
LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
340346

347+
ifeq ($(USE_CLANG), 1)
348+
CLANGLIBS_LIST = AST Basic CodeGen Driver Frontend Lex Tooling Edit Sema Analysis Parse Serialization
349+
LIBCLANG = $(foreach l,$(CLANGLIBS_LIST),$(wildcard $(shell $(LLVM_CONFIG) --libdir)/libclang$(l).a))
350+
LIBS += -Wl,--start-group $(LIBCLANG) -Wl,--end-group
351+
endif
352+
353+
ifeq ($(USE_LLVM), 1)
354+
LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
355+
LIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
356+
endif
357+
358+
ifeq ($(USE_CXX), 1)
359+
LIBS += -lstdc++
360+
endif
361+
341362
export INSTALL SHELL_PATH
342363

343364
### Build rules
@@ -356,7 +377,7 @@ strip: $(PROGRAMS) $(OUTPUT)perf
356377

357378
PERF_IN := $(OUTPUT)perf-in.o
358379

359-
export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK
380+
export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK
360381
export HOSTCC HOSTLD HOSTAR
361382
include $(srctree)/tools/build/Makefile.include
362383

‎tools/perf/tests/make‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ make_no_libbpf := NO_LIBBPF=1
8383
make_no_libcrypto := NO_LIBCRYPTO=1
8484
make_with_babeltrace:= LIBBABELTRACE=1
8585
make_no_sdt := NO_SDT=1
86+
make_with_clangllvm := LIBCLANGLLVM=1
8687
make_tags := tags
8788
make_cscope := cscope
8889
make_help := help
@@ -139,6 +140,7 @@ run += make_no_libbionic
139140
run += make_no_auxtrace
140141
run += make_no_libbpf
141142
run += make_with_babeltrace
143+
run += make_with_clangllvm
142144
run += make_help
143145
run += make_doc
144146
run += make_perf_o

0 commit comments

Comments
 (0)