]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sec->alloced and freeing section contents
authorAlan Modra <amodra@gmail.com>
Sat, 11 Jan 2025 05:50:36 +0000 (16:20 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 19 Jan 2025 20:43:46 +0000 (07:13 +1030)
This modifies _bfd_elf_free_cached_info to unmap/free section
contents.  To do that we need to *not* free sections where contents
are bfd_alloc'd or point to constant strings or somesuch.  I've chosen
to implement this be adding another flag to struct bfd_section,
"alloced" to say the section contents can't be freed.  Most of the
patch is about setting that flag in many places.

60 files changed:
bfd/bfd-in2.h
bfd/coff-arm.c
bfd/compress.c
bfd/elf-m10300.c
bfd/elf-properties.c
bfd/elf.c
bfd/elf32-arc.c
bfd/elf32-arm.c
bfd/elf32-avr.c
bfd/elf32-bfin.c
bfd/elf32-cr16.c
bfd/elf32-cris.c
bfd/elf32-csky.c
bfd/elf32-frv.c
bfd/elf32-hppa.c
bfd/elf32-lm32.c
bfd/elf32-m32c.c
bfd/elf32-m32r.c
bfd/elf32-m68hc1x.c
bfd/elf32-m68k.c
bfd/elf32-metag.c
bfd/elf32-microblaze.c
bfd/elf32-nds32.c
bfd/elf32-or1k.c
bfd/elf32-ppc.c
bfd/elf32-rl78.c
bfd/elf32-s390.c
bfd/elf32-score.c
bfd/elf32-score7.c
bfd/elf32-sh.c
bfd/elf32-spu.c
bfd/elf32-tic6x.c
bfd/elf32-tilepro.c
bfd/elf32-v850.c
bfd/elf32-vax.c
bfd/elf32-xstormy16.c
bfd/elf32-xtensa.c
bfd/elf64-alpha.c
bfd/elf64-hppa.c
bfd/elf64-ia64-vms.c
bfd/elf64-mmix.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elflink.c
bfd/elfnn-aarch64.c
bfd/elfnn-ia64.c
bfd/elfnn-kvx.c
bfd/elfnn-loongarch.c
bfd/elfnn-riscv.c
bfd/elfxx-mips.c
bfd/elfxx-sparc.c
bfd/elfxx-tilegx.c
bfd/elfxx-x86.c
bfd/opncls.c
bfd/section.c
bfd/vms-alpha.c
bfd/wasm-module.c
bfd/xcofflink.c
gas/config/obj-elf.c
ld/ldelf.c

index 1b82b6bcc9952831f15b35efcf0abf3cc85c8c6b..4aa814abe79d4848b54b9ccbb45bdfae93b906b9 100644 (file)
@@ -688,9 +688,12 @@ typedef struct bfd_section
   /* Nonzero if this section uses RELA relocations, rather than REL.  */
   unsigned int use_rela_p:1;
 
-  /* Nonzero if this section contents are mmapped, rather than malloced.  */
+  /* Nonzero if section contents are mmapped.  */
   unsigned int mmapped_p:1;
 
+  /* Nonzero if section contents should not be freed.  */
+  unsigned int alloced:1;
+
   /* Bits used by various backends.  The generic code doesn't touch
      these fields.  */
 
@@ -980,8 +983,8 @@ discarded_section (const asection *sec)
   /* linker_mark, linker_has_input, gc_mark, decompress_status,     */ \
      0,           0,                1,       0,                        \
                                                                       \
-  /* segment_mark, sec_info_type, use_rela_p, mmapped_p,           */  \
-     0,            0,             0,          0,                       \
+  /* segment_mark, sec_info_type, use_rela_p, mmapped_p, alloced,   */ \
+     0,            0,             0,          0,         0,            \
                                                                       \
   /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,    */ \
      0,        0,        0,        0,        0,        0,              \
index 176101a5e4abc8b4156a86aabca8f52ec430a8a6..ab5f7b0663f3b6f0c09dd67e1e9b6e6d5817e092 100644 (file)
@@ -1809,6 +1809,7 @@ bfd_arm_allocate_interworking_sections (struct bfd_link_info * info)
 
       s->size = globals->arm_glue_size;
       s->contents = foo;
+      s->alloced = 1;
     }
 
   if (globals->thumb_glue_size != 0)
@@ -1824,6 +1825,7 @@ bfd_arm_allocate_interworking_sections (struct bfd_link_info * info)
 
       s->size = globals->thumb_glue_size;
       s->contents = foo;
+      s->alloced = 1;
     }
 
   return true;
index 93c3aaed618074e17ab518d60348b03956c86041..b63575067091344e7c25ce56e2d0deb54bbf6418 100644 (file)
@@ -694,6 +694,7 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec)
       sec->size = compressed_size;
       sec->compress_status = COMPRESS_SECTION_DONE;
     }
+  sec->alloced = 1;
   sec->contents = buffer;
   sec->flags |= SEC_IN_MEMORY;
   free (input_buffer);
