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

Message ID 5844EFDF.4040801@huawei.com
State New
Headers show

Commit Message

Wang Nan Dec. 5, 2016, 4:41 a.m.
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:

    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.

Comments

Arnaldo Carvalho de Melo Jan. 17, 2017, 1:38 p.m. | #1
Em Mon, Dec 05, 2016 at 12:41:03PM +0800, Wangnan (F) escreveu:
> 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:

> > I intentionally use statically linking because it is good for

> > smartphone: we can simply 'adb push' a statically linked perf

> > to Android.


So I'm trying to get back to this, and built -DBUILD_SHARED_LIBS=ON HEAD
llvm/clang, applied your patch to switch from .a to .so and got a smaller perf
binary that is dinamically linked to tons of libraries from LLVM and clang, see
below, how to proceed?

I think we should default to linking it dinamically, which is what I'll have in
a test branch and add some machinery to autodetect and use the right approach,
can you do that while I try to go on processing the next patches?

Its a huge bump in the number of libraries in such a build:

[acme@jouet linux]$ ldd /tmp/perf  | wc -l
174
[acme@jouet linux]$ ldd /tmp/perf | egrep -i llvm\|clang | wc -l
145
[acme@jouet linux]$ 

But one expected by those explicitely enabling support for eBPF, right? Those
needing a llvm/clang toolchain installed can opt for using the external
toolchain, that we keep in place, those with a need for those libraries can use
this approach and then those just wanting perf+eBPF, say on a smartphone, like
you said, can get everything in a static build.

- Arnaldo

[acme@jouet linux]$ ls -lah /tmp/perf
-rwxr-xr-x. 1 acme acme 4.4M Jan 17 10:29 /tmp/perf
[acme@jouet linux]$ size /tmp/perf
   text	   data	    bss	    dec	    hex	filename
