<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The GNU linker's handling of debug information is really terrible, and results in frequently running out of memory when linking LLVM with debug information generated.<div class=""><br class=""></div><div class="">You can reduce memory usage by either not building with debug information, or using a different linker.</div><div class=""><br class=""></div><div class="">On linux the Gold linker or LLD are both viable alternatives to gnu.ld, and both have dramatically lower memory usage.</div><div class=""><br class=""></div><div class="">-Chris<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 20, 2018, at 2:53 AM, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style=" font-size:10pt;font-family:sans-serif" class="">Hi all,</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">I've seen it pop
up a few times now: linking LLVM uses too much memory. For me, using a
VM with 10GB RAM was not enough, it still started swapping and the job
took way too long (I had to kill it actually).</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">Using the following
CMake options, I reduced peak memory usage to < 4 GB for a RelWithDebInfo
build (LLVM only, including tools but not cfe/clang).</span>
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">Do NOT set LLVM_USE_LINKER
or set it to gnu.ld</span>
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">LLVM_PARALLEL_LINK_JOBS=1</span>
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">CMAKE_EXE_LINKER_FLAGS="-Wl,--reduce-memory-overheads
-Wl,--hash-size=1021"</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">The `--reduce-memory-overheads`
and the `--hash-size` flags are only supported by the GNU linker as far
as I know.</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">The first option
actually implies the 1021 value set in the second one (and thus `-Wl,--hash-size=1021`
could be omitted), but I suspect that you can play around with the value.
It is supposed to set the size of some internal hash-table sizes of the
linker and not effect the output. (Look up your ld manpage for more info:
</span><a href="https://linux.die.net/man/1/ld" class=""><span style=" font-size:10pt;color:blue;font-family:sans-serif" class="">https://linux.die.net/man/1/ld</span></a><span style=" font-size:10pt;font-family:sans-serif" class="">)
Increasing the number might increase your memory usage and speed up compilation
a bit, until you start swapping. If I had the time to recompile my LLVM
repo a few times, I would try to tune this number to use up most, but not
all of my RAM for optimal speed.</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">I hope this helps
someone. If you have any additional tips, comments or gotchas with this
approach, please add them.</span>
<br class="">
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">All the best,</span>
<br class=""><span style=" font-size:10pt;font-family:sans-serif" class="">Boldizsár Palotás</span><pre class="">This message is intended only for the recipient(s) named above. It may contain proprietary information and/or
protected content. Any unauthorised disclosure, use, retention or dissemination is prohibited. If you have received
this e-mail in error, please notify the sender immediately. ESA applies appropriate organisational measures to protect
personal data, in case of data privacy queries, please contact the ESA Data Protection Officer (<a href="mailto:dpo@esa.int" class="">dpo@esa.int</a>).
</pre>_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>