public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Arnaud Lacombe <lacombar@gmail.com>
To: binutils@sourceware.org
Cc: Arnaud Lacombe <lacombar@gmail.com>
Subject: [PATCH] Fix binutils/gold build on NetBSD
Date: Sat, 04 Dec 2010 04:47:00 -0000	[thread overview]
Message-ID: <1291438024-7921-1-git-send-email-lacombar@gmail.com> (raw)

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

             reply	other threads:[~2010-12-04  4:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-04  4:47 Arnaud Lacombe [this message]
2010-12-05 20:04 ` Ralf Wildenhues
2010-12-06 23:26 ` Ian Lance Taylor
2010-12-07  0:13   ` Arnaud Lacombe
2010-12-07  0:24     ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291438024-7921-1-git-send-email-lacombar@gmail.com \
    --to=lacombar@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).