3954488	 622440	23912104	28489032	1b2b548	/tmp/perf
[acme@jouet linux]$ ldd /tmp/perf | egrep -i llvm\|clang
	libclangAST.so.40 => /usr/local/lib/libclangAST.so.40 (0x00007f4964981000)
	libclangBasic.so.40 => /usr/local/lib/libclangBasic.so.40 (0x00007f49644e6000)
	libclangCodeGen.so.40 => /usr/local/lib/libclangCodeGen.so.40 (0x00007f4963f92000)
	libclangDriver.so.40 => /usr/local/lib/libclangDriver.so.40 (0x00007f4963c59000)
	libclangFrontend.so.40 => /usr/local/lib/libclangFrontend.so.40 (0x00007f4963945000)
	libclangLex.so.40 => /usr/local/lib/libclangLex.so.40 (0x00007f496368d000)
	libclangTooling.so.40 => /usr/local/lib/libclangTooling.so.40 (0x00007f4963447000)
	libclangEdit.so.40 => /usr/local/lib/libclangEdit.so.40 (0x00007f4963239000)
	libclangSema.so.40 => /usr/local/lib/libclangSema.so.40 (0x00007f4962a32000)
	libclangAnalysis.so.40 => /usr/local/lib/libclangAnalysis.so.40 (0x00007f496279b000)
	libclangParse.so.40 => /usr/local/lib/libclangParse.so.40 (0x00007f49624b4000)
	libclangSerialization.so.40 => /usr/local/lib/libclangSerialization.so.40 (0x00007f4962156000)
	libLLVMLTO.so.40 => /usr/local/lib/libLLVMLTO.so.40 (0x00007f4961f13000)
	libLLVMPasses.so.40 => /usr/local/lib/libLLVMPasses.so.40 (0x00007f4961c6d000)
	libLLVMObjCARCOpts.so.40 => /usr/local/lib/libLLVMObjCARCOpts.so.40 (0x00007f4961a48000)
	libLLVMMIRParser.so.40 => /usr/local/lib/libLLVMMIRParser.so.40 (0x00007f496181d000)
	libLLVMSymbolize.so.40 => /usr/local/lib/libLLVMSymbolize.so.40 (0x00007f496160e000)
	libLLVMDebugInfoPDB.so.40 => /usr/local/lib/libLLVMDebugInfoPDB.so.40 (0x00007f49613ca000)
	libLLVMDebugInfoDWARF.so.40 => /usr/local/lib/libLLVMDebugInfoDWARF.so.40 (0x00007f496118f000)
	libLLVMCoverage.so.40 => /usr/local/lib/libLLVMCoverage.so.40 (0x00007f4960f6d000)
	libLLVMTableGen.so.40 => /usr/local/lib/libLLVMTableGen.so.40 (0x00007f4960d22000)
	libLLVMOrcJIT.so.40 => /usr/local/lib/libLLVMOrcJIT.so.40 (0x00007f4960aea000)
	libLLVMXCoreDisassembler.so.40 => /usr/local/lib/libLLVMXCoreDisassembler.so.40 (0x00007f49608e4000)
	libLLVMXCoreCodeGen.so.40 => /usr/local/lib/libLLVMXCoreCodeGen.so.40 (0x00007f4960697000)
	libLLVMXCoreDesc.so.40 => /usr/local/lib/libLLVMXCoreDesc.so.40 (0x00007f4960489000)
	libLLVMXCoreInfo.so.40 => /usr/local/lib/libLLVMXCoreInfo.so.40 (0x00007f4960287000)
	libLLVMXCoreAsmPrinter.so.40 => /usr/local/lib/libLLVMXCoreAsmPrinter.so.40 (0x00007f4960081000)
	libLLVMSystemZDisassembler.so.40 => /usr/local/lib/libLLVMSystemZDisassembler.so.40 (0x00007f495fe70000)
	libLLVMSystemZCodeGen.so.40 => /usr/local/lib/libLLVMSystemZCodeGen.so.40 (0x00007f495fbde000)
	libLLVMSystemZAsmParser.so.40 => /usr/local/lib/libLLVMSystemZAsmParser.so.40 (0x00007f495f9c6000)
	libLLVMSystemZDesc.so.40 => /usr/local/lib/libLLVMSystemZDesc.so.40 (0x00007f495f767000)
	libLLVMSystemZInfo.so.40 => /usr/local/lib/libLLVMSystemZInfo.so.40 (0x00007f495f565000)
	libLLVMSystemZAsmPrinter.so.40 => /usr/local/lib/libLLVMSystemZAsmPrinter.so.40 (0x00007f495f356000)
	libLLVMSparcDisassembler.so.40 => /usr/local/lib/libLLVMSparcDisassembler.so.40 (0x00007f495f14f000)
	libLLVMSparcCodeGen.so.40 => /usr/local/lib/libLLVMSparcCodeGen.so.40 (0x00007f495ef02000)
	libLLVMSparcAsmParser.so.40 => /usr/local/lib/libLLVMSparcAsmParser.so.40 (0x00007f495ecf0000)
	libLLVMSparcDesc.so.40 => /usr/local/lib/libLLVMSparcDesc.so.40 (0x00007f495eacb000)
	libLLVMSparcInfo.so.40 => /usr/local/lib/libLLVMSparcInfo.so.40 (0x00007f495e8c9000)
	libLLVMSparcAsmPrinter.so.40 => /usr/local/lib/libLLVMSparcAsmPrinter.so.40 (0x00007f495e6ad000)
	libLLVMRISCVDesc.so.40 => /usr/local/lib/libLLVMRISCVDesc.so.40 (0x00007f495e4a5000)
	libLLVMRISCVCodeGen.so.40 => /usr/local/lib/libLLVMRISCVCodeGen.so.40 (0x00007f495e2a2000)
	libLLVMRISCVInfo.so.40 => /usr/local/lib/libLLVMRISCVInfo.so.40 (0x00007f495e0a0000)
	libLLVMPowerPCDisassembler.so.40 => /usr/local/lib/libLLVMPowerPCDisassembler.so.40 (0x00007f495de94000)
	libLLVMPowerPCCodeGen.so.40 => /usr/local/lib/libLLVMPowerPCCodeGen.so.40 (0x00007f495db82000)
	libLLVMPowerPCAsmParser.so.40 => /usr/local/lib/libLLVMPowerPCAsmParser.so.40 (0x00007f495d962000)
	libLLVMPowerPCDesc.so.40 => /usr/local/lib/libLLVMPowerPCDesc.so.40 (0x00007f495d6f9000)
	libLLVMPowerPCInfo.so.40 => /usr/local/lib/libLLVMPowerPCInfo.so.40 (0x00007f495d4f6000)
	libLLVMPowerPCAsmPrinter.so.40 => /usr/local/lib/libLLVMPowerPCAsmPrinter.so.40 (0x00007f495d2db000)
	libLLVMNVPTXCodeGen.so.40 => /usr/local/lib/libLLVMNVPTXCodeGen.so.40 (0x00007f495d03b000)
	libLLVMNVPTXDesc.so.40 => /usr/local/lib/libLLVMNVPTXDesc.so.40 (0x00007f495cde7000)
	libLLVMNVPTXInfo.so.40 => /usr/local/lib/libLLVMNVPTXInfo.so.40 (0x00007f495cbe3000)
	libLLVMNVPTXAsmPrinter.so.40 => /usr/local/lib/libLLVMNVPTXAsmPrinter.so.40 (0x00007f495c9ca000)
	libLLVMMSP430CodeGen.so.40 => /usr/local/lib/libLLVMMSP430CodeGen.so.40 (0x00007f495c79d000)
	libLLVMMSP430Desc.so.40 => /usr/local/lib/libLLVMMSP430Desc.so.40 (0x00007f495c592000)
	libLLVMMSP430Info.so.40 => /usr/local/lib/libLLVMMSP430Info.so.40 (0x00007f495c390000)
	libLLVMMSP430AsmPrinter.so.40 => /usr/local/lib/libLLVMMSP430AsmPrinter.so.40 (0x00007f495c18c000)
	libLLVMMipsDisassembler.so.40 => /usr/local/lib/libLLVMMipsDisassembler.so.40 (0x00007f495bf73000)
	libLLVMMipsCodeGen.so.40 => /usr/local/lib/libLLVMMipsCodeGen.so.40 (0x00007f495bc88000)
	libLLVMMipsAsmParser.so.40 => /usr/local/lib/libLLVMMipsAsmParser.so.40 (0x00007f495ba4a000)
	libLLVMMipsDesc.so.40 => /usr/local/lib/libLLVMMipsDesc.so.40 (0x00007f495b7bf000)
	libLLVMMipsInfo.so.40 => /usr/local/lib/libLLVMMipsInfo.so.40 (0x00007f495b5bc000)
	libLLVMMipsAsmPrinter.so.40 => /usr/local/lib/libLLVMMipsAsmPrinter.so.40 (0x00007f495b3ad000)
	libLLVMLanaiDisassembler.so.40 => /usr/local/lib/libLLVMLanaiDisassembler.so.40 (0x00007f495b1a7000)
	libLLVMLanaiCodeGen.so.40 => /usr/local/lib/libLLVMLanaiCodeGen.so.40 (0x00007f495af64000)
	libLLVMLanaiAsmParser.so.40 => /usr/local/lib/libLLVMLanaiAsmParser.so.40 (0x00007f495ad58000)
	libLLVMLanaiDesc.so.40 => /usr/local/lib/libLLVMLanaiDesc.so.40 (0x00007f495ab4a000)
	libLLVMLanaiInstPrinter.so.40 => /usr/local/lib/libLLVMLanaiInstPrinter.so.40 (0x00007f495a943000)
	libLLVMLanaiInfo.so.40 => /usr/local/lib/libLLVMLanaiInfo.so.40 (0x00007f495a741000)
	libLLVMHexagonDisassembler.so.40 => /usr/local/lib/libLLVMHexagonDisassembler.so.40 (0x00007f495a526000)
	libLLVMHexagonCodeGen.so.40 => /usr/local/lib/libLLVMHexagonCodeGen.so.40 (0x00007f495a15e000)
	libLLVMHexagonAsmParser.so.40 => /usr/local/lib/libLLVMHexagonAsmParser.so.40 (0x00007f4959f23000)
	libLLVMHexagonDesc.so.40 => /usr/local/lib/libLLVMHexagonDesc.so.40 (0x00007f4959c77000)
	libLLVMHexagonInfo.so.40 => /usr/local/lib/libLLVMHexagonInfo.so.40 (0x00007f4959a75000)
	libLLVMBPFDisassembler.so.40 => /usr/local/lib/libLLVMBPFDisassembler.so.40 (0x00007f4959871000)
	libLLVMBPFCodeGen.so.40 => /usr/local/lib/libLLVMBPFCodeGen.so.40 (0x00007f4959651000)
	libLLVMBPFDesc.so.40 => /usr/local/lib/libLLVMBPFDesc.so.40 (0x00007f4959447000)
	libLLVMBPFInfo.so.40 => /usr/local/lib/libLLVMBPFInfo.so.40 (0x00007f4959244000)
	libLLVMBPFAsmPrinter.so.40 => /usr/local/lib/libLLVMBPFAsmPrinter.so.40 (0x00007f4959040000)
	libLLVMARMDisassembler.so.40 => /usr/local/lib/libLLVMARMDisassembler.so.40 (0x00007f4958e0c000)
	libLLVMARMCodeGen.so.40 => /usr/local/lib/libLLVMARMCodeGen.so.40 (0x00007f4958a8a000)
	libLLVMARMAsmParser.so.40 => /usr/local/lib/libLLVMARMAsmParser.so.40 (0x00007f495880d000)
	libLLVMARMDesc.so.40 => /usr/local/lib/libLLVMARMDesc.so.40 (0x00007f4958533000)
	libLLVMARMInfo.so.40 => /usr/local/lib/libLLVMARMInfo.so.40 (0x00007f4958330000)
	libLLVMARMAsmPrinter.so.40 => /usr/local/lib/libLLVMARMAsmPrinter.so.40 (0x00007f4958111000)
	libLLVMAMDGPUDisassembler.so.40 => /usr/local/lib/libLLVMAMDGPUDisassembler.so.40 (0x00007f4957ef2000)
	libLLVMAMDGPUCodeGen.so.40 => /usr/local/lib/libLLVMAMDGPUCodeGen.so.40 (0x00007f4957b91000)
	libLLVMAMDGPUAsmParser.so.40 => /usr/local/lib/libLLVMAMDGPUAsmParser.so.40 (0x00007f4957922000)
	libLLVMAMDGPUDesc.so.40 => /usr/local/lib/libLLVMAMDGPUDesc.so.40 (0x00007f49575c8000)
	libLLVMAMDGPUInfo.so.40 => /usr/local/lib/libLLVMAMDGPUInfo.so.40 (0x00007f49573c6000)
	libLLVMAMDGPUAsmPrinter.so.40 => /usr/local/lib/libLLVMAMDGPUAsmPrinter.so.40 (0x00007f4957195000)
	libLLVMAMDGPUUtils.so.40 => /usr/local/lib/libLLVMAMDGPUUtils.so.40 (0x00007f4956f79000)
	libLLVMAArch64Disassembler.so.40 => /usr/local/lib/libLLVMAArch64Disassembler.so.40 (0x00007f4956d58000)
	libLLVMAArch64CodeGen.so.40 => /usr/local/lib/libLLVMAArch64CodeGen.so.40 (0x00007f4956a18000)
	libLLVMAArch64AsmParser.so.40 => /usr/local/lib/libLLVMAArch64AsmParser.so.40 (0x00007f49567b9000)
	libLLVMAArch64Desc.so.40 => /usr/local/lib/libLLVMAArch64Desc.so.40 (0x00007f495651d000)
	libLLVMAArch64Info.so.40 => /usr/local/lib/libLLVMAArch64Info.so.40 (0x00007f495631a000)
	libLLVMAArch64AsmPrinter.so.40 => /usr/local/lib/libLLVMAArch64AsmPrinter.so.40 (0x00007f49560bb000)
	libLLVMAArch64Utils.so.40 => /usr/local/lib/libLLVMAArch64Utils.so.40 (0x00007f4955e9c000)
	libLLVMObjectYAML.so.40 => /usr/local/lib/libLLVMObjectYAML.so.40 (0x00007f4955c5d000)
	libLLVMLibDriver.so.40 => /usr/local/lib/libLLVMLibDriver.so.40 (0x00007f4955a57000)
	libLLVMOption.so.40 => /usr/local/lib/libLLVMOption.so.40 (0x00007f4955849000)
	libLLVMX86Disassembler.so.40 => /usr/local/lib/libLLVMX86Disassembler.so.40 (0x00007f49554e6000)
	libLLVMX86AsmParser.so.40 => /usr/local/lib/libLLVMX86AsmParser.so.40 (0x00007f495523e000)
	libLLVMX86CodeGen.so.40 => /usr/local/lib/libLLVMX86CodeGen.so.40 (0x00007f4954dc9000)
	libLLVMGlobalISel.so.40 => /usr/local/lib/libLLVMGlobalISel.so.40 (0x00007f4954bc5000)
	libLLVMSelectionDAG.so.40 => /usr/local/lib/libLLVMSelectionDAG.so.40 (0x00007f4954799000)
	libLLVMAsmPrinter.so.40 => /usr/local/lib/libLLVMAsmPrinter.so.40 (0x00007f49544ff000)
	libLLVMDebugInfoCodeView.so.40 => /usr/local/lib/libLLVMDebugInfoCodeView.so.40 (0x00007f495429b000)
	libLLVMDebugInfoMSF.so.40 => /usr/local/lib/libLLVMDebugInfoMSF.so.40 (0x00007f495408c000)
	libLLVMX86Desc.so.40 => /usr/local/lib/libLLVMX86Desc.so.40 (0x00007f4953ca8000)
	libLLVMMCDisassembler.so.40 => /usr/local/lib/libLLVMMCDisassembler.so.40 (0x00007f4953a9f000)
	libLLVMX86Info.so.40 => /usr/local/lib/libLLVMX86Info.so.40 (0x00007f495389d000)
	libLLVMX86AsmPrinter.so.40 => /usr/local/lib/libLLVMX86AsmPrinter.so.40 (0x00007f4953648000)
	libLLVMX86Utils.so.40 => /usr/local/lib/libLLVMX86Utils.so.40 (0x00007f495343c000)
	libLLVMMCJIT.so.40 => /usr/local/lib/libLLVMMCJIT.so.40 (0x00007f495322e000)
	libLLVMLineEditor.so.40 => /usr/local/lib/libLLVMLineEditor.so.40 (0x00007f495302a000)
	libLLVMInterpreter.so.40 => /usr/local/lib/libLLVMInterpreter.so.40 (0x00007f4952e03000)
	libLLVMExecutionEngine.so.40 => /usr/local/lib/libLLVMExecutionEngine.so.40 (0x00007f4952be2000)
	libLLVMRuntimeDyld.so.40 => /usr/local/lib/libLLVMRuntimeDyld.so.40 (0x00007f4952991000)
	libLLVMCodeGen.so.40 => /usr/local/lib/libLLVMCodeGen.so.40 (0x00007f4952407000)
	libLLVMTarget.so.40 => /usr/local/lib/libLLVMTarget.so.40 (0x00007f49521fb000)
	libLLVMCoroutines.so.40 => /usr/local/lib/libLLVMCoroutines.so.40 (0x00007f4951fdd000)
	libLLVMipo.so.40 => /usr/local/lib/libLLVMipo.so.40 (0x00007f4951d0d000)
	libLLVMInstrumentation.so.40 => /usr/local/lib/libLLVMInstrumentation.so.40 (0x00007f4951a70000)
	libLLVMVectorize.so.40 => /usr/local/lib/libLLVMVectorize.so.40 (0x00007f49517ea000)
	libLLVMScalarOpts.so.40 => /usr/local/lib/libLLVMScalarOpts.so.40 (0x00007f49513d3000)
	libLLVMLinker.so.40 => /usr/local/lib/libLLVMLinker.so.40 (0x00007f49511b7000)
	libLLVMIRReader.so.40 => /usr/local/lib/libLLVMIRReader.so.40 (0x00007f4950fb0000)
	libLLVMAsmParser.so.40 => /usr/local/lib/libLLVMAsmParser.so.40 (0x00007f4950d59000)
	libLLVMInstCombine.so.40 => /usr/local/lib/libLLVMInstCombine.so.40 (0x00007f4950a8b000)
	libLLVMTransformUtils.so.40 => /usr/local/lib/libLLVMTransformUtils.so.40 (0x00007f4950733000)
	libLLVMBitWriter.so.40 => /usr/local/lib/libLLVMBitWriter.so.40 (0x00007f49504fe000)
	libLLVMAnalysis.so.40 => /usr/local/lib/libLLVMAnalysis.so.40 (0x00007f495005b000)
	libLLVMObject.so.40 => /usr/local/lib/libLLVMObject.so.40 (0x00007f494fde8000)
	libLLVMMCParser.so.40 => /usr/local/lib/libLLVMMCParser.so.40 (0x00007f494fbac000)
	libLLVMMC.so.40 => /usr/local/lib/libLLVMMC.so.40 (0x00007f494f919000)
	libLLVMBitReader.so.40 => /usr/local/lib/libLLVMBitReader.so.40 (0x00007f494f6cd000)
	libLLVMProfileData.so.40 => /usr/local/lib/libLLVMProfileData.so.40 (0x00007f494f498000)
	libLLVMCore.so.40 => /usr/local/lib/libLLVMCore.so.40 (0x00007f494f049000)
	libLLVMSupport.so.40 => /usr/local/lib/libLLVMSupport.so.40 (0x00007f494ed49000)
	libLLVMDemangle.so.40 => /usr/local/lib/libLLVMDemangle.so.40 (0x00007f494eb30000)
	libclangASTMatchers.so.40 => /usr/local/lib/../lib/libclangASTMatchers.so.40 (0x00007f494daf9000)
	libclangFormat.so.40 => /usr/local/lib/../lib/libclangFormat.so.40 (0x00007f494d88f000)
	libclangRewrite.so.40 => /usr/local/lib/../lib/libclangRewrite.so.40 (0x00007f494d67e000)
	libclangToolingCore.so.40 => /usr/local/lib/../lib/libclangToolingCore.so.40 (0x00007f494d46d000)
[acme@jouet linux]$

> > 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.

Patch

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))