summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-01-17 15:55:02 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-01-18 09:46:20 +0000
commit1f1bb33622a517fb674953fedd247fc0d0198f19 (patch)
tree0d2c78664d291ab6f0cd2f7ab6fd634aa64ce427
parent5fdac838ae86f536d12c0b5e7631172d049bd556 (diff)
Use file-based ELF update strategy if posix_fallocate is absent
The whole idea of extending the file and the mmap in place is rather fragile and only works on rather specific setups. If we can't even extend the file, we will likely not be able to extend the mapping that refers to it, either. In that case we might still be able to write the formally undefined memory behind the end of the file because the OS actually maps whole pages, but that is an unspeakable horror. The file based strategy is slower, but robust. Change-Id: I995a173d60cfd70dde08ff78b7a97182e83b4727 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--libelf/elf_update.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index 4ed899ff..3ac38a85 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -67,6 +67,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
return -1;
}
+#if HAVE_DECL_POSIX_FALLOCATE
/* Try to map the file if this isn't done yet. */
if (elf->map_address == NULL && elf->cmd == ELF_C_WRITE_MMAP)
{
@@ -95,14 +96,12 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
&& (elf->maximum_size == ~((size_t) 0)
|| (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
@@ -127,6 +126,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
size = -1;
}
else
+#endif
{
/* The file is not mmaped. */
if ((class == ELFCLASS32