llvm.org GIT mirror llvm / ea55c83
Remove mention of llvm-gcc/llvm-g++ from doc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139998 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
1 changed file(s) with 36 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
7474

Usage

7575
7676
77
7778

The linker takes a -plugin option that points to the path of

7879 the plugin .so file. To find out what link command gcc
7980 would run in a given situation, run gcc -v [...] and look
8182 ld-new -plugin /path/to/LLVMgold.so to test it out. Once you're
8283 ready to switch to using gold, backup your existing /usr/bin/ld
8384 then replace it with ld-new.

84

You can produce bitcode files from llvm-gcc using

85
86

You can produce bitcode files from clang using

8587 -emit-llvm or -flto, or the -O4 flag which is
8688 synonymous with -O3 -flto.

87

llvm-gcc has a -use-gold-plugin option which looks

88 for the gold plugin in the same directories as it looks for cc1 and
89 passes the -plugin option to ld. It will not look for an alternate
89
90

Clang has a -use-gold-plugin option which looks for the

91 gold plugin in the same directories as it looks for cc1 and passes
92 the -plugin option to ld. It will not look for an alternate
9093 linker, which is why you need gold to be the installed system linker in your
9194 path.

95
9296

If you want ar and nm to work seamlessly as well, install

9397 LLVMgold.so to /usr/lib/bfd-plugins. If you built your
9498 own gold, be sure to install the ar and nm-new you built to
95 /usr/bin.
96 <p>
99 <tt>/usr/bin.<p>
97100
98101
99102

136139 }
137140
138141 --- command lines ---
139 $ llvm-gcc -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file
142 $ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file
140143 $ ar q a.a a.o # <-- a.a is an archive with LLVM bitcode
141 $ llvm-gcc b.c -c -o b.o # <-- b.o is native object file
142 $ llvm-gcc -use-gold-plugin a.a b.o -o main # <-- link with LLVMgold plugin
144 $ clang b.c -c -o b.o # <-- b.o is native object file
145 $ clang -use-gold-plugin a.a b.o -o main # <-- link with LLVMgold plugin
143146
147
144148

Gold informs the plugin that foo3 is never referenced outside the IR,

145149 leading LLVM to delete that function. However, unlike in the
146150 libLTO
157161
158162
159163
160

Once your system ld, ar and nm all support LLVM

161 bitcode, everything is in place for an easy to use LTO build of autotooled
162 projects:

164

Once your system ld, ar, and nm all support LLVM

165 bitcode, everything is in place for an easy to use LTO build of autotooled
166 projects:

167
163168
164169
  • Follow the instructions on how to build LLVMgold.so.
  • 165170
  • Install the newly built binutils to $PREFIX
  • 166171
  • Copy Release/lib/LLVMgold.so to
  • 167 $PREFIX/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/ and
    168 $PREFIX/lib/bfd-plugins/
    169
  • Set environment variables ($PREFIX is where you installed llvm-gcc and
  • 170 binutils):
    171
    
                      
                    
    172 export CC="$PREFIX/bin/llvm-gcc -use-gold-plugin"
    173 export CXX="$PREFIX/bin/llvm-g++ -use-gold-plugin"
    172 $PREFIX/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/ and
    173 $PREFIX/lib/bfd-plugins/
    174
  • Set environment variables ($PREFIX is where you installed clang and
  • 175 binutils):
    176
    
                      
                    
    177 export CC="$PREFIX/bin/clang -use-gold-plugin"
    178 export CXX="$PREFIX/bin/clang++ -use-gold-plugin"
    174179 export AR="$PREFIX/bin/ar"
    175180 export NM="$PREFIX/bin/nm"
    176181 export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files in .a
    178183
    179184
    180185
  • Or you can just set your path:
  • 181
    
                      
                    
    186
    
                      
                    
    182187 export PATH="$PREFIX/bin:$PATH"
    183 export CC="llvm-gcc -use-gold-plugin"
    184 export CXX="llvm-g++ -use-gold-plugin"
    188 export CC="clang -use-gold-plugin"
    189 export CXX="clang++ -use-gold-plugin"
    185190 export RANLIB=/bin/true
    186191 export CFLAGS="-O4"
    187
    188
    189
  • Configure & build the project as usual: ./configure && make && make check
  • 192
    193
  • Configure & build the project as usual:
  • 194
    
                      
                    
    195 % ./configure && make && make check
    196
    190197
    191

    The environment variable settings may work for non-autotooled projects

    192 too, but you may need to set the LD environment variable as well.

    198
    199

    The environment variable settings may work for non-autotooled projects

    200 too, but you may need to set the LD environment variable as
    201 well.

    193202
    194203
    195204