index 409804ecd386d1030dd0eb96b494e7ea227e3734..ed399da904c71c75387ee158540983cedabf414d 100644 (file)
@@ -5034,6 +5034,7 @@ _bfd_mn10300_elf_late_size_sections (bfd * output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
   else
@@ -5120,6 +5121,7 @@ _bfd_mn10300_elf_late_size_sections (bfd * output_bfd,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 23634a9d9c911aa54cddbaa50e87c4feeb019e85..f150ab4899f3e086448243ede228ac1d363ff15c 100644 (file)
@@ -872,6 +872,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
                                align_size);
 
       /* Cache the section contents for elf_link_input_bfd.  */
+      sec->alloced = 1;
       elf_section_data (sec)->this_hdr.contents = contents;
 
       /* If GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, protected data
index 1aecb4786a25adf4a8ac4389528c54200ef837a4..bce2a18c9614ccbf6ecb8b942250ea271236dc96 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3885,6 +3885,7 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg)
          *failedptr = true;
          return;
        }
+      sec->alloced = 1;
     }
 
   loc = sec->contents + sec->size;
@@ -10125,6 +10126,15 @@ _bfd_elf_free_cached_info (bfd *abfd)
       _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
       _bfd_dwarf1_cleanup_debug_info (abfd, &tdata->dwarf1_find_line_info);
       _bfd_stab_cleanup (abfd, &tdata->line_info);
+      for (asection *sec = abfd->sections; sec != NULL; sec = sec->next)
+       {
+         _bfd_elf_munmap_section_contents (sec, sec->contents);
+         if (!sec->alloced)
+           {
+             free (elf_section_data (sec)->this_hdr.contents);
+             elf_section_data (sec)->this_hdr.contents = NULL;
+           }
+       }
       free (tdata->symtab_hdr.contents);
       tdata->symtab_hdr.contents = NULL;
     }
@@ -14090,6 +14100,7 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, asection *sec)
          hdr->contents = bfd_alloc (abfd, hdr->sh_size);
          if (hdr->contents == NULL)
            continue;
+         relsec->alloced = 1;
 
 #if DEBUG_SECONDARY_RELOCS
          fprintf (stderr, "write %u secondary relocs for %s from %s\n",
@@ -14235,6 +14246,7 @@ elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf)
        }
     }
 #endif
+  /* FIXME: We should not get here if sec->alloced is set.  */
   bool ret = bfd_get_full_section_contents (abfd, sec, buf);
   if (ret && sec->mmapped_p)
     *buf = sec->contents;
@@ -14262,14 +14274,23 @@ _bfd_elf_link_mmap_section_contents (bfd *abfd, sec_ptr sec,
 /* Munmap section contents.  */
 
 void
-_bfd_elf_munmap_section_contents (asection *sec ATTRIBUTE_UNUSED,
-                                 void *contents)
+_bfd_elf_munmap_section_contents (asection *sec, void *contents)
 {
   /* NB: Since _bfd_elf_munmap_section_contents is called like free,
      CONTENTS may be NULL.  */
   if (contents == NULL)
     return;
 
+  if (sec->alloced
+      /* What a tangled web we weave with section contents.
+        FIXME: We shouldn't need to test anything but sec->alloced
+        here, but there are cases where a buffer is allocated for a
+        section but then another buffer is malloc'd anyway.  eg.
+        trace through ld-elf/eh4 testcase on x86_64.  */
+      && (sec->contents == contents
+         || elf_section_data (sec)->this_hdr.contents == contents))
+    return;
+
   /* Don't leave pointers to data we are about to munmap or free.  */
   if (sec->contents == contents)
     sec->contents = NULL;
@@ -14314,6 +14335,7 @@ _bfd_elf_link_munmap_section_contents (asection *sec ATTRIBUTE_UNUSED)
        abort ();
       sec->mmapped_p = 0;
       sec->contents = NULL;
+      elf_section_data (sec)->this_hdr.contents = NULL;
       elf_section_data (sec)->contents_addr = NULL;
       elf_section_data (sec)->contents_size = 0;
     }
index 71de480a4f4d35ce4b772f25b9b169b58eecd6b3..0a6e66569ba9872426b33118bcf2d8551272154d 100644 (file)
@@ -2735,6 +2735,7 @@ elf_arc_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof (ELF_DYNAMIC_INTERPRETER);
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
 
       /* Add some entries to the .dynamic section.  We fill in some of
@@ -2797,6 +2798,7 @@ elf_arc_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs_exist);
index ba60634997e8a0e60ee96177b0dbf88940fe1d03..8865befc06c37d2b548ec054b19cd95ec239e003 100644 (file)
@@ -7073,6 +7073,7 @@ elf32_arm_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
 
       stub_sec->size = 0;
     }
@@ -7279,6 +7280,7 @@ arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * na
 
   BFD_ASSERT (s->size == size);
   s->contents = contents;
+  s->alloced = 1;
 }
 
 bool
@@ -16823,6 +16825,7 @@ elf32_arm_late_size_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -17173,6 +17176,7 @@ elf32_arm_late_size_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
       s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
index b0826bde03ac26dd9d63f843039f3ceeb8a76ca1..0c1c07426c6f0a20fbdff9520d15dba388bbad19 100644 (file)
@@ -3893,6 +3893,7 @@ elf32_avr_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
     }
 
index c7d03cfae46e3d29bee005a94d290f4651788790..547661a3098e7f4bc8169c8cd794fda1b4e21718 100644 (file)
@@ -3928,6 +3928,7 @@ _bfinfdpic_size_got_plt (bfd *output_bfd,
                                 bfinfdpic_got_section (info)->size);
       if (bfinfdpic_got_section (info)->contents == NULL)
        return false;
+      bfinfdpic_got_section (info)->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
@@ -3947,6 +3948,7 @@ _bfinfdpic_size_got_plt (bfd *output_bfd,
                                 bfinfdpic_gotrel_section (info)->size);
       if (bfinfdpic_gotrel_section (info)->contents == NULL)
        return false;
+      bfinfdpic_gotrel_section (info)->alloced = 1;
     }
 
   bfinfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
@@ -3959,6 +3961,7 @@ _bfinfdpic_size_got_plt (bfd *output_bfd,
                                 bfinfdpic_gotfixup_section (info)->size);
       if (bfinfdpic_gotfixup_section (info)->contents == NULL)
        return false;
+      bfinfdpic_gotfixup_section (info)->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
@@ -3973,6 +3976,7 @@ _bfinfdpic_size_got_plt (bfd *output_bfd,
                                 bfinfdpic_pltrel_section (info)->size);
       if (bfinfdpic_pltrel_section (info)->contents == NULL)
        return false;
+      bfinfdpic_pltrel_section (info)->alloced = 1;
     }
 
   /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
@@ -4018,6 +4022,7 @@ _bfinfdpic_size_got_plt (bfd *output_bfd,
                                 bfinfdpic_plt_section (info)->size);
       if (bfinfdpic_plt_section (info)->contents == NULL)
        return false;
+      bfinfdpic_plt_section (info)->alloced = 1;
     }
 
   return true;
@@ -4048,6 +4053,7 @@ elf32_bfinfdpic_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -5142,6 +5148,7 @@ bfin_late_size_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
   else
@@ -5229,6 +5236,7 @@ bfin_late_size_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL && s->size != 0)
        return false;
+      s->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
@@ -5309,6 +5317,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
   relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
   if (relsec->contents == NULL)
     goto error_return;
+  relsec->alloced = 1;
 
   p = relsec->contents;
 
index de3d5d0ee752320692a27b83046d0393b0212ba9..68ac71f69e599a58da617a61f968e0575758701b 100644 (file)
@@ -2411,6 +2411,7 @@ _bfd_cr16_elf_late_size_sections (bfd * output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
 #endif
        }
     }
@@ -2491,6 +2492,7 @@ _bfd_cr16_elf_late_size_sections (bfd * output_bfd,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
@@ -2699,6 +2701,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
   relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
   if (relsec->contents == NULL)
     goto error_return;
+  relsec->alloced = 1;
 
   p = relsec->contents;
 
index 91178fa7980e483a83da0cb88b91362efc52adb8..306d3e792b19f2e6c7e3776ed1c43f1b8bc002b1 100644 (file)
@@ -3530,6 +3530,7 @@ elf_cris_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
   else
@@ -3644,6 +3645,7 @@ elf_cris_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 5cb45e1a426c3db61df3ac9b68eb24d94a86c07e..dbb603b88bcfed31218690216b8b09b736b03db8 100644 (file)
@@ -1916,6 +1916,7 @@ csky_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -2084,6 +2085,7 @@ csky_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->elf.dynamic_sections_created)
@@ -3854,6 +3856,7 @@ elf32_csky_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
     }
 
index 142b5a201b32dbf65ef3d6fd3b4be0b5c2ccba36..a7e8215ff5ee9a4a02328e9157d2cafb5b341b64 100644 (file)
@@ -5313,6 +5313,7 @@ _frvfdpic_size_got_plt (bfd *output_bfd,
                                 frvfdpic_got_section (info)->size);
       if (frvfdpic_got_section (info)->contents == NULL)
        return false;
+      frvfdpic_got_section (info)->alloced = 1;
     }
 
   if (frvfdpic_gotrel_section (info))
@@ -5332,6 +5333,7 @@ _frvfdpic_size_got_plt (bfd *output_bfd,
                                 frvfdpic_gotrel_section (info)->size);
       if (frvfdpic_gotrel_section (info)->contents == NULL)
        return false;
+      frvfdpic_gotrel_section (info)->alloced = 1;
     }
 
   frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
@@ -5344,6 +5346,7 @@ _frvfdpic_size_got_plt (bfd *output_bfd,
                                 frvfdpic_gotfixup_section (info)->size);
       if (frvfdpic_gotfixup_section (info)->contents == NULL)
        return false;
+      frvfdpic_gotfixup_section (info)->alloced = 1;
     }
 
   if (frvfdpic_pltrel_section (info))
@@ -5360,6 +5363,7 @@ _frvfdpic_size_got_plt (bfd *output_bfd,
                                     frvfdpic_pltrel_section (info)->size);
          if (frvfdpic_pltrel_section (info)->contents == NULL)
            return false;
+         frvfdpic_pltrel_section (info)->alloced = 1;
        }
     }
 
@@ -5413,6 +5417,7 @@ _frvfdpic_size_got_plt (bfd *output_bfd,
                                     frvfdpic_plt_section (info)->size);
          if (frvfdpic_plt_section (info)->contents == NULL)
            return false;
+         frvfdpic_plt_section (info)->alloced = 1;
        }
     }
 
@@ -5442,6 +5447,7 @@ elf32_frvfdpic_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
index af11e0d15f0485f5baff4e7154fa75d9db25506f..ba20bc63e5a575678a0f6ceb240cb3dfa3750af4 100644 (file)
@@ -2068,6 +2068,7 @@ elf32_hppa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
          sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         sec->alloced = 1;
        }
 
       /* Force millicode symbols local.  */
@@ -2272,6 +2273,7 @@ elf32_hppa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       sec->contents = bfd_zalloc (dynobj, sec->size);
       if (sec->contents == NULL)
        return false;
+      sec->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
@@ -2995,6 +2997,7 @@ elf32_hppa_build_stubs (struct bfd_link_info *info)
        stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
        if (stub_sec->contents == NULL)
          return false;
+       stub_sec->alloced = 1;
        stub_sec->size = 0;
       }
 
index ee3d9be19be4443ee41f647f4ac35840a021ebda..45264d69c671019c786d7d11cd721e0238301baf 100644 (file)
@@ -1929,6 +1929,7 @@ lm32_elf_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -2054,6 +2055,7 @@ lm32_elf_late_size_sections (bfd *output_bfd,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
@@ -2182,6 +2184,7 @@ lm32_elf_late_size_sections (bfd *output_bfd,
             bfd_zalloc (dynobj, lm32fdpic_fixup32_section (info)->size);
          if (lm32fdpic_fixup32_section (info)->contents == NULL)
            return false;
+         lm32fdpic_fixup32_section (info)->alloced = 1;
        }
     }
 
index c72ae77f73ae806e93427184d0dccb3439f28b69..890a0ac59a66d3b747f21d6f46b03c1cedeaba0f 100644 (file)
@@ -792,6 +792,7 @@ m32c_elf_early_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size);
   if (splt->contents == NULL)
     return false;
