<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Sep 20, 2018 at 11:09 AM Chris Bieneman via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">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><br></div><div>You can reduce memory usage by either not building with debug information, or using a different linker.</div><div><br></div><div>On linux the Gold linker or LLD are both viable alternatives to gnu.ld, and both have dramatically lower memory usage.</div></div></blockquote><div><br></div><div>gold and lld are in the same ballpark if you compare them with GNU bfd linker, but usually lld uses less memory than gold (and is usually faster than gold as well).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>-Chris<br><div><br><blockquote type="cite"><div>On Sep 20, 2018, at 2:53 AM, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_-2672530000289040838Apple-interchange-newline"><div><span style="font-size:10pt;font-family:sans-serif">Hi all,</span>
<br>
<br><span style="font-size:10pt;font-family:sans-serif">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>
<br><span style="font-size:10pt;font-family:sans-serif">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><span style="font-size:10pt;font-family:sans-serif">Do NOT set LLVM_USE_LINKER
or set it to gnu.ld</span>
<br><span style="font-size:10pt;font-family:sans-serif">LLVM_PARALLEL_LINK_JOBS=1</span>
<br><span style="font-size:10pt;font-family:sans-serif">CMAKE_EXE_LINKER_FLAGS="-Wl,--reduce-memory-overheads
-Wl,--hash-size=1021"</span>
<br>
<br><span style="font-size:10pt;font-family:sans-serif">The `--reduce-memory-overheads`
and the `--hash-size` flags are only supported by the GNU linker as far
as I know.</span>
<br>
<br><span style="font-size:10pt;font-family:sans-serif">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" target="_blank"><span style="font-size:10pt;color:blue;font-family:sans-serif">https://linux.die.net/man/1/ld</span></a><span style="font-size:10pt;font-family:sans-serif">)
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>
<br><span style="font-size:10pt;font-family:sans-serif">I hope this helps
someone. If you have any additional tips, comments or gotchas with this
approach, please add them.</span>
<br>
<br><span style="font-size:10pt;font-family:sans-serif">All the best,</span>
<br><span style="font-size:10pt;font-family:sans-serif">Boldizsár Palotás</span><pre>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" target="_blank">dpo@esa.int</a>).
</pre>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>