]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Tidy elf_mmap_section_contents
authorAlan Modra <amodra@gmail.com>
Wed, 15 Jan 2025 12:51:32 +0000 (23:21 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 15 Jan 2025 23:01:07 +0000 (09:31 +1030)
It is simpler to clear the buffer pointer in the caller than pass
a param that controls clearing.

* elf.c (elf_mmap_section_contents): Remove final_link param.
(_bfd_elf_mmap_section_contents): Instead set *buf to NULL here.
(_bfd_elf_link_mmap_section_contents): Adjust.

bfd/elf.c

index d37f16e974bebec78d5db02a0bf80eb8c6c8c249..1f2b82bfe92066e5f4314a89f08d677a3ac626e7 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -14202,12 +14202,10 @@ _bfd_elf_write_secondary_reloc_section (bfd *abfd, asection *sec)
   return result;
 }
 
-/* Mmap in section contents.  If FINAL_LINK is false, set *BUF to NULL
-   before calling bfd_get_full_section_contents.  */
+/* Mmap in section contents.  */
 
 static bool
-elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf,
-                          bool final_link)
+elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf)
 {
 #ifdef USE_MMAP
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
@@ -14232,17 +14230,11 @@ elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf,
            abort ();
          sec->mmapped_p = 1;
 
-         /* Never use the preallocated buffer if mmapp is used.  */
+         /* We can't use the final link preallocated buffer for mmap.  */
          *buf = NULL;
        }
     }
 #endif
-  /* NB: When this is called from elf_link_input_bfd, FINAL_LINK is
-     true.  If FINAL_LINK is false, *BUF is set to the preallocated
-     buffer if USE_MMAP is undefined and *BUF is set to NULL if
-     USE_MMAP is defined.  */
-  if (!final_link)
-    *buf = NULL;
   bool ret = bfd_get_full_section_contents (abfd, sec, buf);
   if (ret && sec->mmapped_p)
     *buf = sec->contents;
@@ -14254,7 +14246,8 @@ elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf,
 bool
 _bfd_elf_mmap_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **buf)
 {
-  return elf_mmap_section_contents (abfd, sec, buf, false);
+  *buf = NULL;
+  return elf_mmap_section_contents (abfd, sec, buf);
 }
 
 /* Mmap in the full section contents for the final link.  */
@@ -14263,7 +14256,7 @@ bool
 _bfd_elf_link_mmap_section_contents (bfd *abfd, sec_ptr sec,
                                     bfd_byte **buf)
 {
-  return elf_mmap_section_contents (abfd, sec, buf, true);
+  return elf_mmap_section_contents (abfd, sec, buf);
 }
 
 /* Munmap section contents.  */