+  splt->alloced = 1;
 
   return true;
 }
index 3bae1dd76d1b6b88601b18acc81669c2401c77a1..022b0ac30ac2878d32d550497bfb43b72b0fe73a 100644 (file)
@@ -1987,6 +1987,7 @@ m32r_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -2112,6 +2113,7 @@ m32r_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 86badee9f6cc712caec4025d261b63b49dd94c86..7929d55cb88dd9c2ad51bde6d0e2150f2fdcea9e 100644 (file)
@@ -658,6 +658,7 @@ elf32_m68hc11_build_stubs (bfd *abfd, struct bfd_link_info *info)
       stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
     }
 
index 6ecb34ecb67939ea9edb3bcdcb68b3a54a82183e..d7387d938e889f6ec1058b94e2f1a74511e5ec35 100644 (file)
@@ -3126,6 +3126,7 @@ elf_m68k_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
   else
@@ -3216,6 +3217,7 @@ elf_m68k_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
@@ -4400,6 +4402,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
   relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
   if (relsec->contents == NULL)
     goto error_return;
+  relsec->alloced = 1;
 
   p = relsec->contents;
 
index 93069948fc0f390e06a0c257432771a8497158f6..479b9f4405dd8ff32004078ad430851c34dd7f39 100644 (file)
@@ -2740,6 +2740,7 @@ elf_metag_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -2884,7 +2885,8 @@ elf_metag_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
-      else if (reloc_section)
+      s->alloced = 1;
+      if (reloc_section)
        {
          unsigned char *contents = s->contents;
          Elf32_External_Rela reloc;
@@ -3964,6 +3966,7 @@ elf_metag_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
     }
 
