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!
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 ".
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.
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.
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.
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.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With