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]

Re: [PATCH] Fix binutils/gold build on NetBSD


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

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 */

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