index 4d36577b0fda2aa27cf1bb698127bad63b377350..fb86b3e4bcfa3599afe3959d0bbc0718e4f6366d 100644 (file)
@@ -3144,6 +3144,7 @@ microblaze_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL && s->size != 0)
        return false;
+      s->alloced = 1;
     }
 
   /* ??? Force DF_BIND_NOW?  */
index 6b8d925479a8ce40f67d656faa87ed731e3c4049..9db95e87ec63b37acf200aeb9a86537e886f0df5 100644 (file)
@@ -4326,6 +4326,7 @@ nds32_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -4525,6 +4526,7 @@ nds32_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 2374f1184f1a57812cc7164f25c1c3db2c5f921f..bdee1f1fb99c627f214526ae976c23cfd71dc503 100644 (file)
@@ -3069,6 +3069,7 @@ or1k_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -3204,9 +3205,9 @@ or1k_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
         but this way if it does, we get a R_OR1K_NONE reloc instead
         of garbage.  */
       s->contents = bfd_zalloc (dynobj, s->size);
-
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 2ea1574a026ac491e4c510189f5b54f0ee8abcdf..25cb31b8f3bd9664bd38a7400c43cf2412ec9206 100644 (file)
@@ -5502,6 +5502,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -5881,6 +5882,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
       s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->elf.dynamic_sections_created)
index ff3ca2e56c72e3f4afca5c614c9d9030b700a534..c0b8850cd9308935b9addd651557f01c216eee19 100644 (file)
@@ -1459,6 +1459,7 @@ rl78_elf_early_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size);
   if (splt->contents == NULL)
     return false;
+  splt->alloced = 1;
 
   return true;
 }
index bc5e7cd54656453f185e0495fb2752c9d3ff1114..470335ca602e5632cd1a9a21dc3fe4a4d7e7d996 100644 (file)
@@ -1798,6 +1798,7 @@ elf_s390_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -1957,6 +1958,7 @@ elf_s390_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 9563098dc772f2304b5f25bc94063ec2ddd70e04..63a185442ded581f8beb632ba1ffab0eb12cdd6f 100644 (file)
@@ -3246,6 +3246,7 @@ s3_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info
          BFD_ASSERT (s != NULL);
          s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
          s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -3328,6 +3329,7 @@ s3_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info
          bfd_set_error (bfd_error_no_memory);
          return false;
        }
+      s->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
index 2ecabf6a47baf67bfb29741dd12a9edf60a7adf7..448215550ceaccc04066fe68d7f316753e011d20 100644 (file)
@@ -3056,6 +3056,7 @@ s7_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info
          BFD_ASSERT (s != NULL);
          s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
          s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -3138,6 +3139,7 @@ s7_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info
          bfd_set_error (bfd_error_no_memory);
          return false;
        }
+      s->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
index 11491de419fbe03efe7210dc7a95d677b28e9f21..39a837ce3d875c913a216b9153424ec2c8dc7fb4 100644 (file)
@@ -2966,6 +2966,7 @@ sh_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -3193,6 +3194,7 @@ sh_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
index da54bf7019e85a3f537113ebe228550cd530a019..a6b486736aeaac622325fecad25b9c972aa70e67 100644 (file)
@@ -610,6 +610,7 @@ spu_elf_create_sections (struct bfd_link_info *info)
       memcpy (data + 12 + ((sizeof (SPU_PLUGIN_NAME) + 3) & -4),
              bfd_get_filename (info->output_bfd), name_len);
       s->contents = data;
+      s->alloced = 1;
     }
 
   if (htab->params->emit_fixups)
@@ -1965,6 +1966,7 @@ spu_elf_build_stubs (struct bfd_link_info *info)
                                                      htab->stub_sec[i]->size);
            if (htab->stub_sec[i]->contents == NULL)
              return false;
+           htab->stub_sec[i]->alloced = 1;
            htab->stub_sec[i]->rawsize = htab->stub_sec[i]->size;
            htab->stub_sec[i]->size = 0;
          }
@@ -1999,6 +2001,7 @@ spu_elf_build_stubs (struct bfd_link_info *info)
   htab->ovtab->contents = bfd_zalloc (htab->ovtab->owner, htab->ovtab->size);
   if (htab->ovtab->contents == NULL)
     return false;
+  htab->ovtab->alloced = 1;
 
   p = htab->ovtab->contents;
   if (htab->params->ovly_flavour == ovly_soft_icache)
@@ -2100,6 +2103,7 @@ spu_elf_build_stubs (struct bfd_link_info *info)
                                             htab->init->size);
          if (htab->init->contents == NULL)
            return false;
+         htab->init->alloced = 1;
 
          h = define_ovtab_symbol (htab, "__icache_fileoff");
          if (h == NULL)
@@ -5502,6 +5506,7 @@ spu_elf_size_sections (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
       sfixup->contents = (bfd_byte *) bfd_zalloc (info->input_bfds, size);
       if (sfixup->contents == NULL)
        return false;
+      sfixup->alloced = 1;
     }
   return true;
 }
