@llvm.used does not mean the linker will not kill the symbol

Johan Engelen j at j.nl
Mon Apr 1 19:29:20 UTC 2019


On Monday, 1 April 2019 at 18:58:58 UTC, kinke wrote:
>
> On Monday, 1 April 2019 at 17:47:52 UTC, Johan Engelen wrote:
>> After looking more into `@llvm.used` and GCC's 
>> `__attribute__((used))`, I've come to the conclusion that 
>> `llvm.used` does _not_ mean that the linker won't strip it. It 
>> definitely will. Just try this:
>>   __attribute__((used)) void foo() {}
>
> So not even gcc works, or is that clang?

Neither work. The documentation of __attribute__((used)) is only 
about codegen (emission into obj) and not about linking.
-------------------
used
This attribute, attached to a function, means that code must be 
emitted for the function even if it appears that the function is 
not referenced. This is useful, for example, when the function is 
referenced only in inline assembly.

When applied to a member function of a C++ class template, the 
attribute also means that the function is instantiated if the 
class itself is instantiated.
--------------------


However, responses on LLVM thread point to that it _is_ intended 
that `llvm.used` also means that the linker shouldn't remove it. 
It just has not been implemented for ELF (it is working correctly 
for MachO).

https://lists.llvm.org/pipermail/llvm-dev/2019-April/131484.html

-Johan



More information about the digitalmars-d-ldc mailing list