public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix binutils/gold build on NetBSD
@ 2010-12-04  4:47 Arnaud Lacombe
  2010-12-05 20:04 ` Ralf Wildenhues
  2010-12-06 23:26 ` Ian Lance Taylor
  0 siblings, 2 replies; 5+ messages in thread
From: Arnaud Lacombe @ 2010-12-04  4:47 UTC (permalink / raw)
  To: binutils; +Cc: Arnaud Lacombe

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix binutils/gold build on NetBSD
  2010-12-04  4:47 [PATCH] Fix binutils/gold build on NetBSD Arnaud Lacombe
@ 2010-12-05 20:04 ` Ralf Wildenhues
  2010-12-06 23:26 ` Ian Lance Taylor
  1 sibling, 0 replies; 5+ messages in thread
From: Ralf Wildenhues @ 2010-12-05 20:04 UTC (permalink / raw)
  To: Arnaud Lacombe; +Cc: binutils

Hello Arnaud,

* Arnaud Lacombe wrote on Sat, Dec 04, 2010 at 05:47:04AM CET:
> --- 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."

It's actually more portable to write
  choke me

or
  MREMAP_MAYMOVE not defined.

as some compilers only warn over #error, see 'info Autoconf "C
Compiler"'.

> +#endif
> +]])],

If you wrap the whole testing part above in AC_CACHE_CHECK
with a suitable cache variable, and do the actions below:

> +[AC_DEFINE(HAVE_MREMAP_MAYMOVE, 1,
> +[Define to 1 if mremap(2) support the MREMAP_MAYMOVE flag.])],
> +[AC_LIBOBJ(mremap)])

only if that variable has the desired result, then both reruns of
configure are faster, and users can override the result of your test on
systems where it might fail (due to, e.g., portability issues like
above).