index 8a444f64453241351418f2473b01763f1fa507ed..0adab1acc07fb2e1045583630d0d65c484bdb2a9 100644 (file)
@@ -3175,6 +3175,7 @@ elf32_tic6x_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -3319,6 +3320,7 @@ elf32_tic6x_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->elf.dynamic_sections_created)
index e4ecb225dff80912d710db336b43c1b40d898dda..6f9017255240bf2460dfe1a80dd5c30881f57b82 100644 (file)
@@ -2203,6 +2203,7 @@ tilepro_elf_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF32_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF32_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -2368,6 +2369,7 @@ tilepro_elf_late_size_sections (bfd *output_bfd,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
index 0599c11b028d1cab8edf0189337965c7e92dfaff..0c523892164ee781b8960352f606437ac09430c2 100644 (file)
@@ -2392,6 +2392,7 @@ v850_elf_make_note_section (bfd * abfd)
     return NULL;
 
   s->contents = data;
+  s->alloced = 1;
 
   /* Provide default (= uninitilaised) values for all of the notes.  */
   for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
index 3f63fe2b201ab61132d2788ccc7724cb9e1336c3..9d1fee86797bf41dfba34dfc2fe741fae3da7d66 100644 (file)
@@ -1041,6 +1041,7 @@ elf_vax_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -1121,6 +1122,7 @@ elf_vax_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index c814c5a83d827c071459e00223f915a0970ebf2a..3fe619d5869a5aa2940ea18b04cda1904fdb50b7 100644 (file)
@@ -725,6 +725,7 @@ xstormy16_elf_early_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   splt->contents = bfd_zalloc (dynobj, splt->size);
   if (splt->contents == NULL)
     return false;
+  splt->alloced = 1;
 
   return true;
 }
index e21b00cd5a10c0a343d7418a1e77191578b6c7f3..f9c006c345c81be035bfb4fd823b5834bbf1a794 100644 (file)
@@ -1593,6 +1593,7 @@ elf_xtensa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
 
       /* Allocate room for one word in ".got".  */
@@ -1731,6 +1732,7 @@ elf_xtensa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
        }
     }
 
index 2be63df8b459d9d8be15f9b9bf4a9882724d1db6..b3570cebf5af5696dea87aeb1166347d1def630c 100644 (file)
@@ -2586,6 +2586,7 @@ elf64_alpha_early_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          s->contents = (bfd_byte *) bfd_zalloc (i, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
        }
     }
 
@@ -2812,6 +2813,7 @@ elf64_alpha_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
 
       /* Now that we've seen all of the input files, we can decide which
@@ -2882,6 +2884,7 @@ elf64_alpha_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
        }
     }
 
index 85406dc7d983f3a65c3fef508a38b48baf6fa8fd..3f5a3fea4abf43ee93571ac54322cae0ec9aefb0 100644 (file)
@@ -1559,6 +1559,7 @@ elf64_hppa_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
          BFD_ASSERT (sec != NULL);
          sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
          sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         sec->alloced = 1;
        }
     }
   else
@@ -1809,6 +1810,7 @@ elf64_hppa_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
          sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
          if (sec->contents == NULL)
            return false;
+         sec->alloced = 1;
        }
     }
 
index d7165e371f00d15e20740dab0b0938084039a235..26710bac97edf81e4934900d991674888e564f26 100644 (file)
@@ -1248,6 +1248,7 @@ create_ia64_vms_notes (bfd *abfd, struct bfd_link_info *info,
     }
 
   ia64_info->note_sec->contents = note_contents;
+  ia64_info->note_sec->alloced = 1;
   ia64_info->note_sec->size = note_size;
 
   free (module_name);
@@ -2761,6 +2762,7 @@ elf64_ia64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
          if (sec->contents == NULL && sec->size != 0)
            return false;
+         sec->alloced = 1;
        }
     }
 
index 5bb6feee16eb2b1cea9185e7e272cea1357f9525..1b5a65d847976525bbb32381b471f64dedce746a 100644 (file)
@@ -2385,6 +2385,7 @@ _bfd_mmix_after_linker_allocation (bfd *abfd ATTRIBUTE_UNUSED,
     = contents = bfd_alloc (bpo_greg_owner, bpo_gregs_section->size);
   if (contents == NULL)
     return false;
+  bpo_gregs_section->alloced = 1;
 
   /* Sanity check: If these numbers mismatch, some relocation has not been
      accounted for and the rest of gregdata is probably inconsistent.
index 44861a058521b46754ebaa191034782cb185c757..fa28a5363785114aa154e01cba93489cdee7b40f 100644 (file)
@@ -6178,6 +6178,7 @@ sfpr_define (struct bfd_link_info *info,
                    = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
                  if (htab->sfpr->contents == NULL)
                    return false;
+                 htab->sfpr->alloced = 1;
                }
            }
        }
@@ -10262,6 +10263,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -10547,6 +10549,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
       s->contents = bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
@@ -10564,6 +10567,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
              s->contents = bfd_zalloc (ibfd, s->size);
              if (s->contents == NULL)
                return false;
+             s->alloced = 1;
            }
        }
       s = ppc64_elf_tdata (ibfd)->relgot;
@@ -10576,6 +10580,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
              s->contents = bfd_zalloc (ibfd, s->size);
              if (s->contents == NULL)
                return false;
+             s->alloced = 1;
              relocs = true;
              s->reloc_count = 0;
            }
@@ -14416,6 +14421,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
       if (p == NULL)
        return false;
       htab->glink_eh_frame->contents = p;
+      htab->glink_eh_frame->alloced = 1;
       last_fde = p;
       align = 4;
 
@@ -14998,6 +15004,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
                                           stub_sec->size);
          if (stub_sec->contents == NULL)
            return false;
+         stub_sec->alloced = 1;
          stub_sec->size = 0;
        }
     }
@@ -15195,6 +15202,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
                                         htab->brlt->size);
       if (htab->brlt->contents == NULL)
        return false;
+      htab->brlt->alloced = 1;
     }
   if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
     {
@@ -15202,6 +15210,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
                                            htab->relbrlt->size);
       if (htab->relbrlt->contents == NULL)
        return false;
+      htab->relbrlt->alloced = 1;
     }
 
   /* Build the stubs as directed by the stub hash table.  */
