/* 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. */
/* 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, \
s->size = globals->arm_glue_size;
s->contents = foo;
+ s->alloced = 1;
}
if (globals->thumb_glue_size != 0)
s->size = globals->thumb_glue_size;
s->contents = foo;
+ s->alloced = 1;
}
return true;
sec->size = compressed_size;
sec->compress_status = COMPRESS_SECTION_DONE;
}
+ sec->alloced = 1;
sec->contents = buffer;
sec->flags |= SEC_IN_MEMORY;
free (input_buffer);
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
else
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);
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
*failedptr = true;
return;
}
+ sec->alloced = 1;
}
loc = sec->contents + sec->size;
_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;
}
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",
}
}
#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;
/* 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;
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;
}
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
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);
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;
}
BFD_ASSERT (s->size == size);
s->contents = contents;
+ s->alloced = 1;
}
bool
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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,
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;
}
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)
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;
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)
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,
bfinfdpic_plt_section (info)->size);
if (bfinfdpic_plt_section (info)->contents == NULL)
return false;
+ bfinfdpic_plt_section (info)->alloced = 1;
}
return true;
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
else
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)
relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
if (relsec->contents == NULL)
goto error_return;
+ relsec->alloced = 1;
p = relsec->contents;
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
#endif
}
}
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);
relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
if (relsec->contents == NULL)
goto error_return;
+ relsec->alloced = 1;
p = relsec->contents;
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
else
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);
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->elf.dynamic_sections_created)
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;
}
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))
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;
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))
frvfdpic_pltrel_section (info)->size);
if (frvfdpic_pltrel_section (info)->contents == NULL)
return false;
+ frvfdpic_pltrel_section (info)->alloced = 1;
}
}
frvfdpic_plt_section (info)->size);
if (frvfdpic_plt_section (info)->contents == NULL)
return false;
+ frvfdpic_plt_section (info)->alloced = 1;
}
}
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
abort ();
sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ sec->alloced = 1;
}
/* Force millicode symbols local. */
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);
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;
}
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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))
bfd_zalloc (dynobj, lm32fdpic_fixup32_section (info)->size);
if (lm32fdpic_fixup32_section (info)->contents == NULL)
return false;
+ lm32fdpic_fixup32_section (info)->alloced = 1;
}
}
splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size);
if (splt->contents == NULL)
return false;
+ splt->alloced = 1;
return true;
}
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
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;
}
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
else
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);
relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
if (relsec->contents == NULL)
goto error_return;
+ relsec->alloced = 1;
p = relsec->contents;
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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;
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;
}
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? */
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->elf.dynamic_sections_created)
splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size);
if (splt->contents == NULL)
return false;
+ splt->alloced = 1;
return true;
}
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
BFD_ASSERT (s != NULL);
s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
bfd_set_error (bfd_error_no_memory);
return false;
}
+ s->alloced = 1;
}
if (elf_hash_table (info)->dynamic_sections_created)
BFD_ASSERT (s != NULL);
s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
bfd_set_error (bfd_error_no_memory);
return false;
}
+ s->alloced = 1;
}
if (elf_hash_table (info)->dynamic_sections_created)
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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,
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)
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;
}
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)
htab->init->size);
if (htab->init->contents == NULL)
return false;
+ htab->init->alloced = 1;
h = define_ovtab_symbol (htab, "__icache_fileoff");
if (h == NULL)
sfixup->contents = (bfd_byte *) bfd_zalloc (info->input_bfds, size);
if (sfixup->contents == NULL)
return false;
+ sfixup->alloced = 1;
}
return true;
}
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->elf.dynamic_sections_created)
BFD_ASSERT (s != NULL);
s->size = sizeof ELF32_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF32_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
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++)
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
splt->contents = bfd_zalloc (dynobj, splt->size);
if (splt->contents == NULL)
return false;
+ splt->alloced = 1;
return true;
}
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
/* Allocate room for one word in ".got". */
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
}
s->contents = (bfd_byte *) bfd_zalloc (i, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
}
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
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
}
BFD_ASSERT (sec != NULL);
sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ sec->alloced = 1;
}
}
else
sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
if (sec->contents == NULL)
return false;
+ sec->alloced = 1;
}
}
}
ia64_info->note_sec->contents = note_contents;
+ ia64_info->note_sec->alloced = 1;
ia64_info->note_sec->size = note_size;
free (module_name);
sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
if (sec->contents == NULL && sec->size != 0)
return false;
+ sec->alloced = 1;
}
}
= 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.
= bfd_alloc (htab->elf.dynobj, SFPR_MAX);
if (htab->sfpr->contents == NULL)
return false;
+ htab->sfpr->alloced = 1;
}
}
}
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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)
s->contents = bfd_zalloc (ibfd, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
}
s = ppc64_elf_tdata (ibfd)->relgot;
s->contents = bfd_zalloc (ibfd, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
relocs = true;
s->reloc_count = 0;
}
if (p == NULL)
return false;
htab->glink_eh_frame->contents = p;
+ htab->glink_eh_frame->alloced = 1;
last_fde = p;
align = 4;
stub_sec->size);
if (stub_sec->contents == NULL)
return false;
+ stub_sec->alloced = 1;
stub_sec->size = 0;
}
}
htab->brlt->size);
if (htab->brlt->contents == NULL)
return false;
+ htab->brlt->alloced = 1;
}
if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
{
htab->relbrlt->size);
if (htab->relbrlt->contents == NULL)
return false;
+ htab->relbrlt->alloced = 1;
}
/* Build the stubs as directed by the stub hash table. */
= 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)
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
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);
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. */
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;
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;
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. */
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,
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. */
}
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);
_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);
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
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; )
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->root.dynamic_sections_created)
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;
}
sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
if (sec->contents == NULL && sec->size != 0)
return false;
+ sec->alloced = 1;
}
}
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;
}
abort ();
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->root.dynamic_sections_created)
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;
interpreter = "/lib/ld.so.1";
s->contents = (unsigned char *) interpreter;
+ s->alloced = 1;
s->size = strlen (interpreter) + 1;
}
}
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)
BFD_ASSERT (s != NULL);
s->size = strlen (ELFNN_DYNAMIC_INTERPRETER) + 1;
s->contents = (unsigned char *) ELFNN_DYNAMIC_INTERPRETER;
+ s->alloced = 1;
}
}
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
/* Add dynamic entries. */
= 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
bfd_set_error (bfd_error_no_memory);
return false;
}
+ s->alloced = 1;
}
if (htab->root.dynamic_sections_created)
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). */
BFD_ASSERT (s != NULL);
s->size = htab->dynamic_interpreter_size;
s->contents = (unsigned char *) htab->dynamic_interpreter;
+ s->alloced = 1;
htab->interp = s;
}
}
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)
BFD_ASSERT (s != NULL);
s->size = strlen (htab->dynamic_interpreter) + 1;
s->contents = (unsigned char *) htab->dynamic_interpreter;
+ s->alloced = 1;
}
}
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);
/* 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)
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);
s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
return false;
+ s->alloced = 1;
}
if (htab->plt_eh_frame != NULL
abort ();
s->size = htab->dynamic_interpreter_size;
s->contents = (unsigned char *) htab->dynamic_interpreter;
+ s->alloced = 1;
htab->interp = s;
}
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);
. {* 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. *}
.
. {* 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, \
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;
sec = alpha_vms_link_hash (info)->fixup;
sec->contents = content;
+ sec->alloced = 1;
sec->size = sz;
eiaf = (struct vms_eiaf *)content;
o->contents = bfd_alloc (abfd, o->size);
if (o->contents == NULL)
return false;
+ o->alloced = 1;
}
if (o->flags & SEC_LOAD)
{
if (contents == NULL)
return false;
dmt->contents = contents;
+ dmt->alloced = 1;
dmt->size = off;
}
else
sec->flags |= SEC_IN_MEMORY;
if (sec->contents == NULL)
return false;
+ sec->alloced = 1;
}
}
if (!alpha_vms_read_sections_content (abfd, NULL))
section->contents = bfd_alloc (abfd, section->size);
if (section->contents == NULL)
return false;
+ section->alloced = 1;
memcpy (section->contents + offset, location, (size_t) count);
}
bfdsec->size);
if (!bfdsec->contents)
goto error_return;
+ bfdsec->alloced = 1;
}
vma += bfdsec->size;
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);
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)
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)
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,
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. */
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);
}
if (default_interpreter_name != NULL)
{
sinterp->contents = (bfd_byte *) default_interpreter_name;
+ sinterp->alloced = 1;
sinterp->size = strlen ((char *) sinterp->contents) + 1;
}
}