Llvm+clang Add LTO (Link time optimization) support

Source: Internet
Author: User
Tags git clone
Llvm+clang Add LTO (Link time optimization) Support binutils

LTO requires that the current system binutils can use the Gold linker or LD.BFD to support LTO, binutils version >= 2.21.511.0.2 via plugin. Ld-plugin can be used to check whether the current system supports plugin.
RHEL/CENTOS6 system comes with Binutils does not support plugin.

$ ld-v
GNU ld version 2.20.51.0.2-5.47.el6_9.1 20100205
$ ld-plugin
ld:unrecognized option '-plugin '
l D:use the--HELP option for usage information

Can be supported after installing DEVTOOLSET-7.

$ ld-v
GNU ld version 2.28-8.el6
$ ld-plugin
ld:-plugin:missing argument
ld:use the--HELP option for Usage information

can also be installed to the system by recompiling the Binutils to provide support

$ git clone--depth 1 git://sourceware.org/git/binutils-gdb.git binutils
$ mkdir Build
$ cd Build
$: /binutils/configure--disable-werror # LD.BFD includes plugin support by default
$ make All-ld
Llvm-clang Full compile Llvm-clang

Reconfigure Llvm-clang run CMake add-dllvm_binutils_incdir=/path/to/binutils/include specify include plugin-api.h directory parameter, make Install/strip is Can. Llvmgold plugin

Install Binutils to the $PREFIX directory.

CMake ...-dllvm_binutils_incdir=/path/to/binutils/include. /llvm_release_500/
make-c tools/gold/

Copy/lib/llvmgold.so to $PREFIX/lib/bfd-plugins/ Usage

Clang-flto xxx.c-o XXX

Autotool tool chain configuration is used.

Export cc= "$PREFIX/bin/clang-flto"
export cxx= "$PREFIX/bin/clang++-flto"
export ar= "$PREFIX/bin/ar"
Export nm= "$PREFIX/bin/nm"
export ranlib=/bin/true #ranlib is isn't needed, and doesn ' t support. bc files in. A
Reference

Gold linker
GCC LTO
Liblto
Goldplugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.