https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98121
jozefl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jozefl at gcc dot gnu.org --- Comment #1 from jozefl at gcc dot gnu.org --- The feedback after I originally submitted a patch that implements a "retain" attribute to apply SHF_GNU_RETIAN, was that "used" should instead apply SHF_GNU_RETAIN: https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557097.html The discussions went on about other aspects of the implementation in other threads, but there were no objections to the idea of "used" applying SHF_GNU_RETAIN. I think the logic is sound that a declaration marked with the "used" attribute should not be removed by the compiler, or garbage collected by the linker. Basically, if you mark a declaration as "used", it should be retained in the final program, even if it was not referenced. The issue lies in the fact that the "used" attribute has been around for so long, that the change in behavior has the potential to affect existing applications that make use of it. However, the new behavior is only enabled when using the latest GCC and latest Binutils. Some change in behavior can be expected when using the latest versions of the tools. This new behavior should really be documented in the release notes though. I didn't want to have "used" change section attributes in assembler directives, the original plan was to use a separate assembler ".retain" directive to apply SHF_GNU_RETAIN. This would mean we could leave .section assembler directives for a particular "used" declaration untouched, and just emit a ".retain <symbol_name>" directive. The assembler therefore handles the application of the SHF_GNU_RETAIN flag to a particular section, instead of forcing the compiler to have to make these additional considerations about section attributes. I even did a patch for that, but there was staunch objection from H.J. on this, on multiple occasions, I realized we weren't going to get anywhere: https://gcc.gnu.org/pipermail/gcc-patches/2020-November/557931.html https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558400.html https://sourceware.org/pipermail/binutils/2020-November/114077.html I would be more than happy to add the .retain attribute to Binutils, but we would need a Binutils global maintainer to approve that, and no one gave the OK for my original ".retain <symbol_name>" patch the first time round. I could then change the GCC implementation to use the ".retain" directive, which would ensure that section attributes in assembler code output by GCC are not contaminated with the "R" flag when the "used" attribute is applied. Thanks, Jozef