@@ -15294,6 +15303,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
        = bfd_alloc (htab->elf.dynobj, htab->elf.srelrdyn->size);
       if (htab->elf.srelrdyn->contents == NULL)
        return false;
+      htab->elf.srelrdyn->alloced = 1;
 
       bfd_vma *relr_addr = sort_relr (htab);
       if (htab->relr_count != 0 && relr_addr == NULL)
index 422d89acb873c6c3a285d0a8c7a309c5546ab6fc..27836b87d6f83fc6f22b094151421f6054d641a9 100644 (file)
@@ -1739,6 +1739,7 @@ elf_s390_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -1926,6 +1927,7 @@ elf_s390_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
index 91c77c211ef065a77883004eb696adacd92a00be..d4e890df7345f021adff0859c86f5b77a9693111 100644 (file)
@@ -7044,6 +7044,7 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
          s->contents = (unsigned char *) bfd_alloc (output_bfd, s->size);
          if (s->contents == NULL && s->size != 0)
            return false;
+         s->alloced = 1;
 
          /* Fill in the version definition section.  */
 
@@ -7287,6 +7288,7 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
          s->contents = (unsigned char *) bfd_alloc (output_bfd, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
 
          p = s->contents;
          for (vn = elf_tdata (output_bfd)->verref;
@@ -7824,6 +7826,7 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
          s->contents = (unsigned char *) bfd_zalloc (output_bfd, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
 
          if (!_bfd_elf_add_dynamic_entry (info, DT_VERSYM, 0))
            return false;
@@ -7842,6 +7845,7 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
       s->contents = (unsigned char *) bfd_alloc (output_bfd, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
 
       /* The first entry in .dynsym is a dummy symbol.  Clear all the
         section syms, in case we don't output them all.  */
@@ -7897,6 +7901,7 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
          s->contents = (unsigned char *) bfd_zalloc (output_bfd, s->size);
          if (s->contents == NULL)
            return false;
+         s->alloced = 1;
 
          bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents);
          bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,
@@ -7957,6 +7962,7 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
              if (contents == NULL)
                return false;
              s->contents = contents;
+             s->alloced = 1;
              /* 1 empty bucket.  */
              bfd_put_32 (output_bfd, 1, contents);
              /* SYMIDX above the special symbol 0.  */
@@ -8040,6 +8046,7 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
                }
 
              s->contents = contents;
+             s->alloced = 1;
              bfd_put_32 (output_bfd, bucketcount, contents);
              bfd_put_32 (output_bfd, cinfo.symindx, contents + 4);
              bfd_put_32 (output_bfd, maskwords, contents + 8);
@@ -8376,7 +8383,10 @@ _bfd_elf_link_hash_table_free (bfd *obfd)
   _bfd_merge_sections_free (htab->merge_info);
   /* NB: htab->dynamic->contents is always allocated by bfd_realloc.  */
   if (htab->dynamic != NULL)
-    free (htab->dynamic->contents);
+    {
+      free (htab->dynamic->contents);
+      htab->dynamic->contents = NULL;
+    }
   if (htab->first_hash != NULL)
     {
       bfd_hash_table_free (htab->first_hash);
index f327b7a8a36a55ba11b77eaa6933c09dc45b4ab5..1fe0b615800c09eef2690cb78719593794abf5f1 100644 (file)
@@ -4850,6 +4850,7 @@ elfNN_aarch64_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
 
       /* Add a branch around the stub section, and a nop, to keep it 8 byte
@@ -9406,6 +9407,7 @@ elfNN_aarch64_finish_relative_relocs (struct bfd_link_info *info)
   srelrdyn->contents = bfd_alloc (dynobj, srelrdyn->size);
   if (srelrdyn->contents == NULL)
     return false;
+  srelrdyn->alloced = 1;
   bfd_vma *addr = htab->relr_sorted;
   bfd_byte *loc = srelrdyn->contents;
   for (bfd_size_type i = 0; i < htab->relr_count; )
@@ -9472,6 +9474,7 @@ elfNN_aarch64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -9723,6 +9726,7 @@ elfNN_aarch64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->root.dynamic_sections_created)
index d80fc425642b527ba7394c5301a7a5663e2528ce..36ccfef02914edefaabb7d44bf08187b8a421488 100644 (file)
@@ -3010,6 +3010,7 @@ elfNN_ia64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       sec = bfd_get_linker_section (dynobj, ".interp");
       BFD_ASSERT (sec != NULL);
       sec->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+      sec->alloced = 1;
       sec->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
     }
 
@@ -3184,6 +3185,7 @@ elfNN_ia64_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
          if (sec->contents == NULL && sec->size != 0)
            return false;
+         sec->alloced = 1;
        }
     }
 
index a8d2317ba5e7d766a992b8c1c6aa147d90e5d700..3720c5122c4e8a7cb6a97fdd98e6a7ee4ac69e0a 100644 (file)
@@ -1610,6 +1610,7 @@ elfNN_kvx_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
+      stub_sec->alloced = 1;
       stub_sec->size = 0;
     }
 
@@ -4049,6 +4050,7 @@ elfNN_kvx_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            abort ();
          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -4210,6 +4212,7 @@ elfNN_kvx_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->root.dynamic_sections_created)
index 80d2c445d034bb5b74314c7d48d553b0c3e80bda..efa57184e44f56232fcb75fd816ab79d038ae690 100644 (file)
@@ -2311,6 +2311,7 @@ loongarch_elf_finish_relative_relocs (struct bfd_link_info *info)
   srelrdyn->contents = bfd_alloc (dynobj, srelrdyn->size);
   if (!srelrdyn->contents)
     return false;
+  srelrdyn->alloced = 1;
 
   bfd_vma *addr = htab->relr_sorted;
   bfd_byte *loc = srelrdyn->contents;
@@ -2385,6 +2386,7 @@ loongarch_elf_late_size_sections (bfd *output_bfd,
            interpreter = "/lib/ld.so.1";
 
          s->contents = (unsigned char *) interpreter;
+         s->alloced = 1;
          s->size = strlen (interpreter) + 1;
        }
     }
@@ -2613,6 +2615,7 @@ loongarch_elf_late_size_sections (bfd *output_bfd,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
index c3881bb9eddffaab529f55333d8ef066979995e4..57ced95fdb38a8b2868c0a2952b51c4cc821426a 100644 (file)
@@ -1520,6 +1520,7 @@ riscv_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
          BFD_ASSERT (s != NULL);
          s->size = strlen (ELFNN_DYNAMIC_INTERPRETER) + 1;
          s->contents = (unsigned char *) ELFNN_DYNAMIC_INTERPRETER;
+         s->alloced = 1;
        }
     }
 
@@ -1704,6 +1705,7 @@ riscv_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   /* Add dynamic entries.  */
index fb42c741cbb90e7a4beac0b17e9bed76518df070..e428ae278ba6a0d82117ea210a44fac50fd62a75 100644 (file)
@@ -10001,6 +10001,7 @@ _bfd_mips_elf_late_size_sections (bfd *output_bfd,
            = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1;
          s->contents
            = (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd);
+         s->alloced = 1;
        }
 
       /* Figure out the size of the PLT header if we know that we
@@ -10177,6 +10178,7 @@ _bfd_mips_elf_late_size_sections (bfd *output_bfd,
          bfd_set_error (bfd_error_no_memory);
          return false;
        }
+      s->alloced = 1;
     }
 
   if (htab->root.dynamic_sections_created)
@@ -15405,6 +15407,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 
          o->size = c * sizeof (Elf32_External_gptab);
          o->contents = (bfd_byte *) ext_tab;
+         o->alloced = 1;
 
          /* Skip this section later on (I don't think this currently
             matters, but someday it might).  */
index 91ffece38d043a6523ade68aab6f2844327bbb05..71061621e8bfb561ba33efd0397a7ed53ae20edc 100644 (file)
@@ -2403,6 +2403,7 @@ _bfd_sparc_elf_late_size_sections (bfd *output_bfd,
          BFD_ASSERT (s != NULL);
          s->size = htab->dynamic_interpreter_size;
          s->contents = (unsigned char *) htab->dynamic_interpreter;
+         s->alloced = 1;
          htab->interp = s;
        }
     }
@@ -2579,6 +2580,7 @@ _bfd_sparc_elf_late_size_sections (bfd *output_bfd,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
index 71e917420332e382b7d73ccba274754d9ac30895..afa9e86add58234fb97c0cc8ded1a527d39a784c 100644 (file)
@@ -2452,6 +2452,7 @@ tilegx_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          BFD_ASSERT (s != NULL);
          s->size = strlen (htab->dynamic_interpreter) + 1;
          s->contents = (unsigned char *) htab->dynamic_interpreter;
+         s->alloced = 1;
        }
     }
 
@@ -2617,6 +2618,7 @@ tilegx_elf_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
index cd47575f58910f7cf6be63a68a18219d70b6d888..8d8ee333dbe76d684f3b1fb65eb0f8270270b437 100644 (file)
@@ -1789,6 +1789,7 @@ elf_x86_write_dl_relr_bitmap (struct bfd_link_info *info,
 
   /* Cache the section contents for elf_link_input_bfd.  */
   sec->contents = contents;
+  sec->alloced = 1;
 
   if (ABI_64_P (info->output_bfd))
     for (i = 0; i < htab->dt_relr_bitmap.count; i++, contents += 8)
@@ -2018,6 +2019,7 @@ _bfd_x86_elf_write_sframe_plt (bfd *output_bfd,
 
   sec->size = (bfd_size_type) sec_size;
   sec->contents = (unsigned char *) bfd_zalloc (dynobj, sec->size);
+  sec->alloced = 1;
   memcpy (sec->contents, contents, sec_size);
 
   sframe_encoder_free (&ectx);
@@ -2675,6 +2677,7 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
       s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
        return false;
+      s->alloced = 1;
     }
 
   if (htab->plt_eh_frame != NULL
@@ -4706,6 +4709,7 @@ _bfd_x86_elf_link_setup_gnu_properties
            abort ();
          s->size = htab->dynamic_interpreter_size;
          s->contents = (unsigned char *) htab->dynamic_interpreter;
+         s->alloced = 1;
          htab->interp = s;
        }
 
index ca7dbf23aa680e9beac907b4f6799e5614fe757a..45f774c2c9269015b370a4597b1f3598c9f09924 100644 (file)
@@ -148,18 +148,6 @@ _bfd_new_bfd_contained_in (bfd *obfd)
 static void
 _bfd_delete_bfd (bfd *abfd)
 {
-#ifdef USE_MMAP
-  if (abfd->xvec
-      && abfd->xvec->flavour == bfd_target_elf_flavour)
-    {
-      asection *sec;
-      for (sec = abfd->sections; sec != NULL; sec = sec->next)
-       if (sec->mmapped_p)
-         munmap (elf_section_data (sec)->contents_addr,
-                 elf_section_data (sec)->contents_size);
-    }
-#endif
-
   /* Give the target _bfd_free_cached_info a chance to free memory.  */
   if (abfd->memory && abfd->xvec)
     bfd_free_cached_info (abfd);
index ffd2891129781a77848d3e47f537819407e61f4d..b1f7564d190d3de147eefcabf976d2a0e2b98673 100644 (file)
@@ -422,9 +422,12 @@ CODE_FRAGMENT
 .  {* Nonzero if this section uses RELA relocations, rather than REL.  *}
 .  unsigned int use_rela_p:1;
 .
-.  {* Nonzero if this section contents are mmapped, rather than malloced.  *}
+.  {* Nonzero if section contents are mmapped.  *}
 .  unsigned int mmapped_p:1;
 .
+.  {* Nonzero if section contents should not be freed.  *}
+.  unsigned int alloced:1;
+.
 .  {* Bits used by various backends.  The generic code doesn't touch
 .     these fields.  *}
 .
@@ -716,8 +719,8 @@ EXTERNAL
 .  {* linker_mark, linker_has_input, gc_mark, decompress_status,     *}        \
 .     0,           0,                1,       0,                       \
 .                                                                      \
-.  {* segment_mark, sec_info_type, use_rela_p, mmapped_p,           *} \
-.     0,            0,             0,         0,                       \
+.  {* segment_mark, sec_info_type, use_rela_p, mmapped_p, alloced,   *}        \
+.     0,            0,             0,          0,         0,           \
 .                                                                      \
 .  {* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,    *}        \
 .     0,        0,        0,        0,        0,        0,             \
@@ -1656,6 +1659,10 @@ DESCRIPTION
 bool
 bfd_malloc_and_get_section (bfd *abfd, sec_ptr sec, bfd_byte **buf)
 {
+  /* FIXME: We sometimes get here when sec->alloced is set.
+     arm, aarch64, and xtensa targets all abort on some ld tests
+     if we also test sec->alloced here.  We really should not ever be
+     mallocing a buffer if we already have an alloced one.  */
   if (sec->mmapped_p)
     abort ();
   *buf = NULL;
index f5eb99672c00b31a7ebf8db759d6e36b3a3355d7..548a97901003069457f90d21ec310c877fe6cf91 100644 (file)
@@ -9280,6 +9280,7 @@ alpha_vms_build_fixups (struct bfd_link_info *info)
 
   sec = alpha_vms_link_hash (info)->fixup;
   sec->contents = content;
+  sec->alloced = 1;
   sec->size = sz;
 
   eiaf = (struct vms_eiaf *)content;
@@ -9685,6 +9686,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
          o->contents = bfd_alloc (abfd, o->size);
          if (o->contents == NULL)
            return false;
+         o->alloced = 1;
        }
       if (o->flags & SEC_LOAD)
        {
@@ -9833,6 +9835,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
              if (contents == NULL)
                return false;
              dmt->contents = contents;
+             dmt->alloced = 1;
              dmt->size = off;
            }
          else
@@ -9891,6 +9894,7 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
              sec->flags |= SEC_IN_MEMORY;
              if (sec->contents == NULL)
                return false;
+             sec->alloced = 1;
            }
        }
       if (!alpha_vms_read_sections_content (abfd, NULL))
@@ -10111,6 +10115,7 @@ _bfd_vms_set_section_contents (bfd * abfd,
       section->contents = bfd_alloc (abfd, section->size);
       if (section->contents == NULL)
        return false;
+      section->alloced = 1;
 
       memcpy (section->contents + offset, location, (size_t) count);
     }
index d5d186e07c8b71aae22741f25093a4f6841a6e13..db4b08147a83df9d1faad8542f512328199d2108 100644 (file)
@@ -468,6 +468,7 @@ wasm_scan (bfd *abfd)
                                                  bfdsec->size);
          if (!bfdsec->contents)
            goto error_return;
