Fix 17492, ld segfault with --oformat=binary

PR 17492
	* elf32-arm.c (elf32_arm_add_symbol_hook): Only set has_gnu_symbols
	on ELF output bfd.
	* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Likewise.  Handle
	STB_GNU_UNIQUE too.
This commit is contained in:
Alan Modra 2014-10-16 21:16:07 +10:30
parent bb99c4726c
commit f1885d1e59
11 changed files with 62 additions and 39 deletions

View File

@ -1,3 +1,19 @@
2014-10-16 Alan Modra <amodra@gmail.com>
PR 17492
* elf32-arm.c (elf32_arm_add_symbol_hook): Only set has_gnu_symbols
on ELF output bfd.
* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
* elf-s390-common.c (elf_s390_add_symbol_hook): Likewise. Handle
STB_GNU_UNIQUE too.
2014-10-16 Alan Modra <amodra@gmail.com> 2014-10-16 Alan Modra <amodra@gmail.com>
* elf64-ppc.c (ppc64_elf_before_check_relocs): Do .opd processing * elf64-ppc.c (ppc64_elf_before_check_relocs): Do .opd processing

View File

@ -234,8 +234,10 @@ elf_s390_add_symbol_hook (bfd *abfd,
asection **secp ATTRIBUTE_UNUSED, asection **secp ATTRIBUTE_UNUSED,
bfd_vma *valp ATTRIBUTE_UNUSED) bfd_vma *valp ATTRIBUTE_UNUSED)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
&& (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;

View File

@ -15908,9 +15908,10 @@ elf32_arm_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
Elf_Internal_Sym *sym, const char **namep, Elf_Internal_Sym *sym, const char **namep,
flagword *flagsp, asection **secp, bfd_vma *valp) flagword *flagsp, asection **secp, bfd_vma *valp)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
if (elf32_arm_hash_table (info) == NULL) if (elf32_arm_hash_table (info) == NULL)

View File

@ -5038,16 +5038,17 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h)
static bfd_boolean static bfd_boolean
elf_i386_add_symbol_hook (bfd * abfd, elf_i386_add_symbol_hook (bfd * abfd,
struct bfd_link_info * info ATTRIBUTE_UNUSED, struct bfd_link_info * info,
Elf_Internal_Sym * sym, Elf_Internal_Sym * sym,
const char ** namep ATTRIBUTE_UNUSED, const char ** namep ATTRIBUTE_UNUSED,
flagword * flagsp ATTRIBUTE_UNUSED, flagword * flagsp ATTRIBUTE_UNUSED,
asection ** secp ATTRIBUTE_UNUSED, asection ** secp ATTRIBUTE_UNUSED,
bfd_vma * valp ATTRIBUTE_UNUSED) bfd_vma * valp ATTRIBUTE_UNUSED)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;

View File

@ -4842,9 +4842,10 @@ elf_m68k_add_symbol_hook (bfd *abfd,
asection **secp ATTRIBUTE_UNUSED, asection **secp ATTRIBUTE_UNUSED,
bfd_vma *valp ATTRIBUTE_UNUSED) bfd_vma *valp ATTRIBUTE_UNUSED)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;

View File

@ -3636,9 +3636,10 @@ ppc_elf_add_symbol_hook (bfd *abfd,
*valp = sym->st_size; *valp = sym->st_size;
} }
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;

View File

@ -173,16 +173,17 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
static bfd_boolean static bfd_boolean
elf32_sparc_add_symbol_hook (bfd * abfd, elf32_sparc_add_symbol_hook (bfd * abfd,
struct bfd_link_info * info ATTRIBUTE_UNUSED, struct bfd_link_info * info,
Elf_Internal_Sym * sym, Elf_Internal_Sym * sym,
const char ** namep ATTRIBUTE_UNUSED, const char ** namep ATTRIBUTE_UNUSED,
flagword * flagsp ATTRIBUTE_UNUSED, flagword * flagsp ATTRIBUTE_UNUSED,
asection ** secp ATTRIBUTE_UNUSED, asection ** secp ATTRIBUTE_UNUSED,
bfd_vma * valp ATTRIBUTE_UNUSED) bfd_vma * valp ATTRIBUTE_UNUSED)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;
} }

View File

@ -4807,19 +4807,16 @@ ppc64_elf_add_symbol_hook (bfd *ibfd,
asection **sec, asection **sec,
bfd_vma *value ATTRIBUTE_UNUSED) bfd_vma *value ATTRIBUTE_UNUSED)
{ {
if ((ibfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
&& ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE) || ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
&& (ibfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) if (!(ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
{ || ELF_ST_TYPE (isym->st_info) == STT_FUNC)
if ((ibfd->flags & DYNAMIC) == 0) && *sec != NULL
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; && strcmp ((*sec)->name, ".opd") == 0)
}
else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC)
;
else if (*sec != NULL
&& strcmp ((*sec)->name, ".opd") == 0)
isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC); isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0) if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)

View File

@ -424,9 +424,10 @@ elf64_sparc_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
{ {
static const char *const stt_types[] = { "NOTYPE", "OBJECT", "FUNCTION" }; static const char *const stt_types[] = { "NOTYPE", "OBJECT", "FUNCTION" };
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
if (ELF_ST_TYPE (sym->st_info) == STT_REGISTER) if (ELF_ST_TYPE (sym->st_info) == STT_REGISTER)

View File

@ -5541,9 +5541,10 @@ elf_x86_64_add_symbol_hook (bfd *abfd,
return TRUE; return TRUE;
} }
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;

View File

@ -481,9 +481,10 @@ _bfd_aarch64_elf_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
asection **secp ATTRIBUTE_UNUSED, asection **secp ATTRIBUTE_UNUSED,
bfd_vma *valp ATTRIBUTE_UNUSED) bfd_vma *valp ATTRIBUTE_UNUSED)
{ {
if ((abfd->flags & DYNAMIC) == 0 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
&& (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
|| ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)) && (abfd->flags & DYNAMIC) == 0
&& bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE; elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
return TRUE; return TRUE;