diff options
author | Alan Modra <amodra@gmail.com> | 2025-01-13 20:33:54 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-01-20 07:13:46 +1030 |
commit | 3a8864b3aa87330412f956a6ce233209eba133c8 (patch) | |
tree | 07c3dcea730b90f3852ff1453c6ccdb7f2fd4e42 /bfd/elf32-ppc.c | |
parent | cb6326b5ceb7cfc784003c05b90b351d78c755fd (diff) | |
download | binutils-3a8864b3aa87330412f956a6ce233209eba133c8.zip binutils-3a8864b3aa87330412f956a6ce233209eba133c8.tar.gz binutils-3a8864b3aa87330412f956a6ce233209eba133c8.tar.bz2 |
reloc caching
This arranges to free section relocs cached in elf_section_data. To
do that, some relocs stored there need to use bfd_malloc buffers
rather than bfd_alloc ones.
* elf.c (_bfd_elf_free_cached_info): Free relocs.
* elf32-ppc.c (ppc_elf_relax_section): Realloc relocs rather
than malloc, copy, free old.
* elf64-ppc.c (get_relocs): bfd_malloc relocs.
* elflink.c (_bfd_elf_link_info_read_relocs): Always
bfd_malloc relocs.
Diffstat (limited to 'bfd/elf32-ppc.c')
-rw-r--r-- | bfd/elf32-ppc.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 25cb31b..f17effd 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -6629,26 +6629,15 @@ ppc_elf_relax_section (bfd *abfd, { /* Append sufficient NOP relocs so we can write out relocation information for the trampolines. */ - Elf_Internal_Shdr *rel_hdr; - Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count) - * sizeof (*new_relocs)); - unsigned ix; - - if (!new_relocs) + size_t old_size = isec->reloc_count * sizeof (*internal_relocs); + size_t extra_size = changes * sizeof (*internal_relocs); + internal_relocs = bfd_realloc (internal_relocs, old_size + extra_size); + elf_section_data (isec)->relocs = internal_relocs; + if (!internal_relocs) goto error_return; - memcpy (new_relocs, internal_relocs, - isec->reloc_count * sizeof (*new_relocs)); - for (ix = changes; ix--;) - { - irel = new_relocs + ix + isec->reloc_count; - - irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); - } - if (internal_relocs != elf_section_data (isec)->relocs) - free (internal_relocs); - elf_section_data (isec)->relocs = new_relocs; + memset ((char *) internal_relocs + old_size, 0, extra_size); isec->reloc_count += changes; - rel_hdr = _bfd_elf_single_rel_hdr (isec); + Elf_Internal_Shdr *rel_hdr = _bfd_elf_single_rel_hdr (isec); rel_hdr->sh_size += changes * rel_hdr->sh_entsize; } else if (elf_section_data (isec)->relocs != internal_relocs) |