This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC 1/2] Add IFUNC support for MIPS (v5)
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Faraz Shahbazker <faraz dot shahbazker at imgtec dot com>
- Cc: "libc-alpha\ at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Thu, 03 Sep 2015 23:21:40 +0100
- Subject: Re: [RFC 1/2] Add IFUNC support for MIPS (v5)
- Authentication-results: sourceware.org; auth=none
- References: <DCB1C42372B1674B8F912A294CCB775A71684631 at BADAG02 dot ba dot imgtec dot org> <87k2tdn5xt dot fsf at googlemail dot com> <55BFC10F dot 2050503 at imgtec dot com> <87k2tapwq0 dot fsf at googlemail dot com> <55CE5217 dot 5020902 at imgtec dot com> <87io8f2gc9 dot fsf at googlemail dot com> <55D23368 dot 1070705 at imgtec dot com> <87io8dhegb dot fsf at googlemail dot com> <55D269D2 dot 2030208 at imgtec dot com> <87si7h6oyv dot fsf at googlemail dot com> <55D7A3C5 dot 8050600 at imgtec dot com> <87vbc7u1df dot fsf at googlemail dot com> <55E8C3BC dot 8040606 at imgtec dot com>
Faraz Shahbazker <faraz.shahbazker@imgtec.com> writes:
> - /* This wouldn't work for a symbol imported from other
> - libraries for which there's no GOT entry, but MIPS
> - requires every symbol referenced in a dynamic
> - relocation to have a GOT entry in the primary GOT,
> - so we only get here for locally-defined symbols.
> - For section symbols, we should *NOT* be adding
> - sym->st_value (per the definition of the meaning of
> - S in reloc expressions in the ELF64 MIPS ABI),
> - since it should have already been added to
> - reloc_value by the linker, but older versions of
> - GNU ld didn't add it, and newer versions don't emit
> - useless relocations to section symbols any more, so
> - it is safe to keep on adding sym->st_value, even
> - though it's not ABI compliant. Some day we should
> - bite the bullet and stop doing this. */
> + if (ELFW(ST_BIND) (sym->st_info) == STB_LOCAL)
> + {
> + /* For section symbols, we should *NOT* be adding
> + sym->st_value (per the definition of the meaning of S
> + in reloc expressions in the ELF64 MIPS ABI), since it
> + should have already been added to reloc_value by the
> + linker, but older versions of GNU ld didn't add it, and
> + newer versions don't emit useless relocations to
> + section symbols any more, so it is safe to keep on
> + adding sym->st_value, even though it's not ABI
> + compliant. */
> #ifndef RTLD_BOOTSTRAP
> - if (map != &GL(dl_rtld_map))
> + if (map != &GL(dl_rtld_map))
> +#endif
> + reloc_value += sym->st_value + map->l_addr;
> + }
> +#ifndef RTLD_BOOTSTRAP
> + /* The original MIPS ABI required every global symbol used in
> + a relocation to be in the global GOT. We would then only
> + expect to get here for local symbols. This restriction is
> + removed for objects that use DT_MIPS_GENERAL_GOTNO, since
> + newer relocations and symbol types do not fit easily in the
> + original ABI scheme. Relocations against symbols below
> + DT_MIPS_GOTSYM bind in just the same way as relocations
> + against symbols in the global GOT; the only difference is
> + that we are not able to use the global GOT as a
> + directly-indexed lookup cache. Symbols below
> + DT_MIPS_GOTSYM might be in the general GOT region or might
> + not have a GOT entry at all. */
> + else if (__glibc_unlikely (map->l_info[DT_MIPS (GENERAL_GOTNO)]
> + == NULL))
> + {
> + const char *strtab;
> + strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
> +
> + _dl_error_printf ("\
> +%s: Explicitly relocated symbol `%s' requires dynamic tag MIPS_GENERAL_GOTNO\n",
> + RTLD_PROGNAME, strtab + sym->st_name);
> + }
> + else
> + {
> + struct link_map *rmap = RESOLVE_MAP (&sym, version, r_type);
> + if ((ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC))
> + reloc_value = elf_ifunc_invoke (sym->st_value
> + + rmap->l_addr);
> + else
> + /* The behavior for section symbols described above
> + is now so firmly established that it is explicitly
> + adopted by objects with DT_MIPS_GLOBAL_GOTNO.
> + We therefore don't have a special case for
> + section symbols. */
> + reloc_value = sym->st_value + rmap->l_addr;
> + }
> #endif
> - reloc_value += sym->st_value + map->l_addr;
Don't shoot me :-) but I meant that the structure ought to be:
if (__glibc_unlikely (map->l_info[DT_MIPS (GENERAL_GOTNO)] == NULL))
{
if (ELFW(ST_BIND) (sym->st_info) == STB_LOCAL)
{
/* For section symbols, we should *NOT* be adding
...
}
else
{
const char *strtab;
...
}
}
else
{
struct link_map *rmap = RESOLVE_MAP (&sym, version, r_type);
...
}
I.e. in the DT_MIPS_GENERAL_GOTNO != NULL case we treat the relocation
exactly like a normal relocation on other targets. That just feels more
future proof to me, rather than than keeping the legacy special case
even for the new objects.
This also justifies the "The behavior for section symbols described above
is now so firmly established..." comment. With the structure in the patch
we'd never actually reach that point for section symbols so the comment
doesn't say much. With the revised structure we'd reach that point for
section symbols but not do anything special for them.
Aside from that shuffling around, this looks great to me.
Thanks,
Richard