diff options
author | Sandipan Das <sandipan@linux.vnet.ibm.com> | 2018-04-04 14:04:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-04-09 10:13:08 -0400 |
commit | 7854e499f33fd9c7e63288692ffb754d9b1d02fd (patch) | |
tree | 6750f7f75a43862c60fc3e9f8c305127084ccf59 /tools/perf/util/c++/clang.cpp | |
parent | c2fb54a183cfe77c6fdc9d71e2d5299c1c302a6e (diff) |
perf clang: Add support for recent clang versions
The clang API calls used by perf have changed in recent releases and
builds succeed with libclang-3.9 only. This introduces compatibility
with libclang-4.0 and above.
Without this patch, we will see the following compilation errors with
libclang-4.0+:
util/c++/clang.cpp: In function ‘clang::CompilerInvocation* perf::createCompilerInvocation(llvm::opt::ArgStringList, llvm::StringRef&, clang::DiagnosticsEngine&)’:
util/c++/clang.cpp:62:33: error: ‘IK_C’ was not declared in this scope
Opts.Inputs.emplace_back(Path, IK_C);
^~~~
util/c++/clang.cpp: In function ‘std::unique_ptr<llvm::Module> perf::getModuleFromSource(llvm::opt::ArgStringList, llvm::StringRef, llvm::IntrusiveRefCntPtr<clang::vfs::FileSystem>)’:
util/c++/clang.cpp:75:26: error: no matching function for call to ‘clang::CompilerInstance::setInvocation(clang::CompilerInvocation*)’
Clang.setInvocation(&*CI);
^
In file included from util/c++/clang.cpp:14:0:
/usr/include/clang/Frontend/CompilerInstance.h:231:8: note: candidate: void clang::CompilerInstance::setInvocation(std::shared_ptr<clang::CompilerInvocation>)
void setInvocation(std::shared_ptr<CompilerInvocation> Value);
^~~~~~~~~~~~~
Committer testing:
Tested on Fedora 27 after installing the clang-devel and llvm-devel
packages, versions:
# rpm -qa | egrep llvm\|clang
llvm-5.0.1-6.fc27.x86_64
clang-libs-5.0.1-5.fc27.x86_64
clang-5.0.1-5.fc27.x86_64
clang-tools-extra-5.0.1-5.fc27.x86_64
llvm-libs-5.0.1-6.fc27.x86_64
llvm-devel-5.0.1-6.fc27.x86_64
clang-devel-5.0.1-5.fc27.x86_64
#
Make sure you don't have some older version lying around in /usr/local,
etc, then:
$ make LIBCLANGLLVM=1 -C tools/perf install-bin
And in the end perf will be linked agains these libraries:
# ldd ~/bin/perf | egrep -i llvm\|clang
libclangAST.so.5 => /lib64/libclangAST.so.5 (0x00007f8bb2eb4000)
libclangBasic.so.5 => /lib64/libclangBasic.so.5 (0x00007f8bb29e3000)
libclangCodeGen.so.5 => /lib64/libclangCodeGen.so.5 (0x00007f8bb23f7000)
libclangDriver.so.5 => /lib64/libclangDriver.so.5 (0x00007f8bb2060000)
libclangFrontend.so.5 => /lib64/libclangFrontend.so.5 (0x00007f8bb1d06000)
libclangLex.so.5 => /lib64/libclangLex.so.5 (0x00007f8bb1a3e000)
libclangTooling.so.5 => /lib64/libclangTooling.so.5 (0x00007f8bb17d4000)
libclangEdit.so.5 => /lib64/libclangEdit.so.5 (0x00007f8bb15c5000)
libclangSema.so.5 => /lib64/libclangSema.so.5 (0x00007f8bb0cc9000)
libclangAnalysis.so.5 => /lib64/libclangAnalysis.so.5 (0x00007f8bb0a23000)
libclangParse.so.5 => /lib64/libclangParse.so.5 (0x00007f8bb0725000)
libclangSerialization.so.5 => /lib64/libclangSerialization.so.5 (0x00007f8bb039a000)
libLLVM-5.0.so => /lib64/libLLVM-5.0.so (0x00007f8bace98000)
libclangASTMatchers.so.5 => /lib64/../lib64/libclangASTMatchers.so.5 (0x00007f8bab735000)
libclangFormat.so.5 => /lib64/../lib64/libclangFormat.so.5 (0x00007f8bab4b2000)
libclangRewrite.so.5 => /lib64/../lib64/libclangRewrite.so.5 (0x00007f8bab2a1000)
libclangToolingCore.so.5 => /lib64/../lib64/libclangToolingCore.so.5 (0x00007f8bab08e000)
#
Signed-off-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Fixes: 00b86691c77c ("perf clang: Add builtin clang support ant test case")
Link: http://lkml.kernel.org/r/20180404180419.19056-2-sandipan@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/c++/clang.cpp')
-rw-r--r-- | tools/perf/util/c++/clang.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp index 1bfc946e37dc..bf31ceab33bd 100644 --- a/tools/perf/util/c++/clang.cpp +++ b/tools/perf/util/c++/clang.cpp | |||
@@ -9,6 +9,7 @@ | |||
9 | * Copyright (C) 2016 Huawei Inc. | 9 | * Copyright (C) 2016 Huawei Inc. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include "clang/Basic/Version.h" | ||
12 | #include "clang/CodeGen/CodeGenAction.h" | 13 | #include "clang/CodeGen/CodeGenAction.h" |
13 | #include "clang/Frontend/CompilerInvocation.h" | 14 | #include "clang/Frontend/CompilerInvocation.h" |
14 | #include "clang/Frontend/CompilerInstance.h" | 15 | #include "clang/Frontend/CompilerInstance.h" |
@@ -58,7 +59,8 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path, | |||
58 | 59 | ||
59 | FrontendOptions& Opts = CI->getFrontendOpts(); | 60 | FrontendOptions& Opts = CI->getFrontendOpts(); |
60 | Opts.Inputs.clear(); | 61 | Opts.Inputs.clear(); |
61 | Opts.Inputs.emplace_back(Path, IK_C); | 62 | Opts.Inputs.emplace_back(Path, |
63 | FrontendOptions::getInputKindForExtension("c")); | ||
62 | return CI; | 64 | return CI; |
63 | } | 65 | } |
64 | 66 | ||
@@ -71,10 +73,17 @@ getModuleFromSource(llvm::opt::ArgStringList CFlags, | |||
71 | 73 | ||
72 | Clang.setVirtualFileSystem(&*VFS); | 74 | Clang.setVirtualFileSystem(&*VFS); |
73 | 75 | ||
76 | #if CLANG_VERSION_MAJOR < 4 | ||
74 | IntrusiveRefCntPtr<CompilerInvocation> CI = | 77 | IntrusiveRefCntPtr<CompilerInvocation> CI = |
75 | createCompilerInvocation(std::move(CFlags), Path, | 78 | createCompilerInvocation(std::move(CFlags), Path, |
76 | Clang.getDiagnostics()); | 79 | Clang.getDiagnostics()); |
77 | Clang.setInvocation(&*CI); | 80 | Clang.setInvocation(&*CI); |
81 | #else | ||
82 | std::shared_ptr<CompilerInvocation> CI( | ||
83 | createCompilerInvocation(std::move(CFlags), Path, | ||
84 | Clang.getDiagnostics())); | ||
85 | Clang.setInvocation(CI); | ||
86 | #endif | ||
78 | 87 | ||
79 | std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx)); | 88 | std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx)); |
80 | if (!Clang.ExecuteAction(*Act)) | 89 | if (!Clang.ExecuteAction(*Act)) |