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

perf build: Check LLVM version in feature check

Cancel builtin llvm and clang support when LLVM version is less than
3.9.0: following commits uses newer API.

Since Clang/LLVM's API is not guaranteed to be stable, add a
test-llvm-version.cpp feature checker, issue warning if LLVM found in
compiling environment is not tested yet.

Committer Notes:

Testing it:

Environment:

$ cat /etc/fedora-release
Fedora release 25 (Twenty Five)
$ rpm -q llvm-devel clang-devel
llvm-devel-3.8.0-1.fc25.x86_64
clang-devel-3.8.0-2.fc25.x86_64
$

Before:

$ make -k LIBCLANGLLVM=1 O=/tmp/build/perf -C tools/perf install-bin
make: Entering directory '/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j4' parallel build
Warning: tools/include/uapi/linux/bpf.h differs from kernel
Warning: tools/arch/arm/include/uapi/asm/kvm.h differs from kernel
INSTALL GTK UI
LINK /tmp/build/perf/perf
/tmp/build/perf/libperf.a(libperf-in.o): In function `perf::createCompilerInvocation(llvm::SmallVector<char const*, 16u>, llvm::StringRef&, clang::DiagnosticsEngine&)':
/home/acme/git/linux/tools/perf/util/c++/clang.cpp:56: undefined reference to `clang::tooling::newInvocation(clang::DiagnosticsEngine*, llvm::SmallVector<char const*, 16u> const&)'
/tmp/build/perf/libperf.a(libperf-in.o): In function `perf::getModuleFromSource(llvm::SmallVector<char const*, 16u>, llvm::StringRef, llvm::IntrusiveRefCntPtr<clang::vfs::FileSystem>)':
/home/acme/git/linux/tools/perf/util/c++/clang.cpp:68: undefined reference to `clang::CompilerInstance::CompilerInstance(std::shared_ptr<clang::PCHContainerOperations>, bool)'
/home/acme/git/linux/tools/perf/util/c++/clang.cpp:69: undefined reference to `clang::CompilerInstance::createDiagnostics(clang::DiagnosticConsumer*, bool)'
<SNIP>

After:

Makefile.config:807: No suitable libLLVM found, disabling builtin clang and llvm support. Please install llvm-dev(el) (>= 3.9.0)

Updating the environment to a locally built LLVM 4.0 + clang 3.9 (forgot
to git pull, duh) combo, all works as expected, it is properly detected
and built into the resulting perf binary.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Reported-and-Tested-by: Arnaldo Carvalho de Melo <acme@redhat.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/20161206072230.7651-1-wangnan0@huawei.com
[ Change the warning message a bit (add 'suitable' and 'builtin'), clarifying it, see committer notes above ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
a940cad3 34c4a427

+28 -4
+6 -2
tools/build/feature/Makefile
··· 231 231 $(BUILD) 232 232 233 233 $(OUTPUT)test-llvm.bin: 234 - $(BUILDXX) -std=gnu++11 \ 234 + $(BUILDXX) -std=gnu++11 \ 235 235 -I$(shell $(LLVM_CONFIG) --includedir) \ 236 236 -L$(shell $(LLVM_CONFIG) --libdir) \ 237 237 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 238 238 $(shell $(LLVM_CONFIG) --system-libs) 239 239 240 + $(OUTPUT)test-llvm-version.bin: 241 + $(BUILDXX) -std=gnu++11 \ 242 + -I$(shell $(LLVM_CONFIG) --includedir) 243 + 240 244 $(OUTPUT)test-clang.bin: 241 - $(BUILDXX) -std=gnu++11 \ 245 + $(BUILDXX) -std=gnu++11 \ 242 246 -I$(shell $(LLVM_CONFIG) --includedir) \ 243 247 -L$(shell $(LLVM_CONFIG) --libdir) \ 244 248 -Wl,--start-group -lclangBasic -lclangDriver \
+11
tools/build/feature/test-llvm-version.cpp
··· 1 + #include <cstdio> 2 + #include "llvm/Config/llvm-config.h" 3 + 4 + #define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH) 5 + #define pass int main() {printf("%x\n", NUM_VERSION); return 0;} 6 + 7 + #if NUM_VERSION >= 0x030900 8 + pass 9 + #else 10 + # error This LLVM is not tested yet. 11 + #endif
+5
tools/build/feature/test-llvm.cpp
··· 1 1 #include "llvm/Support/ManagedStatic.h" 2 2 #include "llvm/Support/raw_ostream.h" 3 + #define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH) 4 + 5 + #if NUM_VERSION < 0x030900 6 + # error "LLVM version too low" 7 + #endif 3 8 int main() 4 9 { 5 10 llvm::errs() << "Hello World!\n";
+6 -2
tools/perf/Makefile.config
··· 802 802 msg := $(warning No g++ found, disable clang and llvm support. Please install g++) 803 803 else 804 804 $(call feature_check,llvm) 805 + $(call feature_check,llvm-version) 805 806 ifneq ($(feature-llvm), 1) 806 - msg := $(warning No libLLVM found, disable clang and llvm support. Please install llvm-dev) 807 + msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0)) 807 808 else 808 809 $(call feature_check,clang) 809 810 ifneq ($(feature-clang), 1) 810 - msg := $(warning No libclang found, disable clang and llvm support. Please install libclang-dev) 811 + msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0)) 811 812 else 812 813 CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT 813 814 CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir) ··· 817 816 USE_CXX = 1 818 817 USE_LLVM = 1 819 818 USE_CLANG = 1 819 + ifneq ($(feature-llvm-version),1) 820 + msg := $(warning This version of LLVM is not tested. May cause build errors) 821 + endif 820 822 endif 821 823 endif 822 824 endif