Cheers,
Ralf


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix binutils/gold build on NetBSD
  2010-12-04  4:47 [PATCH] Fix binutils/gold build on NetBSD Arnaud Lacombe
  2010-12-05 20:04 ` Ralf Wildenhues
@ 2010-12-06 23:26 ` Ian Lance Taylor
  2010-12-07  0:13   ` Arnaud Lacombe
  1 sibling, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2010-12-06 23:26 UTC (permalink / raw)
  To: Arnaud Lacombe; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 486 bytes --]

Arnaud Lacombe <lacombar@gmail.com> writes:

> 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.

I would prefer to avoid adding the #ifdef to output.cc.  Also, the
configure check should be cached.  Does this patch work for you?

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: foo.patch --]
[-- Type: text/x-diff, Size: 4513 bytes --]

Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gold/configure.ac,v
retrieving revision 1.60
diff -u -r1.60 configure.ac
--- configure.ac	23 Nov 2010 13:39:56 -0000	1.60
+++ configure.ac	6 Dec 2010 23:25:06 -0000
@@ -393,7 +393,20 @@
 AC_SUBST(LFS_CFLAGS)
 
 AC_CHECK_FUNCS(chsize)
-AC_REPLACE_FUNCS(pread ftruncate mremap ffsll)
+AC_REPLACE_FUNCS(pread ftruncate ffsll)
+
+AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
+[AC_LINK_IFELSE([
+AC_LANG_PROGRAM([[
+#include <sys/mman.h>
+void f() { mremap (0, 0, 0, MREMAP_MAYMOVE); }
+]])], [gold_cv_lib_mremap_maymove=yes], [gold_cv_lib_mremap_maymove=no])])
+if test "$gold_cv_lib_mremap_maymove" = "yes"; then
+  AC_DEFINE(HAVE_MREMAP, 1,
+    [Define to 1 if you have the mremap function with MREMAP_MAYMOVE support])
+else
+  AC_LIBOBJ(mremap)
+fi
 
 # Link in zlib if we can.  This allows us to write compressed sections.
 AC_SEARCH_LIBS(zlibVersion, z, [AC_CHECK_HEADERS(zlib.h)])
Index: gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.44
diff -u -r1.44 gold.h
--- gold.h	1 Jun 2010 23:37:57 -0000	1.44
+++ gold.h	6 Dec 2010 23:25:06 -0000
@@ -137,7 +137,8 @@
 
 #ifndef HAVE_MREMAP
 #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);
+#define mremap gold_mremap
 #endif
 
 #ifndef HAVE_FFSLL
Index: mremap.c
===================================================================
RCS file: /cvs/src/src/gold/mremap.c,v
retrieving revision 1.2
diff -u -r1.2 mremap.c
--- mremap.c	28 Mar 2009 05:22:30 -0000	1.2
+++ mremap.c	6 Dec 2010 23:25:06 -0000
@@ -40,11 +40,11 @@
 # 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,
-	int flags ATTRIBUTE_UNUSED, ...)
+gold_mremap (void *old_address, size_t old_size, size_t new_size,
+	     int flags ATTRIBUTE_UNUSED)
 {
   void *ret;
 
Index: configure
===================================================================
RCS file: /cvs/src/src/gold/configure,v
retrieving revision 1.63
diff -u -r1.63 configure
--- configure	23 Nov 2010 13:39:56 -0000	1.63
+++ configure	6 Dec 2010 23:25:07 -0000
@@ -6496,7 +6496,7 @@
 fi
 done
 
-for ac_func in pread ftruncate mremap ffsll
+for ac_func in pread ftruncate ffsll
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -6518,6 +6518,49 @@
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking mremap with MREMAP_MAYMOVE" >&5
+$as_echo_n "checking mremap with MREMAP_MAYMOVE... " >&6; }
+if test "${gold_cv_lib_mremap_maymove+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+#include <sys/mman.h>
+void f() { mremap (0, 0, 0, MREMAP_MAYMOVE); }
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gold_cv_lib_mremap_maymove=yes
+else
+  gold_cv_lib_mremap_maymove=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gold_cv_lib_mremap_maymove" >&5
+$as_echo "$gold_cv_lib_mremap_maymove" >&6; }
+if test "$gold_cv_lib_mremap_maymove" = "yes"; then
+
+$as_echo "#define HAVE_MREMAP 1" >>confdefs.h
+
+else
+  case " $LIBOBJS " in
+  *" mremap.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS mremap.$ac_objext"
+ ;;
+esac
+
+fi
+
 # Link in zlib if we can.  This allows us to write compressed sections.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing zlibVersion" >&5
 $as_echo_n "checking for library containing zlibVersion... " >&6; }
Index: config.in
===================================================================
RCS file: /cvs/src/src/gold/config.in,v
retrieving revision 1.28
diff -u -r1.28 config.in
--- config.in	17 Dec 2009 16:02:02 -0000	1.28
+++ config.in	6 Dec 2010 23:25:07 -0000
@@ -87,7 +87,7 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
-/* Define to 1 if you have the `mremap' function. */
+/* Define to 1 if you have the mremap function with MREMAP_MAYMOVE support */
 #undef HAVE_MREMAP
 
 /* Define if compiler supports #pragma omp threadprivate */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix binutils/gold build on NetBSD
  2010-12-06 23:26 ` Ian Lance Taylor
@ 2010-12-07  0:13   ` Arnaud Lacombe
  2010-12-07  0:24     ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaud Lacombe @ 2010-12-07  0:13 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

Hi,

On Mon, Dec 6, 2010 at 6:26 PM, Ian Lance Taylor <iant@google.com> wrote:
> Arnaud Lacombe <lacombar@gmail.com> writes:
>
>> 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.
>
> I would prefer to avoid adding the #ifdef to output.cc.  Also, the
> configure check should be cached.  Does this patch work for you?
>
I did not test it yet, but I would expect it to work. I will confirm
that later on.

In the mean time, shouldn't this kind of portability call go to libiberty ?

Thanks,
 - Arnaud

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix binutils/gold build on NetBSD
  2010-12-07  0:13   ` Arnaud Lacombe
@ 2010-12-07  0:24     ` Ian Lance Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2010-12-07  0:24 UTC (permalink / raw)
  To: Arnaud Lacombe; +Cc: binutils

Arnaud Lacombe <lacombar@gmail.com> writes:

> In the mean time, shouldn't this kind of portability call go to libiberty ?

I would personally only be inclined to put it in libiberty if it were a
proper reimplementation of mremap.  Since gold does not require a proper
reimplementation, the gold-specific version seems appropriate to me.
Also there's a good chance to no other program which uses libiberty will
want to use mremap, which is another reason to keep it in gold.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-12-07  0:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-04  4:47 [PATCH] Fix binutils/gold build on NetBSD Arnaud Lacombe
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

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).