Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gcc use multiple cores when linking?

Tags:

gcc

linker

So when compiling tons of source files with GCC one can use -j to use all available cores. But what about the linker? Is there a similar option to speed up linking or does GCC not support multi-threading? In some larger projects it can really take a while ... (... and I hate to wait!)

Edit: Thanks for pointing out that -j is a option for make and not gcc/g++. But this does not answer my question! I would like to know if gcc can use multi threading while linking a program!

like image 517
Danvil Avatar asked Feb 28 '11 13:02

Danvil


People also ask

Does GCC do linking?

Because of the advantage of dynamic linking, GCC, by default, links to the shared library if it is available. You can list the contents of a library via " nm filename ".

Is GCC multithreaded?

GCC uses a single instance of rtl_data class, representing the current function being compiled in RTL. So far, this should not be a problem as RTL expansion and optimization phase is still single-threaded.

Does compiling use multiple cores?

And for 1000 files, each core of the processor can happily compile one file at a time, keeping all cores totally busy. Tip: "make" uses multiple cores if you give it the right command line option. Without that it will compile one file after the other on a 16 core system.

Does multithreading use multiple cores?

What Is Multithreading? Multithreading is a form of parallelization or dividing up work for simultaneous processing. Instead of giving a large workload to a single core, threaded programs split the work into multiple software threads. These threads are processed in parallel by different CPU cores to save time.


2 Answers

Try gold, which was developed by Ian Lance Taylor et al. from Google and released as part of GNU binutils package.

From Wikipedia:

The motivation for writing gold was to make a linker that is faster than the GNU linker, especially for large applications coded in C++

I must admit I haven't tried it myself yet but it's mentioned on WebKitGTK project webpage.

For more information see an article written by the author of gold: A New ELF Linker.

More importantly, see the work on incremental / parallel / concurrent linking by Sander Mathijs van Veen titled Concurrent Linking with the GNU Gold Linker and the bibliography therein.

like image 76
Adam Romanek Avatar answered Sep 21 '22 23:09

Adam Romanek


lld, the linker developed by the LLVM project, will use multiple cores by default. I have also found it to be about 2x faster than gold running with multiple threads (-Wl,--threads -Wl,--thread-count,xxx)

like image 28
Martin Richtarsky Avatar answered Sep 19 '22 23:09

Martin Richtarsky