+         bfdsec->alloced = 1;
        }
 
       vma += bfdsec->size;
index 502cd08a8915bbdaccbfa4c1ef9438bcbd52b69c..14eb008f967d797d7e21a15f28721128ba51f353 100644 (file)
@@ -3990,6 +3990,7 @@ xcoff_build_loader_section (struct xcoff_loader_info *ldinfo)
   lsec->contents = bfd_zalloc (output_bfd, lsec->size);
   if (lsec->contents == NULL)
     return false;
+  lsec->alloced = 1;
 
   /* Set up the header.  */
   bfd_xcoff_swap_ldhdr_out (output_bfd, ldhdr, lsec->contents);
@@ -4062,6 +4063,7 @@ bfd_xcoff_build_dynamic_sections (bfd *output_bfd,
       sec->contents = bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        return false;
+      sec->alloced = 1;
     }
   sec = xcoff_hash_table (info)->toc_section;
   if (sec->size > 0)
@@ -4069,6 +4071,7 @@ bfd_xcoff_build_dynamic_sections (bfd *output_bfd,
       sec->contents = bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        return false;
+      sec->alloced = 1;
     }
   sec = xcoff_hash_table (info)->descriptor_section;
   if (sec->size > 0)
@@ -4076,6 +4079,7 @@ bfd_xcoff_build_dynamic_sections (bfd *output_bfd,
       sec->contents = bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        return false;
+      sec->alloced = 1;
     }
 
   /* Now that we've done garbage collection, decide which symbols to keep,
@@ -4931,7 +4935,7 @@ bfd_xcoff_build_stubs (struct bfd_link_info *info)
       stub_sec->contents = bfd_zalloc (htab->params->stub_bfd, size);
       if (stub_sec->contents == NULL && size != 0)
        return false;
-
+      stub_sec->alloced = 1;
     }
 
   /* Build the stubs as directed by the stub hash table.  */
index c4af01808b6a8206ab8ed35f70758f7690233eba..52080cb5bc1afb091a7680f932579132aaf592ac 100644 (file)
@@ -3076,6 +3076,7 @@ elf_frob_file_after_relocs (void)
       subseg_set (group, 0);
       bfd_set_section_size (group, size);
       group->contents = (unsigned char *) frag_more (size);
+      group->alloced = 1;
       frag_now->fr_fix = frag_now_fix_octets ();
       frag_wane (frag_now);
     }
index 4a1aa044e70bafe1c222efa3543785b5bff13966..d627b55419b6e409a4389a60ce5e81ceb710e024 100644 (file)
@@ -1857,6 +1857,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
       if (default_interpreter_name != NULL)
        {
          sinterp->contents = (bfd_byte *) default_interpreter_name;
+         sinterp->alloced = 1;
          sinterp->size = strlen ((char *) sinterp->contents) + 1;
        }
     }