Tidy elf_mmap_section_contents

Alan Modra amodra@gmail.com
Wed Jan 15 23:02:15 GMT 2025


It is simpler to clear the buffer pointer in the caller than pass
a param that controls clearing.  Committed.

	* 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.

diff --git a/bfd/elf.c b/bfd/elf.c
index d37f16e974b..1f2b82bfe92 100644
--- 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.  */

-- 
Alan Modra


More information about the Binutils mailing list