<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="">Hi All,<div class=""><br class=""></div><div class="">Recently we discovered a (hidden) performance bug that happened when you’re using Full LTO setup + BFD linker to compile first-stage PGO executables that were expected to generate IR level profile files. That is, compiling an executable using following commands:</div><div class="">```</div><div class=""><span id="docs-internal-guid-f9f404e4-7fff-965f-b7be-db6283532868" class=""><span style="font-size: 12pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;" class="">clang -flto -fprofile-generate -c sample.c -o sample.c.bc.o</span></span></div><div class=""><span id="docs-internal-guid-25b12471-7fff-b740-bb93-56de3e65db05" class=""><span style="font-size: 12pt; font-family: "Courier New"; color: rgb(0, 0, 0); font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; vertical-align: baseline; white-space: pre-wrap;" class="">clang -flto sample.c.bc.o -o sample_exe -fprofile-generate</span></span></div><div class="">```</div><div class="">The resulting sample_exe executable will <i class="">always</i> emit Frontend level profile files despite the presence of the -fprofile-generate flag, which should make the executable generate IR level profile files. Other prerequisites to reproduce this problem including:</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Using (latest version of) BFD linker<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Using LLVM’s own LTO linker plugin (i.e. LLVMgold.so)<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Using LLVM’s compiler-rt as the runtime library<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• On a Linux / BSD platform</div></div><div class="">This problem has been confirmed <i class="">not</i> to happen with gold and LLD linkers. Impacts on usages on Windows platform remain unknown.</div><div class=""><br class=""></div><div class="">I just cooked a patch for this bug: <a href="https://reviews.llvm.org/D83967" class="">https://reviews.llvm.org/D83967</a></div><div class="">Basically the solution (and the root cause) is similar to this patch several years ago: <a href="https://reviews.llvm.org/D34797" class="">https://reviews.llvm.org/D34797</a></div><div class=""><br class=""></div><div class="">The intriguing (or annoying) part of this bug is that you’ll never find the issue (since it neither crashes nor causes significant performance regression) unless you take a look into the generated profile files. So I just want to put a heads up here, though I know most of the folks here are moving away from using BFD linkers.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">-Min</div></body></html>