On Mon, Jan 29, 2024 at 2:51 PM Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Mon, Jan 29, 2024 at 11:29:22PM +0100, Jakub Jelinek wrote:
> > On Mon, Jan 29, 2024 at 11:22:44PM +0100, Jakub Jelinek wrote:
> > > On Mon, Jan 29, 2024 at 02:01:56PM -0800, H.J. Lu wrote:
> > > > > A function accesses a function symbol defined in a comdat group.
> > > > > If the function symbol is public, any comdat definition of the same 
> > > > > group
> > > > > signature should provide the function definition.  If the function 
> > > > > symbol
> > > > > is private to the comdat group, only functions in the same comdat
> > > > > group can access the private function symbol.  If a function in a 
> > > > > different
> > > > > comdat group accesses a private symbol, it is a compiler bug and
> > > > > link may catch it like in this case.
> > > > >
> > > >
> > > > My patch simply puts the constant pool of the function symbol reference
> > > > in the same comdat group as the function definition.  I believe it is 
> > > > the
> > > > right thing to do.
> > >
> > > I disagree, I think we should use something like
> > >       if (current_function_decl)
> >
> > Or perhaps && DECL_COMDAT_GROUP (current_function_decl) added here as well,
> > just to make it change things less often.
> >
> > >     return targetm.asm_out.function_rodata_section (current_function_decl,
> > >                                                     true);
> > >
> > > Obviously, for non-reloc or non-pic, we don't want an unconditional
> > >   if (current_function_decl)
> > >     return targetm.asm_out.function_rodata_section (current_function_decl,
> > >                                                 false);
> > > that would kill mergeable sections, so perhaps
> > >   if (current_function_decl
> > >       && reloc
> > >       && DECL_COMDAT_GROUP (current_function_decl))
> > >     return targetm.asm_out.function_rodata_section (current_function_decl,
> > >                                                 false);
>
> Now, that doesn't actually work, because current_function_decl is always
> NULL when the constant pool entries are emitted.
> But basing the output section on what it refers rather than what refers to
> it seems wrong, plus there is the section anchors support, which treats them
> yet differently.
> So, I wonder if force_const_mem shouldn't punt if asked to emit from
> DECL_COMDAT_GROUP (current_function_decl) a SYMBOL_REF (or CONST PLUS
> SYMBOL_REF ...) with the same DECL_COMDAT_GROUP with a private symbol,
> or shouldn't punt unless using a per-function (i.e. non-shared) constant
> pool, or force a per-function constant pool in that case somehow.
>

Here is the patch to only call function_rodata_section for COMDAT
function symbol reference:

https://patchwork.sourceware.org/project/gcc/list/?series=30329
-- 
H.J.

Reply via email to