public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [COMMITTED] libelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAP
@ 2022-04-24 17:49 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2022-04-24 17:49 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add a AC_CHECK_FUNCS configure check for mremap. Some systems like
KFreeBSD and the Hurd don't have it. Also add a configure warning
because without mremap elf_update will often fail when ELF_C_RDWR_MMAP
is used. ELF_C_RDWR_MMAP is an elfutils extension to libelf.

https://sourceware.org/bugzilla/show_bug.cgi?id=27337

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog           | 4 ++++
 configure.ac        | 5 ++++-
 libelf/ChangeLog    | 4 ++++
 libelf/elf_update.c | 2 ++
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3357f69b..f0cd28a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-24  Mark Wielaard  <mark@klomp.org>
+
+	* configure.ac (AC_CHECK_FUNCS): Add mremap.
+
 2021-03-20  Mark Wielaard  <mark@klomp.org>
 
 	* configure.ac: Remove -m64 on 32bit target comments for
diff --git a/configure.ac b/configure.ac
index 2418d474..33c4b5e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -435,7 +435,10 @@ AC_CHECK_DECLS([reallocarray],[],[],
                [#define _GNU_SOURCE
                 #include <stdlib.h>])
 
-AC_CHECK_FUNCS([process_vm_readv])
+AC_CHECK_FUNCS([process_vm_readv mremap])
+
+AS_IF([test "x$ac_cv_func_mremap" = "xno"],
+      [AC_MSG_WARN([elf_update needs mremap to support ELF_C_RDWR_MMAP])])
 
 AC_CHECK_HEADERS([error.h])
 AC_CHECK_HEADERS([err.h])
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 985f795d..00d4ac0f 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-24  Mark Wielaard  <mark@klomp.org>
+
+	* elf_update.c (write_file): Check HAVE_MREMAP.
+
 2022-04-01  Mark Wielaard  <mark@klomp.org>
 
 	* libelfP.h (struct Elf_Data_Chunk): Add an int64_t offset field.
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index 9b8867ce..97ca9ca9 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -106,8 +106,10 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t shnum)
 	  if (elf->cmd == ELF_C_RDWR_MMAP
 	      && (size_t) size > elf->maximum_size)
 	    {
+#ifdef HAVE_MREMAP
 	      if (mremap (elf->map_address, elf->maximum_size,
 			  size, 0) == MAP_FAILED)
+#endif
 		{
 		  __libelf_seterrno (ELF_E_WRITE_ERROR);
 		  return -1;
-- 
2.30.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-24 17:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 17:49 [COMMITTED] libelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAP Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).