Fix null pointer dereferences when using a link built with clang.
PR binutils/21342 * elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer dereference. (bfd_elf_final_link): Only initialize the extended symbol index section if there are extended symbol tables to list.
This commit is contained in:
parent
db3a1dc7c9
commit
ad32986fdf
|
@ -1,3 +1,11 @@
|
||||||
|
2017-04-04 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
|
PR binutils/21342
|
||||||
|
* elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer
|
||||||
|
dereference.
|
||||||
|
(bfd_elf_final_link): Only initialize the extended symbol index
|
||||||
|
section if there are extended symbol tables to list.
|
||||||
|
|
||||||
2017-04-03 H.J. Lu <hongjiu.lu@intel.com>
|
2017-04-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
|
* Makefile.am (BFD32_BACKENDS): Add elf-properties.lo.
|
||||||
|
|
|
@ -119,15 +119,18 @@ _bfd_elf_define_linkage_sym (bfd *abfd,
|
||||||
defined in shared libraries can't be overridden, because we
|
defined in shared libraries can't be overridden, because we
|
||||||
lose the link to the bfd which is via the symbol section. */
|
lose the link to the bfd which is via the symbol section. */
|
||||||
h->root.type = bfd_link_hash_new;
|
h->root.type = bfd_link_hash_new;
|
||||||
|
bh = &h->root;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
bh = NULL;
|
||||||
|
|
||||||
bh = &h->root;
|
|
||||||
bed = get_elf_backend_data (abfd);
|
bed = get_elf_backend_data (abfd);
|
||||||
if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL,
|
if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL,
|
||||||
sec, 0, NULL, FALSE, bed->collect,
|
sec, 0, NULL, FALSE, bed->collect,
|
||||||
&bh))
|
&bh))
|
||||||
return NULL;
|
return NULL;
|
||||||
h = (struct elf_link_hash_entry *) bh;
|
h = (struct elf_link_hash_entry *) bh;
|
||||||
|
BFD_ASSERT (h != NULL);
|
||||||
h->def_regular = 1;
|
h->def_regular = 1;
|
||||||
h->non_elf = 0;
|
h->non_elf = 0;
|
||||||
h->root.linker_def = 1;
|
h->root.linker_def = 1;
|
||||||
|
@ -12038,24 +12041,28 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
|
||||||
{
|
{
|
||||||
/* Finish up and write out the symbol string table (.strtab)
|
/* Finish up and write out the symbol string table (.strtab)
|
||||||
section. */
|
section. */
|
||||||
Elf_Internal_Shdr *symstrtab_hdr;
|
Elf_Internal_Shdr *symstrtab_hdr = NULL;
|
||||||
file_ptr off = symtab_hdr->sh_offset + symtab_hdr->sh_size;
|
file_ptr off = symtab_hdr->sh_offset + symtab_hdr->sh_size;
|
||||||
|
|
||||||
symtab_shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
|
if (elf_symtab_shndx_list (abfd))
|
||||||
if (symtab_shndx_hdr != NULL && symtab_shndx_hdr->sh_name != 0)
|
|
||||||
{
|
{
|
||||||
symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
|
symtab_shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
|
||||||
symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
|
|
||||||
symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
|
|
||||||
amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
|
|
||||||
symtab_shndx_hdr->sh_size = amt;
|
|
||||||
|
|
||||||
off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
|
if (symtab_shndx_hdr != NULL && symtab_shndx_hdr->sh_name != 0)
|
||||||
off, TRUE);
|
{
|
||||||
|
symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
|
||||||
|
symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
|
||||||
|
symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
|
||||||
|
amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
|
||||||
|
symtab_shndx_hdr->sh_size = amt;
|
||||||
|
|
||||||
if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
|
off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
|
||||||
|| (bfd_bwrite (flinfo.symshndxbuf, amt, abfd) != amt))
|
off, TRUE);
|
||||||
return FALSE;
|
|
||||||
|
if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
|
||||||
|
|| (bfd_bwrite (flinfo.symshndxbuf, amt, abfd) != amt))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
|
symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
|
||||||
|
|
Loading…
Reference in New Issue