This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PowerPC [target/17828] -O2 -fPIC doesn't work with switches in linkonce functions and new binutils
On Wed, Jul 27, 2005 at 03:15:11AM -0400, Jakub Jelinek wrote:
> On Wed, Jul 27, 2005 at 11:51:15AM +0930, Alan Modra wrote:
>
> > +#if HAVE_LD_MULT_GOT2 && HAVE_COMDAT_GROUP
> > +/* If function text will be placed in separate sections, then place
> > + toc entries for the function in separate sections too. */
> > +#undef TOC_PER_FUNCTION
> > +#define TOC_PER_FUNCTION \
> > + (TARGET_ELF \
> > + && DEFAULT_ABI == ABI_V4 \
> > + && flag_pic == 2 \
> > + && cfun != NULL \
> > + && cfun->decl != NULL \
> > + && (DECL_ONE_ONLY (cfun->decl) \
> > + || (flag_function_sections && flag_data_sections)))
> > +#endif
>
> Couldn't we have a definition also for
> !HAVE_LD_MULT_GOT2 && HAVE_COMDAT_GROUP? In that case it couldn't
> handle (flag_function_sections && flag_data_sections), just DECL_ONE_ONLY
> (cfun->decl), by using .section .got2,"awG",[comdat_group],comdat.
No, that would require linker support too. -msecure-plt needs to know
the got section used before making plt calls. A linker that doesn't
pass the HAVE_LD_MULT_GOT test will just use the first .got2 section it
finds in the input file, which might be the wrong one.
> > +
> > #define SDATA_SECTION_ASM_OP "\t.section\t\".sdata\",\"aw\""
> > #define SDATA2_SECTION_ASM_OP "\t.section\t\".sdata2\",\"a\""
> > #define SBSS_SECTION_ASM_OP "\t.section\t\".sbss\",\"aw\",@nobits"
> > @@ -378,7 +392,38 @@ do { \
> > void \
> > toc_section (void) \
> > { \
> > - if (in_section != in_toc) \
> > + if (TOC_PER_FUNCTION) \
> > + { \
> > + if (in_section != in_toc \
> > + || toc_initialized != current_function_funcdef_no + 2) \
>
> Isn't using just one global toc_initialized and not
> cfun->machine->toc_initialized instead here too risky? It relies e.g.
> on all non-TOC_PER_FUNCTION functions to be emitted first and then
> TOC_PER_FUNCTION ones (otherwise e.g. DECL_ONE_ONLY's toc_section
> would set toc_initialized to its number + 2 and later on when
> !TOC_PER_FUNCTION, we would see toc_initialized != 0 and assume
> the non-COMDAT .got2 doesn't have to be set up).
No, because it so happens that .got2 is always set up first via the
toc_section call in rs6000_file_start.
> > + s = TREE_STRING_POINTER (DECL_SECTION_NAME (cfun->decl)); \
> > + s = strchr (s + 1, '.'); \
> > + if (s == NULL) \
> > + s = ""; \
>
> Can't we unconditionally use "" for DECL_ONE_ONLY functions (as COMDAT
> will take care of its uniqueness)?
You could, but then the linker would need to search the group to map
function text to got2 sections. That might be a reasonable thing to do
too, but I didn't implement the linker support that way. One reason is
that the gcc-3.4 support I've also implemented uses .gnu.linkonce
sections which require a naming convention to associate the sections.
--
Alan Modra
IBM OzLabs - Linux Technology Centre