[Bug other/98121] __attribute__ ((used)) should not imply SHF_RETAIN_SECTION

fw at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 3 16:53:34 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98121

--- Comment #6 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to Jozef Lawrynowicz from comment #4)
> GAS merges the "R" flag state in .section declarations, silently, and with
> logical OR, and GCC should do the same. So if you have:
> 
> int __attribute__((section(".data.foo"))) foo1 = 1;
> int __attribute__((used,section(".data.foo"))) foo2 = 2;
> 
> .data.foo should have SECTION_RETAIN set within GCC. The addition of the
> "used" attribute to the second declaration of section(".data.foo") should
> not cause any warning/error messages to be emitted either. So option 3 from
> above.
> 
> Just need to do something similar to what is already done for SECTION_NOTYPE
> in varasm.c:get_section.

I don't now the details, but I think foo1 should not implicitly be marked as
“used”. The difference matters for static functions, for example. GCC should
still drop them if they are not referenced, even if they are located in a
retained section.  So free_slotinfo in comment 5.


More information about the Gcc-bugs mailing list