mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-26 07:19:16 +08:00
* elf64-ppc.c (ppc64_elf_edit_toc): Clear "repeat" inside
loop. Really mark toc entry referring to another toc entry only if the first is used.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2012-11-05 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
* elf64-ppc.c (ppc64_elf_edit_toc): Clear "repeat" inside
|
||||||
|
loop. Really mark toc entry referring to another toc entry
|
||||||
|
only if the first is used.
|
||||||
|
|
||||||
2012-10-30 H.J. Lu <hongjiu.lu@intel.com>
|
2012-10-30 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* configure.in: Also handle --enable-64-bit-bfd when setting
|
* configure.in: Also handle --enable-64-bit-bfd when setting
|
||||||
|
258
bfd/elf64-ppc.c
258
bfd/elf64-ppc.c
@ -8372,150 +8372,156 @@ ppc64_elf_edit_toc (struct bfd_link_info *info)
|
|||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
|
||||||
/* Mark toc entries referenced as used. */
|
/* Mark toc entries referenced as used. */
|
||||||
repeat = 0;
|
|
||||||
do
|
do
|
||||||
for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
|
{
|
||||||
{
|
repeat = 0;
|
||||||
enum elf_ppc64_reloc_type r_type;
|
for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
|
||||||
unsigned long r_symndx;
|
{
|
||||||
asection *sym_sec;
|
enum elf_ppc64_reloc_type r_type;
|
||||||
struct elf_link_hash_entry *h;
|
unsigned long r_symndx;
|
||||||
Elf_Internal_Sym *sym;
|
asection *sym_sec;
|
||||||
bfd_vma val;
|
struct elf_link_hash_entry *h;
|
||||||
enum {no_check, check_lo, check_ha} insn_check;
|
Elf_Internal_Sym *sym;
|
||||||
|
bfd_vma val;
|
||||||
|
enum {no_check, check_lo, check_ha} insn_check;
|
||||||
|
|
||||||
r_type = ELF64_R_TYPE (rel->r_info);
|
r_type = ELF64_R_TYPE (rel->r_info);
|
||||||
switch (r_type)
|
switch (r_type)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
insn_check = no_check;
|
insn_check = no_check;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_PPC64_GOT_TLSLD16_HA:
|
case R_PPC64_GOT_TLSLD16_HA:
|
||||||
case R_PPC64_GOT_TLSGD16_HA:
|
case R_PPC64_GOT_TLSGD16_HA:
|
||||||
case R_PPC64_GOT_TPREL16_HA:
|
case R_PPC64_GOT_TPREL16_HA:
|
||||||
case R_PPC64_GOT_DTPREL16_HA:
|
case R_PPC64_GOT_DTPREL16_HA:
|
||||||
case R_PPC64_GOT16_HA:
|
case R_PPC64_GOT16_HA:
|
||||||
case R_PPC64_TOC16_HA:
|
case R_PPC64_TOC16_HA:
|
||||||
insn_check = check_ha;
|
insn_check = check_ha;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_PPC64_GOT_TLSLD16_LO:
|
case R_PPC64_GOT_TLSLD16_LO:
|
||||||
case R_PPC64_GOT_TLSGD16_LO:
|
case R_PPC64_GOT_TLSGD16_LO:
|
||||||
case R_PPC64_GOT_TPREL16_LO_DS:
|
case R_PPC64_GOT_TPREL16_LO_DS:
|
||||||
case R_PPC64_GOT_DTPREL16_LO_DS:
|
case R_PPC64_GOT_DTPREL16_LO_DS:
|
||||||
case R_PPC64_GOT16_LO:
|
case R_PPC64_GOT16_LO:
|
||||||
case R_PPC64_GOT16_LO_DS:
|
case R_PPC64_GOT16_LO_DS:
|
||||||
case R_PPC64_TOC16_LO:
|
case R_PPC64_TOC16_LO:
|
||||||
case R_PPC64_TOC16_LO_DS:
|
case R_PPC64_TOC16_LO_DS:
|
||||||
insn_check = check_lo;
|
insn_check = check_lo;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insn_check != no_check)
|
if (insn_check != no_check)
|
||||||
{
|
{
|
||||||
bfd_vma off = rel->r_offset & ~3;
|
bfd_vma off = rel->r_offset & ~3;
|
||||||
unsigned char buf[4];
|
unsigned char buf[4];
|
||||||
unsigned int insn;
|
unsigned int insn;
|
||||||
|
|
||||||
if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
|
if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
|
||||||
{
|
{
|
||||||
free (used);
|
free (used);
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
insn = bfd_get_32 (ibfd, buf);
|
insn = bfd_get_32 (ibfd, buf);
|
||||||
if (insn_check == check_lo
|
if (insn_check == check_lo
|
||||||
? !ok_lo_toc_insn (insn)
|
? !ok_lo_toc_insn (insn)
|
||||||
: ((insn & ((0x3f << 26) | 0x1f << 16))
|
: ((insn & ((0x3f << 26) | 0x1f << 16))
|
||||||
!= ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
|
!= ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
|
||||||
{
|
{
|
||||||
char str[12];
|
char str[12];
|
||||||
|
|
||||||
ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
|
ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
|
||||||
sprintf (str, "%#08x", insn);
|
sprintf (str, "%#08x", insn);
|
||||||
info->callbacks->einfo
|
info->callbacks->einfo
|
||||||
(_("%P: %H: toc optimization is not supported for"
|
(_("%P: %H: toc optimization is not supported for"
|
||||||
" %s instruction.\n"),
|
" %s instruction.\n"),
|
||||||
ibfd, sec, rel->r_offset & ~3, str);
|
ibfd, sec, rel->r_offset & ~3, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (r_type)
|
switch (r_type)
|
||||||
{
|
{
|
||||||
case R_PPC64_TOC16:
|
case R_PPC64_TOC16:
|
||||||
case R_PPC64_TOC16_LO:
|
case R_PPC64_TOC16_LO:
|
||||||
case R_PPC64_TOC16_HI:
|
case R_PPC64_TOC16_HI:
|
||||||
case R_PPC64_TOC16_HA:
|
case R_PPC64_TOC16_HA:
|
||||||
case R_PPC64_TOC16_DS:
|
case R_PPC64_TOC16_DS:
|
||||||
case R_PPC64_TOC16_LO_DS:
|
case R_PPC64_TOC16_LO_DS:
|
||||||
/* In case we're taking addresses of toc entries. */
|
/* In case we're taking addresses of toc entries. */
|
||||||
case R_PPC64_ADDR64:
|
case R_PPC64_ADDR64:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
r_symndx = ELF64_R_SYM (rel->r_info);
|
||||||
|
if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
|
||||||
|
r_symndx, ibfd))
|
||||||
|
{
|
||||||
|
free (used);
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sym_sec != toc)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
r_symndx = ELF64_R_SYM (rel->r_info);
|
if (h != NULL)
|
||||||
if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
|
val = h->root.u.def.value;
|
||||||
r_symndx, ibfd))
|
else
|
||||||
{
|
val = sym->st_value;
|
||||||
free (used);
|
val += rel->r_addend;
|
||||||
goto error_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sym_sec != toc)
|
if (val >= toc->size)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (h != NULL)
|
if ((skip[val >> 3] & can_optimize) != 0)
|
||||||
val = h->root.u.def.value;
|
{
|
||||||
else
|
bfd_vma off;
|
||||||
val = sym->st_value;
|
unsigned char opc;
|
||||||
val += rel->r_addend;
|
|
||||||
|
|
||||||
if (val >= toc->size)
|
switch (r_type)
|
||||||
continue;
|
{
|
||||||
|
case R_PPC64_TOC16_HA:
|
||||||
if ((skip[val >> 3] & can_optimize) != 0)
|
|
||||||
{
|
|
||||||
bfd_vma off;
|
|
||||||
unsigned char opc;
|
|
||||||
|
|
||||||
switch (r_type)
|
|
||||||
{
|
|
||||||
case R_PPC64_TOC16_HA:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R_PPC64_TOC16_LO_DS:
|
|
||||||
off = rel->r_offset + (bfd_big_endian (ibfd) ? -2 : 3);
|
|
||||||
if (!bfd_get_section_contents (ibfd, sec, &opc, off, 1))
|
|
||||||
{
|
|
||||||
free (used);
|
|
||||||
goto error_ret;
|
|
||||||
}
|
|
||||||
if ((opc & (0x3f << 2)) == (58u << 2))
|
|
||||||
break;
|
break;
|
||||||
/* Fall thru */
|
|
||||||
|
|
||||||
default:
|
case R_PPC64_TOC16_LO_DS:
|
||||||
/* Wrong sort of reloc, or not a ld. We may
|
off = rel->r_offset;
|
||||||
as well clear ref_from_discarded too. */
|
off += (bfd_big_endian (ibfd) ? -2 : 3);
|
||||||
skip[val >> 3] = 0;
|
if (!bfd_get_section_contents (ibfd, sec, &opc,
|
||||||
}
|
off, 1))
|
||||||
}
|
{
|
||||||
|
free (used);
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
if ((opc & (0x3f << 2)) == (58u << 2))
|
||||||
|
break;
|
||||||
|
/* Fall thru */
|
||||||
|
|
||||||
/* For the toc section, we only mark as used if
|
default:
|
||||||
this entry itself isn't unused. */
|
/* Wrong sort of reloc, or not a ld. We may
|
||||||
if (sec == toc
|
as well clear ref_from_discarded too. */
|
||||||
&& !used[val >> 3]
|
skip[val >> 3] = 0;
|
||||||
&& (used[rel->r_offset >> 3]
|
}
|
||||||
|| !(skip[rel->r_offset >> 3] & ref_from_discarded)))
|
}
|
||||||
/* Do all the relocs again, to catch reference
|
|
||||||
chains. */
|
|
||||||
repeat = 1;
|
|
||||||
|
|
||||||
used[val >> 3] = 1;
|
if (sec != toc)
|
||||||
}
|
used[val >> 3] = 1;
|
||||||
|
/* For the toc section, we only mark as used if this
|
||||||
|
entry itself isn't unused. */
|
||||||
|
else if ((used[rel->r_offset >> 3]
|
||||||
|
|| !(skip[rel->r_offset >> 3] & ref_from_discarded))
|
||||||
|
&& !used[val >> 3])
|
||||||
|
{
|
||||||
|
/* Do all the relocs again, to catch reference
|
||||||
|
chains. */
|
||||||
|
repeat = 1;
|
||||||
|
used[val >> 3] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
while (repeat);
|
while (repeat);
|
||||||
|
|
||||||
if (elf_section_data (sec)->relocs != relstart)
|
if (elf_section_data (sec)->relocs != relstart)
|
||||||
|
Reference in New Issue
Block a user