<div dir="ltr">Unfortunately the linker part of @llvm.used is not implemented for ELF. One way that it could be implemented is to emit a zero-length .init_array section with an R_*_NONE relocation pointing to the symbol.<div><br></div><div>If you just want a quick workaround, you could use the -u linker flag to keep the symbol alive.</div><div><br></div><div>Peter</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 10:12 AM Johan Engelen 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div> The documentation of `@llvm.used` says:</div><div><br></div><div>"<span style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px">If a symbol appears in the </span><code class="gmail-m_-6220647150546287564gmail-docutils gmail-m_-6220647150546287564gmail-literal gmail-m_-6220647150546287564gmail-notranslate" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:0.95em;color:rgb(0,0,0)"><span class="gmail-m_-6220647150546287564gmail-pre">@llvm.used</span></code><span style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px"> list, then the compiler, assembler, and linker are required to treat the symbol as if there is a reference to the symbol that it cannot see (which is why they have to be named)."</span></div><div><br></div><div>We've always understood this as: the symbol will survive into the final executable, also when it is in its own section and with `--gc-sections`. But I think that's not true.</div><div>My understanding now is that `@llvm.used` is completely ignored by the linker when creating a final whole-program binary. That is, the symbol is emitted by the compiler into the object file, so not stripped e.g. by DCE. But when the linker combines multiple object files into the final executable, the symbol will be removed by `--gc-sections` when the linker sees no reference to it.</div><div>It appears that the only way to keep an unreferenced symbol while linking with `--gc-sections` (compiling with `-f{function,data}-sections`) is to put it in a segment that is kept as specified by the linkerscript (`KEEP`).</div><div><br></div><div>I hope someone can tell me that my current understanding is correct, and that we have to use another way to keep a symbol until the very end (tips welcome, without modifying the system default linker script...).</div><div><br></div><div>Thanks!</div><div> Johan</div><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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>