summaryrefslogtreecommitdiffstats
path: root/libelf/elf_update.c
diff options
context:
space:
mode:
Diffstat (limited to 'libelf/elf_update.c')
-rw-r--r--libelf/elf_update.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index b6014cdb..4ed899ff 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -80,7 +80,6 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
if (elf->map_address != NULL)
{
-#if HAVE_DECL_POSIX_FALLOCATE
/* When using mmap we want to make sure the file content is
really there. Only using ftruncate might mean the file is
extended, but space isn't allocated yet. This might cause a
@@ -94,15 +93,32 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
ENOSPC. Otherwise we ignore the error and treat it as just hint. */
if (elf->parent == NULL
&& (elf->maximum_size == ~((size_t) 0)
- || (size_t) size > elf->maximum_size)
- && unlikely (posix_fallocate (elf->fildes, 0, size) != 0))
- if (errno == ENOSPC)
- {
- __libelf_seterrno (ELF_E_WRITE_ERROR);
- return -1;
- }
+ || (size_t) size > elf->maximum_size))
+ {
+#if HAVE_DECL_POSIX_FALLOCATE
+ if (unlikely (posix_fallocate (elf->fildes, 0, size) != 0))
+ if (errno == ENOSPC)
+ {
+ __libelf_seterrno (ELF_E_WRITE_ERROR);
+ return -1;
+ }
#endif
+ /* Extend the mmap address if needed. */
+ if (elf->cmd == ELF_C_RDWR_MMAP
+ && (size_t) size > elf->maximum_size)
+ {
+ if (mremap (elf->map_address, elf->maximum_size,
+ size, 0) == MAP_FAILED)
+ {
+ __libelf_seterrno (ELF_E_WRITE_ERROR);
+ return -1;
+ }
+ elf->maximum_size = size;
+ }
+
+ }
+
/* The file is mmaped. */
if ((class == ELFCLASS32
? __elf32_updatemmap (elf, change_bo, shnum)