[PATCH] SHT_GROUP handling: Use _bfd_elf_link_m[un]map_section_contents
Alan Modra
amodra@gmail.com
Thu Jun 27 23:55:24 GMT 2024
On Thu, Jun 27, 2024 at 03:37:55PM -0700, H.J. Lu wrote:
> Use _bfd_elf_link_m[un]map_section_content to mmap in SHT_GROUP section.
I considered using the mmap calls here and decided against it since
I've never seen a group with over 4k elements. Have you?
(_bfd_minimum_mmap_size is typically 16k.)
> * elf.c (process_sht_group_entries): Replace
> bfd_malloc_and_get_section and free with
> _bfd_elf_mmap_section_contents and
> _bfd_elf_munmap_section_contents.
You missed one free. BTW, thanks for critically looking over
process_sht_group_entries. The changes from the previous code are
substantial enough that it could do with more pairs of eyes.
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
> bfd/elf.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/bfd/elf.c b/bfd/elf.c
> index 8bb296f9637..325f43c778a 100644
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -607,7 +607,8 @@ process_sht_group_entries (bfd *abfd,
> unsigned char *contents;
>
> /* Read the raw contents. */
> - if (!bfd_malloc_and_get_section (abfd, ghdr->bfd_section, &contents))
> + if (!_bfd_elf_mmap_section_contents (abfd, ghdr->bfd_section,
> + &contents))
> {
> _bfd_error_handler
> /* xgettext:c-format */
> @@ -693,7 +694,7 @@ process_sht_group_entries (bfd *abfd,
> }
> }
> }
> - free (contents);
> + _bfd_elf_munmap_section_contents (ghdr->bfd_section, contents);
> return true;
> }
>
> --
> 2.45.2
--
Alan Modra
More information about the Binutils
mailing list