[PATCH] D96838: Add GNU attribute 'retain'
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 23 11:14:44 PST 2021
MaskRay marked an inline comment as done.
MaskRay added inline comments.
================
Comment at: clang/include/clang/Basic/AttrDocs.td:98
+This support is available in GNU ``ld`` and ``gold`` as of binutils 2.36, as
+well as in ``ld.lld`` 13.
+ }];
----------------
probinson wrote:
> As a user, this seems like a complicated thing to figure out.
> Also it seems to understate the case; if you have a linker that does understand SHF_GNU_RETAIN, then you *have* to use attribute `retain` to get the effect you want; otherwise your code breaks, probably silently.
> And it looks like if you happen to combine an older compiler with a new-enough linker, you can never get it to do what you want.
>
> I hope I'm wrong about these things, but that's what the docs suggest.
> Also it seems to understate the case; if you have a linker that does understand SHF_GNU_RETAIN, then you *have* to use attribute retain to get the effect you want; otherwise your code breaks, probably silently.
For ELF, `used` does not retain the entity, regardless of this patch.
This means on https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable , the "linker" part has been false for ELF, and had been false for COFF until 2018-01 (https://reviews.llvm.org/rG99f479abcf2c9b36daad04eb91cd0aafa659bb1d).
> 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).
`llvm.compiler.used`'s description has
> This is a rare construct that should only be used in rare circumstances, and should not be exposed to source languages.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96838/new/
https://reviews.llvm.org/D96838
More information about the cfe-commits
mailing list