Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1530629

[PATCH v3 08/30] tools build: Add feature detection for clang

From Wang Nan <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject [PATCH v3 08/30] tools build: Add feature detection for clang
Date 2016-11-26 08:20 +0100
Message-ID <sHFrc-3qJ-29@gated-at.bofh.it> (permalink)
References <sHFhv-3nx-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Check if basic clang compiling environment is ready.

Doesn't like 'llvm-config --libs' which can returns llvm libraries in
right order and duplicates some libraries if necessary, there's no
correspondence for clang libraries (-lclangxxx). to avoid extra
complexity and to avoid new clang breaking libraries ordering, use
--start-group and --end-group.

In this test case, manually identify required clang libs and hope it to
be stable. Putting all clang libraries here is possible (use make's
wildcard), but then feature checking becomes very slow.

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: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1474874832-134786-5-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/build/feature/Makefile       | 10 ++++++++++
 tools/build/feature/test-clang.cpp | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 tools/build/feature/test-clang.cpp

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index c09de59..871d553 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -237,6 +237,16 @@ $(OUTPUT)test-llvm.bin:
 		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
 		$(shell $(LLVM_CONFIG) --system-libs)
 
+$(OUTPUT)test-clang.bin:
+	$(BUILDXX) -std=gnu++11 					\
+		-I$(shell $(LLVM_CONFIG) --includedir) 		\
+		-L$(shell $(LLVM_CONFIG) --libdir)		\
+		-Wl,--start-group -lclangBasic -lclangDriver	\
+		  -lclangFrontend -lclangEdit -lclangLex	\
+		  -lclangAST -Wl,--end-group 			\
+		$(shell $(LLVM_CONFIG) --libs Core option)	\
+		$(shell $(LLVM_CONFIG) --system-libs)
+
 -include $(OUTPUT)*.d
 
 ###############################
diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp
new file mode 100644
index 0000000..e23c1b1
--- /dev/null
+++ b/tools/build/feature/test-clang.cpp
@@ -0,0 +1,21 @@
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+using namespace clang::driver;
+
+int main()
+{
+	IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+	IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
+
+	DiagnosticsEngine Diags(DiagID, &*DiagOpts);
+	Driver TheDriver("test", "bpf-pc-linux", Diags);
+
+	llvm::llvm_shutdown();
+	return 0;
+}
-- 
2.10.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/30] perf clang: Builtin clang and perfhook support Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
  [PATCH v3 08/30] tools build: Add feature detection for clang Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] tools build: Add feature detection for clang tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:30 +0100
  [PATCH v3 11/30] perf clang: Use real file system for #include Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] perf clang: Use real file system for #include tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:30 +0100
  [PATCH v3 15/30] perf clang: Compile BPF script use builtin clang support Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] perf clang: Compile BPF script using builtin clang  support tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:50 +0100
  [PATCH v3 03/30] tools lib bpf: Retrive bpf_map through offset of bpf_map_def Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    Re: [PATCH v3 03/30] tools lib bpf: Retrive bpf_map through offset  of bpf_map_def Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-11-26 18:20 +0100
    [tip:perf/core] tools lib bpf: Retrive bpf_map through offset of  bpf_map_def tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-02 11:40 +0100

csiph-web