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

Johan Engelen j at j.nl
Mon Apr 1 17:47:52 UTC 2019


Hi all,
   Remember we looked into stripped symbols and @llvm.used? Just 
now, I am running into troubles with it again on something 
non-LDC related. Works on x86_64 but not on AArch64 (at least, 
that's what it looks like right now).
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() {}
   int main() { return 0; }

I asked about it on LLVM list, and the answer:
"Unfortunately the linker part of @llvm.used is not implemented 
for ELF."

I think things work for LDC because we reference __start_minfo / 
__stop_minfo and the symbols that we don't want to disappear are 
in those segments. In other words: we actually _do_ reference (in 
a roundabout way) the symbols in the final executable and the 
linker sees that.

Cheers,
   Johan



More information about the digitalmars-d-ldc mailing list