PR23805, NULL pointer dereference in elf_link_input_bfd
authorAlan Modra <amodra@gmail.com>
Tue, 23 Oct 2018 08:00:22 +0000 (18:30 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 23 Oct 2018 10:39:09 +0000 (21:09 +1030)
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.

bfd/ChangeLog
bfd/elflink.c

index da423b14763565c83169a0e3f0401b6e7d5d06b7..1f3fc1c4d42ef77a234c242cff6c6f472b3e0cfb 100644 (file)
@@ -1,3 +1,10 @@
+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
index c3876cbf3ef7633598ba66d9a32a0b37298e7eb7..87440db9605551795b645561ce12693360274e0c 100644 (file)
@@ -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);
                                }
                            }