PR24337, segfault in _bfd_elf_rela_local_sym, again
authorAlan Modra <amodra@gmail.com>
Fri, 15 Mar 2019 23:04:47 +0000 (09:34 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 16 Mar 2019 01:25:28 +0000 (11:55 +1030)
Reverts commit 1ff31e135f, fixing the problem more generally.  There
are likely other place that will segfault on a NULL section.

PR 24337
* elf.c (_bfd_elf_rela_local_sym): Revert last change.
(_bfd_elf_rel_local_sym): Likewise.
* elflink.c (elf_link_input_bfd): Use bfd_und_section for
section of symbols with unrecognized shndx.

bfd/ChangeLog
bfd/elf.c
bfd/elflink.c

index b019ca6..f92b273 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-16  Alan Modra  <amodra@gmail.com>
+
+       PR 24337
+       * elf.c (_bfd_elf_rela_local_sym): Revert last change.
+       (_bfd_elf_rel_local_sym): Likewise.
+       * elflink.c (elf_link_input_bfd): Use bfd_und_section for
+       section of symbols with unrecognized shndx.
+
 2019-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/24267
index 585bf3c..73fb869 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -11822,10 +11822,9 @@ _bfd_elf_rela_local_sym (bfd *abfd,
   asection *sec = *psec;
   bfd_vma relocation;
 
-  relocation = sym->st_value;
-  if (sec == NULL)
-    return relocation;
-  relocation += sec->output_section->vma + sec->output_offset;
+  relocation = (sec->output_section->vma
+               + sec->output_offset
+               + sym->st_value);
   if ((sec->flags & SEC_MERGE)
       && ELF_ST_TYPE (sym->st_info) == STT_SECTION
       && sec->sec_info_type == SEC_INFO_TYPE_MERGE)
@@ -11859,7 +11858,7 @@ _bfd_elf_rel_local_sym (bfd *abfd,
 {
   asection *sec = *psec;
 
-  if (sec == NULL || sec->sec_info_type != SEC_INFO_TYPE_MERGE)
+  if (sec->sec_info_type != SEC_INFO_TYPE_MERGE)
     return sym->st_value + addend;
 
   return _bfd_merged_section_offset (abfd, psec,
index 09990a4..c796e27 100644 (file)
@@ -4446,7 +4446,7 @@ error_free_dyn:
            continue;
 
          /* If we aren't prepared to handle locals within the globals
-             then we'll likely segfault on a NULL section.  */
+            then we'll likely segfault on a NULL section.  */
          bfd_set_error (bfd_error_bad_value);
          goto error_free_vers;
 
@@ -10421,8 +10421,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
            {
              /* Don't attempt to output symbols with st_shnx in the
                 reserved range other than SHN_ABS and SHN_COMMON.  */
-             *ppsection = NULL;
-             continue;
+             isec = bfd_und_section_ptr;
            }
          else if (isec->sec_info_type == SEC_INFO_TYPE_MERGE
                   && ELF_ST_TYPE (isym->st_info) != STT_SECTION)