[llvm-dev] Symbols in 'llvm.used' stripped by --gc-sections

Peter Collingbourne via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 1 10:19:12 PDT 2019


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.

If you just want a quick workaround, you could use the -u linker flag to
keep the symbol alive.

Peter

On Mon, Apr 1, 2019 at 10:12 AM Johan Engelen via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi all,
>   The documentation of `@llvm.used` says:
>
> "If a symbol appears in the @llvm.used 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)."
>
> 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.
> 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.
> 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`).
>
> 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...).
>
> Thanks!
>   Johan
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190401/897defa9/attachment.html>


More information about the llvm-dev mailing list