]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: Handle bmmap failure in _bfd_mmap_read_temporary
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 4 Apr 2024 13:52:27 +0000 (06:52 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 4 Apr 2024 22:35:31 +0000 (15:35 -0700)
iovec->bmmap may return MAP_FAILED, which happens in GDB on objects with
iovec == opncls_iovec.  Update _bfd_mmap_read_temporary to handle
iovec->bmmap failure.

* libbfd.c (_bfd_mmap_read_temporary): Handle iovec->bmmap
failure.

bfd/libbfd.c

index 869f0ed5c6611dd964dbeff1f329d739dbe5b954..5126ee207a8ea7d3a61df7e29db0d116e41fb9b1 100644 (file)
@@ -1205,12 +1205,18 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
                 && (abfd->flags & BFD_PLUGIN) == 0);
   if (use_mmmap)
     {
-      data = _bfd_mmap_readonly_temporary (abfd, size, mmap_base,
-                                          size_p);
-      if (data == NULL || data == MAP_FAILED)
-       abort ();
-      *data_p = data;
-      return true;
+      void *mmaped = _bfd_mmap_readonly_temporary (abfd, size,
+                                                  mmap_base,
+                                                  size_p);
+      /* MAP_FAILED is returned when called from GDB on an object with
+        opncls_iovec.  Use bfd_read in this case.  */
+      if (mmaped != MAP_FAILED)
+       {
+         if (mmaped == NULL)
+           abort ();
+         *data_p = mmaped;
+         return true;
+       }
     }
 #endif