aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2018-10-23 18:30:22 +1030
committerAlan Modra <amodra@gmail.com>2018-10-23 21:09:09 +1030
commit102def4da826b3d9e169741421e5e67e8731909a (patch)
tree0fd9ebb55888cb2eee0b559be776df8b5ab999c3
parentab419ddbb2cdd17ca83618990f2cacf904ce1d61 (diff)
downloadgdb-102def4da826b3d9e169741421e5e67e8731909a.zip
gdb-102def4da826b3d9e169741421e5e67e8731909a.tar.gz
gdb-102def4da826b3d9e169741421e5e67e8731909a.tar.bz2
PR23805, NULL pointer dereference in elf_link_input_bfd
PR 23805 * elflink.c (elf_link_input_bfd): Don't segfault on finding STT_TLS symbols without any TLS sections. Instead, change the symbol type to STT_NOTYPE.
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elflink.c20
2 files changed, 21 insertions, 6 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index da423b1..1f3fc1c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,12 @@
2018-10-23 Alan Modra <amodra@gmail.com>
+ PR 23805
+ * elflink.c (elf_link_input_bfd): Don't segfault on finding
+ STT_TLS symbols without any TLS sections. Instead, change the
+ symbol type to STT_NOTYPE.
+
+2018-10-23 Alan Modra <amodra@gmail.com>
+
PR 23804
* merge.c (_bfd_add_merge_section): Don't attempt to merge
sections where size is not a multiple of entsize.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index c3876cb..87440db 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10489,8 +10489,11 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
if (ELF_ST_TYPE (osym.st_info) == STT_TLS)
{
/* STT_TLS symbols are relative to PT_TLS segment base. */
- BFD_ASSERT (elf_hash_table (flinfo->info)->tls_sec != NULL);
- osym.st_value -= elf_hash_table (flinfo->info)->tls_sec->vma;
+ if (elf_hash_table (flinfo->info)->tls_sec != NULL)
+ osym.st_value -= elf_hash_table (flinfo->info)->tls_sec->vma;
+ else
+ osym.st_info = ELF_ST_INFO (ELF_ST_BIND (osym.st_info),
+ STT_NOTYPE);
}
}
@@ -11046,12 +11049,17 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
sym.st_value += osec->vma;
if (ELF_ST_TYPE (sym.st_info) == STT_TLS)
{
+ struct elf_link_hash_table *htab
+ = elf_hash_table (flinfo->info);
+
/* STT_TLS symbols are relative to PT_TLS
segment base. */
- BFD_ASSERT (elf_hash_table (flinfo->info)
- ->tls_sec != NULL);
- sym.st_value -= (elf_hash_table (flinfo->info)
- ->tls_sec->vma);
+ if (htab->tls_sec != NULL)
+ sym.st_value -= htab->tls_sec->vma;
+ else
+ sym.st_info
+ = ELF_ST_INFO (ELF_ST_BIND (sym.st_info),
+ STT_NOTYPE);
}
}