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

--- Comment #7 from Jozef Lawrynowicz <jozefl at gcc dot gnu.org> ---
(In reply to Florian Weimer from comment #6)
> (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.

With the suggested approach, GCC would still drop foo1 if it is not used, since
it is only the section being marked with SECTION_RETAIN, and this only affects
whether the "R" flag is output in the .section directive for the decl.

GCC will only keep an unreferenced decl if it has DECL_PRESERVE_P and we
haven't changed that with the "used" applies SHF_GNU_RETAIN functionality.

If foo1 somehow makes it into the assembler code, it will be kept, even if it
is not used, since we lose the ability to remove individual decls once they are
put in sections.

Reply via email to