This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix binutils/gold build on NetBSD


Hi *,

This patch intends to fix gold build on NetBSD host. NetBSD supports mremap(2),
but does not support MREMAP_MAYMOVE flags.

This patch renames gold's internal version of mremap to avoid namespace conflict
as prototypes differs and add an additionnal configure-time check for
MREMAP_MAYMOVE.

 - Arnaud

ps: this patch has been wandering around on my disk for quite some time, but as
it still applies cleanly, I guess the issue still exists. I'll be able to
confirm next time I use gold.

ps2: yes, I know, the configure script is not regenerated. and this mail is
not in the proper changelog format, but I'm not a particular fan of the
change itself (in particular the rename), a better solution certainly exist.

---
 gold/configure.ac |   11 +++++++++++
 gold/gold.h       |    4 ++--
 gold/mremap.c     |    4 ++--
 gold/output.cc    |    5 +++++
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gold/configure.ac b/gold/configure.ac
index 2c50d97..46e526b 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -395,6 +395,17 @@ AC_SUBST(LFS_CFLAGS)
 AC_CHECK_FUNCS(chsize)
 AC_REPLACE_FUNCS(pread ftruncate mremap ffsll)
 
+AC_COMPILE_IFELSE([
+AC_LANG_PROGRAM([[
+#include <sys/mman.h>
+#ifndef MREMAP_MAYMOVE
+#error "MREMAP_MAYMOVE not defined."
+#endif
+]])],
+[AC_DEFINE(HAVE_MREMAP_MAYMOVE, 1,
+[Define to 1 if mremap(2) support the MREMAP_MAYMOVE flag.])],
+[AC_LIBOBJ(mremap)])
+
 # Link in zlib if we can.  This allows us to write compressed sections.
 AC_SEARCH_LIBS(zlibVersion, z, [AC_CHECK_HEADERS(zlib.h)])
 AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_search_zlibVersion" != "no")
diff --git a/gold/gold.h b/gold/gold.h
index 90f1f7d..a457bc8 100644
--- a/gold/gold.h
+++ b/gold/gold.h
@@ -135,9 +135,9 @@ extern "C" ssize_t pread(int, void*, size_t, off_t);
 extern "C" int ftruncate(int, off_t);
 #endif
 
-#ifndef HAVE_MREMAP
+#if !defined(HAVE_MREMAP) || !defined(HAVE_MREMAP_MAYMOVE)
 #define MREMAP_MAYMOVE 1
-extern "C" void *mremap(void *, size_t, size_t, int, ...);
+extern "C" void *gold_mremap(void *, size_t, size_t, int, ...);
 #endif
 
 #ifndef HAVE_FFSLL
diff --git a/gold/mremap.c b/gold/mremap.c
index 332fded..632bfc8 100644
--- a/gold/mremap.c
+++ b/gold/mremap.c
@@ -40,10 +40,10 @@
 # define MAP_ANONYMOUS MAP_ANON
 #endif
 
-extern void *mremap (void *, size_t, size_t, int, ...);
+extern void *gold_mremap (void *, size_t, size_t, int, ...);
 
 void *
-mremap (void *old_address, size_t old_size, size_t new_size,
+gold_mremap (void *old_address, size_t old_size, size_t new_size,
 	int flags ATTRIBUTE_UNUSED, ...)
 {
   void *ret;
diff --git a/gold/output.cc b/gold/output.cc
index 1158a77..cd75a98 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -4349,8 +4349,13 @@ Output_file::resize(off_t file_size)
   // to unmap to flush to the file, then remap after growing the file.
   if (this->map_is_anonymous_)
     {
+#if defined(HAVE_MREMAP) && defined(HAVE_MREMAP_MAYMOVE)
       void* base = ::mremap(this->base_, this->file_size_, file_size,
                             MREMAP_MAYMOVE);
+#else
+      void* base = ::gold_mremap(this->base_, this->file_size_, file_size,
+                            MREMAP_MAYMOVE);
+#endif
       if (base == MAP_FAILED)
         gold_fatal(_("%s: mremap: %s"), this->name_, strerror(errno));
       this->base_ = static_cast<unsigned char*>(base);
-- 
1.7.2.30.gc37d7.dirty


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]