<div dir="ltr"><br><div>There are two independent sets of "-O<x>" options:</div><div><br></div><div><br></div><div>1. The gcc/clang options -O[0-3sz]</div><div><br></div><div>These include -O0 to -O3 and -Os (optimize for size) and -Oz (attempt to achieve minimum size, even at significant runtime cost). These options affect the compiler's optimizer. For example, they affect things like inlining and unrolling where performance can often be significantly increased at the cost of code size.</div><div><br></div><div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">2. The ld/gold/lld options -O[0-3]</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">As you found, these range from -O0 to -O3 and control features like linker string merging and tail duplication that tend to save some binary size. There is no -Os or -Oz since, unlike the compiler, the linker only does size optimizations (whereas the compiler has to balance performance against code size).</div><br class="gmail-Apple-interchange-newline"><br></div><div>So to answer your question, the fact that there is no `-Os` for gold is as intended.</div><div><br></div><div><br></div><div>FWIW, if you are trying to save on code size, consider also passing `-ffunction-sections -fdata-sections` to clang/gcc when compiling your .cpp files and then pass `--gc-sections --icf=all` to gold/lld.</div><div><br></div><div>-- Sean Silva</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 6, 2018 at 10:39 PM, Muhui Jiang via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div><br></div><div>When I use -flto -fuse-ld=gold to force clang to use gold as the linker. I found gold doesn't support the optimization flag -Os. It says that the flag must between 0-3. </div><div><br></div><div>Does anyone know how to use size optimization with gold linker? Many Thanks.</div><div><br></div><div>Regards</div><span class="HOEnZb"><font color="#888888"><div>Muhui</div></font></span></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>