[PATCH] bfd: Handle bmmap failure in _bfd_mmap_read_temporary
H.J. Lu
hjl.tools@gmail.com
Wed Apr 3 22:37:44 GMT 2024
bmmap may return MAP_FAILED. _bfd_mmap_readonly_temporary returns
MAP_FAILED when called from GDB on an object with opncls_iovec. Update
_bfd_mmap_read_temporary to handle bmmap failure.
* libbfd.c (_bfd_mmap_read_temporary): Handle bmmap failure.
---
bfd/libbfd.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 869f0ed5c66..34197b75b5e 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1207,7 +1207,11 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
{
data = _bfd_mmap_readonly_temporary (abfd, size, mmap_base,
size_p);
- if (data == NULL || data == MAP_FAILED)
+ /* MAP_FAILED is returned when called from GDB on an object with
+ opncls_iovec. Use bfd_read in this case. */
+ if (data == MAP_FAILED)
+ goto mmap_failed;
+ if (data == NULL)
abort ();
*data_p = data;
return true;
@@ -1216,6 +1220,7 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
if (data == NULL)
{
+mmap_failed:
data = bfd_malloc (size);
if (data == NULL)
return false;
--
2.44.0
More information about the Gdb-patches
mailing list