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


Groups > linux.kernel > #1535809

Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test case

From "Wangnan (F)" <wangnan0@huawei.com>
Newsgroups linux.kernel
Subject Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test case
Date 2016-12-05 05:50 +0100
Message-ID <sKTnY-8bT-1@gated-at.bofh.it> (permalink)
References <sHFhv-3nx-5@gated-at.bofh.it> <sHFrb-3qJ-9@gated-at.bofh.it> <sJYg1-5Hd-13@gated-at.bofh.it> <sKRm9-6Su-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 2016/12/5 10:36, Wangnan (F) wrote:
>
>
> On 2016/12/2 23:44, Arnaldo Carvalho de Melo wrote:
>> Em Sat, Nov 26, 2016 at 07:03:34AM +0000, Wang Nan escreveu:
>>> Add basic clang support in clang.cpp and test__clang() testcase. The
>>> first testcase checks if builtin clang is able to generate LLVM IR.
>>>
>>> tests/clang.c is a proxy. Real testcase resides in
>>> utils/c++/clang-test.cpp in c++ and exports C interface to perf test
>>> subsystem.
>>>
>>> Test result:
>>>
>>>     $ perf test -v clang
>>>     51: Test builtin clang support                               :
>>>     51.1: Test builtin clang compile C source to IR              :
>>>     --- start ---
>>>     test child forked, pid 13215
>>>     test child finished with 0
>>>     ---- end ----
>>>     Test builtin clang support subtest 0: Ok
>> While testing this I noticed that the perf binary got huge, can't this
>> be done in some other way, i.e. using dynamic library?
>
> I intentionally use statically linking because it is good for
> smartphone: we can simply 'adb push' a statically linked perf
> to Android.
>
> The resulting ELF executable would be even larger if LLVM is
> built with default setting.
>
> In my setting the resuling 'perf' is less than 60MB:
>
>  $ ls -s  ~/perf -h
>  58M /home/wn/perf
>
>  $ size  ~/perf
>    text       data        bss        dec        hex    filename
>  56931273    2950808    24108632    83990713    50198b9 /home/wn/perf
>
> It is reasonable for me.
>
> I think using dynamic clang and llvm libraries is possible but I
> never tried it before. It depend on LLVM compiling. I think if
> distro provides shared libraries then perf can utilize them
> automatically. Let me check it today.
>

Good news: it works.

To enable llvm and clang dynamic libraries, we need to build llvm and 
clang with
cmake option -DBUILD_SHARED_LIBS=ON. Then apply a trivial patch to perf:

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index dfb20dd..e3054f3 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -346,7 +346,7 @@ LIBS = -Wl,--whole-archive $(PERFLIBS) 
-Wl,--no-whole-archive -Wl,--start-group

  ifeq ($(USE_CLANG), 1)
    CLANGLIBS_LIST = AST Basic CodeGen Driver Frontend Lex Tooling Edit 
Sema Analysis Parse Serialization
-  LIBCLANG = $(foreach l,$(CLANGLIBS_LIST),$(wildcard $(shell 
$(LLVM_CONFIG) --libdir)/libclang$(l).a))
+  LIBCLANG = $(foreach l,$(CLANGLIBS_LIST),$(wildcard $(shell 
$(LLVM_CONFIG) --libdir)/libclang$(l).so))
    LIBS += -Wl,--start-group $(LIBCLANG) -Wl,--end-group
  endif

(replace '.a' to '.so')

Resuling perf executable:

$ ls -s -h ~/perf
26M /home/wn/perf

$ size ~/perf
    text       data        bss        dec        hex    filename
4274339     755032    23959984    28989355    1ba57ab /home/wn/perf

$ strip ~/perf
$ ls -s -h
4.9M /home/wn/perf

$ ldd ~/perf | grep 'LLVM\|clang'
     libclangBasic.so => /tmp/oxygen_root/usr/lib64/libclangBasic.so 
(0x00007f24da49f000)
     libclangCodeGen.so => /tmp/oxygen_root/usr/lib64/libclangCodeGen.so 
(0x00007f24d9f72000)
     libclangFrontend.so => 
/tmp/oxygen_root/usr/lib64/libclangFrontend.so (0x00007f24d9c64000)
     libclangTooling.so => /tmp/oxygen_root/usr/lib64/libclangTooling.so 
(0x00007f24d9a01000)
     libLLVMBPFCodeGen.so => 
/tmp/oxygen_root/usr/lib64/libLLVMBPFCodeGen.so (0x00007f24d97e2000)
     libLLVMBPFDesc.so => /tmp/oxygen_root/usr/lib64/libLLVMBPFDesc.so 
(0x00007f24d95da000)
     ....

As I said, if distro provides dynamic libraries then everything would be 
fine.

If you are okay with the above conclusion, in next version I'll use 
'-lclangBasic'
style linking options so it works for both dynamic and static 
LLVM/clang, then let's
wait for distro's action.

Thank you.

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


Thread

[PATCH v3 10/30] perf clang: Add builtin clang support ant test case Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
  Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-11-26 18:20 +0100
    Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case "Wangnan (F)" <wangnan0@huawei.com> - 2016-11-28 08:50 +0100
  Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-12-02 16:50 +0100
    Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case "Wangnan (F)" <wangnan0@huawei.com> - 2016-12-05 03:40 +0100
      Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case "Wangnan (F)" <wangnan0@huawei.com> - 2016-12-05 05:50 +0100
    Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-12-05 18:00 +0100
      Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-12-05 22:10 +0100
        Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-12-05 22:50 +0100
          Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case "Wangnan (F)" <wangnan0@huawei.com> - 2016-12-06 03:20 +0100
            Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-12-06 14:50 +0100
      Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-12-06 20:30 +0100
        Re: [PATCH v3 10/30] perf clang: Add builtin clang support ant test  case Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-12-06 22:10 +0100
  [tip:perf/core] perf clang: Add builtin clang support ant test case tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:30 +0100

csiph-web