2009-06-18 H.J. Lu <hongjiu.lu@intel.com>

* elf32-i386.c (elf_i386_check_relocs): Remove isymbuf and use
	bfd_sym_from_r_symndx.
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
This commit is contained in:
H.J. Lu 2009-06-18 15:49:39 +00:00
parent 87d72d41b0
commit c2e61a4e93
3 changed files with 42 additions and 90 deletions

View file

@ -1,3 +1,9 @@
2009-06-18 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Remove isymbuf and use
bfd_sym_from_r_symndx.
* elf64-x86-64.c (elf64_x86_64_check_relocs): Likewise.
2009-06-18 Alan Modra <amodra@bigpond.net.au> 2009-06-18 Alan Modra <amodra@bigpond.net.au>
* elf-bfd.h (struct sym_sec_cache): Delete. * elf-bfd.h (struct sym_sec_cache): Delete.

View file

@ -1258,7 +1258,6 @@ elf_i386_check_relocs (bfd *abfd,
const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end; const Elf_Internal_Rela *rel_end;
asection *sreloc; asection *sreloc;
Elf_Internal_Sym *isymbuf;
if (info->relocatable) if (info->relocatable)
return TRUE; return TRUE;
@ -1267,7 +1266,6 @@ elf_i386_check_relocs (bfd *abfd,
htab = elf_i386_hash_table (info); htab = elf_i386_hash_table (info);
symtab_hdr = &elf_symtab_hdr (abfd); symtab_hdr = &elf_symtab_hdr (abfd);
isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
sym_hashes = elf_sym_hashes (abfd); sym_hashes = elf_sym_hashes (abfd);
sreloc = NULL; sreloc = NULL;
@ -1295,25 +1293,18 @@ elf_i386_check_relocs (bfd *abfd,
/* A local symbol. */ /* A local symbol. */
Elf_Internal_Sym *isym; Elf_Internal_Sym *isym;
/* Read this BFD's local symbols. */ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
if (isymbuf == NULL) abfd, r_symndx);
{ if (isym == NULL)
if (isymbuf == NULL) return FALSE;
isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
symtab_hdr->sh_info, 0,
NULL, NULL, NULL);
if (isymbuf == NULL)
return FALSE;
}
/* Check relocation against local STT_GNU_IFUNC symbol. */ /* Check relocation against local STT_GNU_IFUNC symbol. */
isym = isymbuf + r_symndx;
if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
{ {
h = elf_i386_get_local_sym_hash (htab, abfd, rel, h = elf_i386_get_local_sym_hash (htab, abfd, rel,
TRUE); TRUE);
if (h == NULL) if (h == NULL)
goto error_return; return FALSE;
/* Fake a STT_GNU_IFUNC symbol. */ /* Fake a STT_GNU_IFUNC symbol. */
h->type = STT_GNU_IFUNC; h->type = STT_GNU_IFUNC;
@ -1350,7 +1341,7 @@ elf_i386_check_relocs (bfd *abfd,
case R_386_GOT32: case R_386_GOT32:
case R_386_GOTOFF: case R_386_GOTOFF:
if (!_bfd_elf_create_ifunc_sections (abfd, info)) if (!_bfd_elf_create_ifunc_sections (abfd, info))
goto error_return; return FALSE;
break; break;
} }
@ -1380,7 +1371,7 @@ elf_i386_check_relocs (bfd *abfd,
? h->root.root.string : "a local symbol"), ? h->root.root.string : "a local symbol"),
__FUNCTION__); __FUNCTION__);
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
goto error_return; return FALSE;
case R_386_32: case R_386_32:
h->non_got_ref = 1; h->non_got_ref = 1;
@ -1394,7 +1385,7 @@ elf_i386_check_relocs (bfd *abfd,
(abfd, info, sec, sreloc, (abfd, info, sec, sreloc,
&((struct elf_i386_link_hash_entry *) h)->dyn_relocs); &((struct elf_i386_link_hash_entry *) h)->dyn_relocs);
if (sreloc == NULL) if (sreloc == NULL)
goto error_return; return FALSE;
} }
break; break;
@ -1411,7 +1402,7 @@ elf_i386_check_relocs (bfd *abfd,
if (htab->elf.sgot == NULL if (htab->elf.sgot == NULL
&& !_bfd_elf_create_got_section (htab->elf.dynobj, && !_bfd_elf_create_got_section (htab->elf.dynobj,
info)) info))
goto error_return; return FALSE;
break; break;
} }
@ -1423,7 +1414,7 @@ elf_i386_check_relocs (bfd *abfd,
symtab_hdr, sym_hashes, symtab_hdr, sym_hashes,
&r_type, GOT_UNKNOWN, &r_type, GOT_UNKNOWN,
rel, rel_end, h)) rel, rel_end, h))
goto error_return; return FALSE;
switch (r_type) switch (r_type)
{ {
@ -1504,7 +1495,7 @@ elf_i386_check_relocs (bfd *abfd,
+ sizeof (bfd_vma) + sizeof(char)); + sizeof (bfd_vma) + sizeof(char));
local_got_refcounts = bfd_zalloc (abfd, size); local_got_refcounts = bfd_zalloc (abfd, size);
if (local_got_refcounts == NULL) if (local_got_refcounts == NULL)
goto error_return; return FALSE;
elf_local_got_refcounts (abfd) = local_got_refcounts; elf_local_got_refcounts (abfd) = local_got_refcounts;
elf_i386_local_tlsdesc_gotent (abfd) elf_i386_local_tlsdesc_gotent (abfd)
= (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info); = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
@ -1535,7 +1526,7 @@ elf_i386_check_relocs (bfd *abfd,
"thread local symbol"), "thread local symbol"),
abfd, abfd,
h ? h->root.root.string : "<local>"); h ? h->root.root.string : "<local>");
goto error_return; return FALSE;
} }
} }
@ -1557,7 +1548,7 @@ elf_i386_check_relocs (bfd *abfd,
if (htab->elf.dynobj == NULL) if (htab->elf.dynobj == NULL)
htab->elf.dynobj = abfd; htab->elf.dynobj = abfd;
if (!_bfd_elf_create_got_section (htab->elf.dynobj, info)) if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
goto error_return; return FALSE;
} }
if (r_type != R_386_TLS_IE) if (r_type != R_386_TLS_IE)
break; break;
@ -1639,7 +1630,7 @@ elf_i386_check_relocs (bfd *abfd,
(sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE); (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ FALSE);
if (sreloc == NULL) if (sreloc == NULL)
goto error_return; return FALSE;
} }
/* If this is a global symbol, we count the number of /* If this is a global symbol, we count the number of
@ -1676,7 +1667,7 @@ elf_i386_check_relocs (bfd *abfd,
bfd_size_type amt = sizeof *p; bfd_size_type amt = sizeof *p;
p = bfd_alloc (htab->elf.dynobj, amt); p = bfd_alloc (htab->elf.dynobj, amt);
if (p == NULL) if (p == NULL)
goto error_return; return FALSE;
p->next = *head; p->next = *head;
*head = p; *head = p;
p->sec = sec; p->sec = sec;
@ -1694,7 +1685,7 @@ elf_i386_check_relocs (bfd *abfd,
Reconstruct it for later use during GC. */ Reconstruct it for later use during GC. */
case R_386_GNU_VTINHERIT: case R_386_GNU_VTINHERIT:
if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
goto error_return; return FALSE;
break; break;
/* This relocation describes which C++ vtable entries are actually /* This relocation describes which C++ vtable entries are actually
@ -1703,7 +1694,7 @@ elf_i386_check_relocs (bfd *abfd,
BFD_ASSERT (h != NULL); BFD_ASSERT (h != NULL);
if (h != NULL if (h != NULL
&& !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
goto error_return; return FALSE;
break; break;
default: default:
@ -1711,25 +1702,7 @@ elf_i386_check_relocs (bfd *abfd,
} }
} }
if (isymbuf != NULL
&& (unsigned char *) isymbuf != symtab_hdr->contents)
{
if (!info->keep_memory)
free (isymbuf);
else
{
/* Cache the symbols for elf_link_input_bfd. */
symtab_hdr->contents = (unsigned char *) isymbuf;
}
}
return TRUE; return TRUE;
error_return:
if (isymbuf != NULL
&& (unsigned char *) isymbuf != symtab_hdr->contents)
free (isymbuf);
return FALSE;
} }
/* Return the section that should be marked against GC for a given /* Return the section that should be marked against GC for a given

View file

@ -1040,7 +1040,6 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end; const Elf_Internal_Rela *rel_end;
asection *sreloc; asection *sreloc;
Elf_Internal_Sym *isymbuf;
if (info->relocatable) if (info->relocatable)
return TRUE; return TRUE;
@ -1049,7 +1048,6 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
htab = elf64_x86_64_hash_table (info); htab = elf64_x86_64_hash_table (info);
symtab_hdr = &elf_symtab_hdr (abfd); symtab_hdr = &elf_symtab_hdr (abfd);
isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
sym_hashes = elf_sym_hashes (abfd); sym_hashes = elf_sym_hashes (abfd);
sreloc = NULL; sreloc = NULL;
@ -1076,25 +1074,18 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
/* A local symbol. */ /* A local symbol. */
Elf_Internal_Sym *isym; Elf_Internal_Sym *isym;
/* Read this BFD's local symbols. */ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
if (isymbuf == NULL) abfd, r_symndx);
{ if (isym == NULL)
if (isymbuf == NULL) return FALSE;
isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
symtab_hdr->sh_info, 0,
NULL, NULL, NULL);
if (isymbuf == NULL)
return FALSE;
}
/* Check relocation against local STT_GNU_IFUNC symbol. */ /* Check relocation against local STT_GNU_IFUNC symbol. */
isym = isymbuf + r_symndx;
if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
{ {
h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel, h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel,
TRUE); TRUE);
if (h == NULL) if (h == NULL)
goto error_return; return FALSE;
/* Fake a STT_GNU_IFUNC symbol. */ /* Fake a STT_GNU_IFUNC symbol. */
h->type = STT_GNU_IFUNC; h->type = STT_GNU_IFUNC;
@ -1134,7 +1125,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
case R_X86_64_GOTPCREL: case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCREL64: case R_X86_64_GOTPCREL64:
if (!_bfd_elf_create_ifunc_sections (abfd, info)) if (!_bfd_elf_create_ifunc_sections (abfd, info))
goto error_return; return FALSE;
break; break;
} }
@ -1164,7 +1155,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
? h->root.root.string : "a local symbol"), ? h->root.root.string : "a local symbol"),
__FUNCTION__); __FUNCTION__);
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
goto error_return; return FALSE;
case R_X86_64_64: case R_X86_64_64:
h->non_got_ref = 1; h->non_got_ref = 1;
@ -1178,7 +1169,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
(abfd, info, sec, sreloc, (abfd, info, sec, sreloc,
&((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs); &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs);
if (sreloc == NULL) if (sreloc == NULL)
goto error_return; return FALSE;
} }
break; break;
@ -1201,7 +1192,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
if (htab->elf.sgot == NULL if (htab->elf.sgot == NULL
&& !_bfd_elf_create_got_section (htab->elf.dynobj, && !_bfd_elf_create_got_section (htab->elf.dynobj,
info)) info))
goto error_return; return FALSE;
break; break;
} }
@ -1213,7 +1204,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
symtab_hdr, sym_hashes, symtab_hdr, sym_hashes,
&r_type, GOT_UNKNOWN, &r_type, GOT_UNKNOWN,
rel, rel_end, h)) rel, rel_end, h))
goto error_return; return FALSE;
switch (r_type) switch (r_type)
{ {
@ -1230,7 +1221,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
x86_64_elf_howto_table[r_type].name, x86_64_elf_howto_table[r_type].name,
(h) ? h->root.root.string : "a local symbol"); (h) ? h->root.root.string : "a local symbol");
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
goto error_return; return FALSE;
} }
break; break;
@ -1290,7 +1281,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
local_got_refcounts = ((bfd_signed_vma *) local_got_refcounts = ((bfd_signed_vma *)
bfd_zalloc (abfd, size)); bfd_zalloc (abfd, size));
if (local_got_refcounts == NULL) if (local_got_refcounts == NULL)
goto error_return; return FALSE;
elf_local_got_refcounts (abfd) = local_got_refcounts; elf_local_got_refcounts (abfd) = local_got_refcounts;
elf64_x86_64_local_tlsdesc_gotent (abfd) elf64_x86_64_local_tlsdesc_gotent (abfd)
= (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info); = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
@ -1318,7 +1309,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
(*_bfd_error_handler) (*_bfd_error_handler)
(_("%B: '%s' accessed both as normal and thread local symbol"), (_("%B: '%s' accessed both as normal and thread local symbol"),
abfd, h ? h->root.root.string : "<local>"); abfd, h ? h->root.root.string : "<local>");
goto error_return; return FALSE;
} }
} }
@ -1342,7 +1333,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
htab->elf.dynobj = abfd; htab->elf.dynobj = abfd;
if (!_bfd_elf_create_got_section (htab->elf.dynobj, if (!_bfd_elf_create_got_section (htab->elf.dynobj,
info)) info))
goto error_return; return FALSE;
} }
break; break;
@ -1391,7 +1382,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
x86_64_elf_howto_table[r_type].name, x86_64_elf_howto_table[r_type].name,
(h) ? h->root.root.string : "a local symbol"); (h) ? h->root.root.string : "a local symbol");
bfd_set_error (bfd_error_bad_value); bfd_set_error (bfd_error_bad_value);
goto error_return; return FALSE;
} }
/* Fall through. */ /* Fall through. */
@ -1467,7 +1458,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
(sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE); (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
if (sreloc == NULL) if (sreloc == NULL)
goto error_return; return FALSE;
} }
/* If this is a global symbol, we count the number of /* If this is a global symbol, we count the number of
@ -1508,7 +1499,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
p = ((struct elf_dyn_relocs *) p = ((struct elf_dyn_relocs *)
bfd_alloc (htab->elf.dynobj, amt)); bfd_alloc (htab->elf.dynobj, amt));
if (p == NULL) if (p == NULL)
goto error_return; return FALSE;
p->next = *head; p->next = *head;
*head = p; *head = p;
p->sec = sec; p->sec = sec;
@ -1526,7 +1517,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
Reconstruct it for later use during GC. */ Reconstruct it for later use during GC. */
case R_X86_64_GNU_VTINHERIT: case R_X86_64_GNU_VTINHERIT:
if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
goto error_return; return FALSE;
break; break;
/* This relocation describes which C++ vtable entries are actually /* This relocation describes which C++ vtable entries are actually
@ -1535,7 +1526,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
BFD_ASSERT (h != NULL); BFD_ASSERT (h != NULL);
if (h != NULL if (h != NULL
&& !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
goto error_return; return FALSE;
break; break;
default: default:
@ -1543,25 +1534,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
} }
} }
if (isymbuf != NULL
&& (unsigned char *) isymbuf != symtab_hdr->contents)
{
if (!info->keep_memory)
free (isymbuf);
else
{
/* Cache the symbols for elf_link_input_bfd. */
symtab_hdr->contents = (unsigned char *) isymbuf;
}
}
return TRUE; return TRUE;
error_return:
if (isymbuf != NULL
&& (unsigned char *) isymbuf != symtab_hdr->contents)
free (isymbuf);
return FALSE;
} }
/* Return the section that should be marked against GC for a given /* Return the section that should be marked against GC for a given