[PATCH] D97448: ELF: Create unique SHF_GNU_RETAIN sections for llvm.used global objects

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 9 00:46:36 PDT 2021


nikic added a comment.

Thanks for the reference! The part that wasn't obvious to me (both from the patch summary here and the gold bug) is that using SHF_GNU_RETAIN with an older binutils version will not only ignore the retain semantics (which is entirely expected), but will lead to silent miscompiles unrelated to retain semantics. From the description here and rnk's comment, it sounded like there aren't any toolchain compatibility concerns.

It would be good to update LangRef in this regard. Currently the `llvm.used` documentation says:

> This is commonly used to represent references from inline asms and other things the compiler cannot “see”, and corresponds to “attribute((used))” in GNU C.

And the `llvm.compiler.used` documentation says:

> This is a rare construct that should only be used in rare circumstances, and should not be exposed to source languages.

While now the recommendation seems to be the other way around: Frontends should map "used"-like attributes to `llvm.compiler.used` rather than `llvm.used`, and using the latter may be dangerous if the frontend doesn't control the used toolchain.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97448/new/

https://reviews.llvm.org/D97448



More information about the llvm-commits mailing list