2.31 breaks build of 'gold' for x86_64-w64-mingw32

Message ID fea693af-38e8-393f-9699-d7b925aa501f@att.net
State Superseded
Headers show
Series
  • 2.31 breaks build of 'gold' for x86_64-w64-mingw32
Related show

Commit Message

Alexey Neyman Oct. 7, 2018, 8:50 p.m.
Hi,

Canadian cross for x86_64-w64-mingw32 host (in crosstool-NG) has been 
failing to build gold because the mkdtemp and link functions are not 
available.

Patch attached. Replacement code for mkdtemp stolen from 
binutils/bucomm.c; link() call is just placed under an appropriate 
ifdef, as the function already has a fallback (copying the file).

Regards,
Alexey.

Comments

Cary Coutant Oct. 24, 2018, 1:03 a.m. | #1
> Patch attached. Replacement code for mkdtemp stolen from

> binutils/bucomm.c; link() call is just placed under an appropriate

> ifdef, as the function already has a fallback (copying the file).


+AC_CHECK_FUNCS(chsize mmap link)
...
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
+AC_CHECK_FUNC([mkdtemp],
+              AC_DEFINE([HAVE_MKDTEMP], 1,
+              [Define to 1 if you have the `mkdtemp' function.]))

Is there a reason why you didn't just add mkdtemp to one of the
AC_CHECK_FUNCS macros?

-cary
Alexey Neyman Oct. 30, 2018, 5:10 a.m. | #2
On 10/23/2018 06:03 PM, Cary Coutant wrote:
>> Patch attached. Replacement code for mkdtemp stolen from

>> binutils/bucomm.c; link() call is just placed under an appropriate

>> ifdef, as the function already has a fallback (copying the file).

> +AC_CHECK_FUNCS(chsize mmap link)

> ..

>   AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)

> +AC_CHECK_FUNC([mkdtemp],

> +              AC_DEFINE([HAVE_MKDTEMP], 1,

> +              [Define to 1 if you have the `mkdtemp' function.]))

>

> Is there a reason why you didn't just add mkdtemp to one of the

> AC_CHECK_FUNCS macros?

No specific reason, just copy-pasted from the same check in 
binutils/configure.ac.

Included into the AC_CHECK_FUNCS right above; updated patch attached.

Regards,
Alexey.
From 39f83bb42ba5978f0ed6bc4d2d58664ea01054a7 Mon Sep 17 00:00:00 2001
From: Alexey Neyman <stilor@att.net>

Date: Sun, 7 Oct 2018 11:57:49 -0700
Subject: [PATCH] Restore build on x86_64-w64-mingw32

	* gold/configure.ac: Add checks for link, mkdtemp.
	* gold/configure: Regenerated.
	* gold/config.in: Regenerated.
	* gold/plugin.cc (Plugin_recorder::init): Fall back to mktemp
	if mkdtemp is not available.
	(link_or_copy_file): Fall back to copy if link() is not available.

Signed-off-by: Alexey Neyman <stilor@att.net>

---
 gold/config.in    |  6 ++++++
 gold/configure    |  9 ++++++++-
 gold/configure.ac |  5 ++++-
 gold/plugin.cc    | 14 ++++++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gold/config.in b/gold/config.in
index 2b53d71185..7bac34aab2 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -103,6 +103,9 @@
 /* Define if your <locale.h> file defines LC_MESSAGES. */
 #undef HAVE_LC_MESSAGES
 
+/* Define to 1 if you have the `link' function. */
+#undef HAVE_LINK
+
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 
@@ -112,6 +115,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
diff --git a/gold/configure b/gold/configure
index a57025bd0b..c83a96682a 100755
--- a/gold/configure
+++ b/gold/configure
@@ -7977,7 +7977,7 @@ fi
 
 done
 
-for ac_func in chsize mmap
+for ac_func in chsize mmap link
 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"
@@ -9878,6 +9878,13 @@ _ACEOF
 fi
 done
 
+ac_fn_cxx_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
+if test "x$ac_cv_func_mkdtemp" = xyes; then :
+
+$as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h
+
+fi
+
 ac_fn_cxx_check_decl "$LINENO" "basename" "ac_cv_have_decl_basename" "$ac_includes_default"
 if test "x$ac_cv_have_decl_basename" = xyes; then :
   ac_have_decl=1
diff --git a/gold/configure.ac b/gold/configure.ac
index d9a1869070..50b540eb21 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -529,7 +529,7 @@ LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 AC_SUBST(LFS_CFLAGS)
 
 AC_CHECK_HEADERS(sys/mman.h)
-AC_CHECK_FUNCS(chsize mmap)
+AC_CHECK_FUNCS(chsize mmap link)
 AC_REPLACE_FUNCS(pread ftruncate ffsll)
 
 AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
@@ -614,6 +614,9 @@ esac
 AC_SUBST(DLOPEN_LIBS)
 
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
+AC_CHECK_FUNC([mkdtemp],
+              AC_DEFINE([HAVE_MKDTEMP], 1,
+              [Define to 1 if you have the `mkdtemp' function.]))
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 3415b914ad..70b83b4713 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -508,8 +508,20 @@ Plugin_recorder::init()
   // Create a temporary directory where we can stash the log and
   // copies of replacement files.
   char dir_template[] = "gold-recording-XXXXXX";
+#ifdef HAVE_MKDTEMP
   if (mkdtemp(dir_template) == NULL)
     return false;
+#else
+  if (mktemp(dir_template) == NULL)
+    return false;
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+  if (mkdir(dir_template) != 0)
+    return false;
+#else
+  if (mkdir(dir_template, 0700) != 0)
+    return false;
+#endif
+#endif
 
   size_t len = strlen(dir_template) + 1;
   char* tempdir = new char[len];
@@ -562,8 +574,10 @@ link_or_copy_file(const char* inname, const char* outname)
 {
   static char buf[4096];
 
+#ifdef HAVE_LINK
   if (::link(inname, outname) == 0)
     return true;
+#endif
 
   int in = ::open(inname, O_RDONLY);
   if (in < 0)
-- 
2.14.1
Cary Coutant Nov. 7, 2018, 7:05 p.m. | #3
> Included into the AC_CHECK_FUNCS right above; updated patch attached.


        * gold/configure.ac: Add checks for link, mkdtemp.
        * gold/configure: Regenerated.
        * gold/config.in: Regenerated.
        * gold/plugin.cc (Plugin_recorder::init): Fall back to mktemp
        if mkdtemp is not available.
        (link_or_copy_file): Fall back to copy if link() is not available.

This is OK. Thanks!

-cary
Alexey Neyman Nov. 7, 2018, 8:10 p.m. | #4
On 11/07/2018 11:05 AM, Cary Coutant wrote:
>> Included into the AC_CHECK_FUNCS right above; updated patch attached.

>          * gold/configure.ac: Add checks for link, mkdtemp.

>          * gold/configure: Regenerated.

>          * gold/config.in: Regenerated.

>          * gold/plugin.cc (Plugin_recorder::init): Fall back to mktemp

>          if mkdtemp is not available.

>          (link_or_copy_file): Fall back to copy if link() is not available.

>

> This is OK. Thanks!

I noticed that I accidentally attached the first version of the patch, 
not updated (forgot to copy the updated patch from the build machine).

Really, really updated patch attached now :)

Sorry about this confusion,
Alexey.
From 52eff2b13fbdc8970fe73f2e1e26217c24f4ffdc Mon Sep 17 00:00:00 2001
From: Alexey Neyman <stilor@att.net>

Date: Sun, 7 Oct 2018 11:57:49 -0700
Subject: [PATCH] Restore build on x86_64-w64-mingw32

	* gold/configure.ac: Add checks for link, mkdtemp.
	* gold/configure: Regenerated.
	* gold/config.in: Regenerated.
	* gold/plugin.cc (Plugin_recorder::init): Fall back to mktemp
	if mkdtemp is not available.
	(link_or_copy_file): Fall back to copy if link() is not available.

Signed-off-by: Alexey Neyman <stilor@att.net>

---
 gold/config.in    |  6 ++++++
 gold/configure    |  4 ++--
 gold/configure.ac |  4 ++--
 gold/plugin.cc    | 14 ++++++++++++++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/gold/config.in b/gold/config.in
index 2b53d71185..7bac34aab2 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -103,6 +103,9 @@
 /* Define if your <locale.h> file defines LC_MESSAGES. */
 #undef HAVE_LC_MESSAGES
 
+/* Define to 1 if you have the `link' function. */
+#undef HAVE_LINK
+
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 
@@ -112,6 +115,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
diff --git a/gold/configure b/gold/configure
index a57025bd0b..216af10f3e 100755
--- a/gold/configure
+++ b/gold/configure
@@ -7977,7 +7977,7 @@ fi
 
 done
 
-for ac_func in chsize mmap
+for ac_func in chsize mmap link
 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"
@@ -9866,7 +9866,7 @@ case "$ac_cv_search_dlopen" in
 esac
 
 
-for ac_func in mallinfo posix_fallocate fallocate readv sysconf times
+for ac_func in mallinfo posix_fallocate fallocate readv sysconf times mkdtemp
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gold/configure.ac b/gold/configure.ac
index d9a1869070..6ab43b9359 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -529,7 +529,7 @@ LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 AC_SUBST(LFS_CFLAGS)
 
 AC_CHECK_HEADERS(sys/mman.h)
-AC_CHECK_FUNCS(chsize mmap)
+AC_CHECK_FUNCS(chsize mmap link)
 AC_REPLACE_FUNCS(pread ftruncate ffsll)
 
 AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
@@ -613,7 +613,7 @@ case "$ac_cv_search_dlopen" in
 esac
 AC_SUBST(DLOPEN_LIBS)
 
-AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
+AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times mkdtemp)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 3415b914ad..70b83b4713 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -508,8 +508,20 @@ Plugin_recorder::init()
   // Create a temporary directory where we can stash the log and
   // copies of replacement files.
   char dir_template[] = "gold-recording-XXXXXX";
+#ifdef HAVE_MKDTEMP
   if (mkdtemp(dir_template) == NULL)
     return false;
+#else
+  if (mktemp(dir_template) == NULL)
+    return false;
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+  if (mkdir(dir_template) != 0)
+    return false;
+#else
+  if (mkdir(dir_template, 0700) != 0)
+    return false;
+#endif
+#endif
 
   size_t len = strlen(dir_template) + 1;
   char* tempdir = new char[len];
@@ -562,8 +574,10 @@ link_or_copy_file(const char* inname, const char* outname)
 {
   static char buf[4096];
 
+#ifdef HAVE_LINK
   if (::link(inname, outname) == 0)
     return true;
+#endif
 
   int in = ::open(inname, O_RDONLY);
   if (in < 0)
-- 
2.14.1

Patch

From be07c0ea2b943fe0bc8009432eadf157bbc2b718 Mon Sep 17 00:00:00 2001
From: Alexey Neyman <stilor@att.net>
Date: Sun, 7 Oct 2018 11:57:49 -0700
Subject: [PATCH] Restore build on x86_64-w64-mingw32

	* gold/configure.ac: Add checks for link, mkdtemp.
	* gold/configure: Regenerated.
	* gold/config.in: Regenerated.
	* gold/plugin.cc (Plugin_recorder::init): Fall back to mktemp
	if mkdtemp is not available.
	(link_or_copy_file): Fall back to copy if link() is not available.

Signed-off-by: Alexey Neyman <stilor@att.net>
---
 gold/config.in    |  6 ++++++
 gold/configure    |  9 ++++++++-
 gold/configure.ac |  5 ++++-
 gold/plugin.cc    | 14 ++++++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gold/config.in b/gold/config.in
index 2b53d71185..7bac34aab2 100644
--- a/gold/config.in
+++ b/gold/config.in
@@ -103,6 +103,9 @@ 
 /* Define if your <locale.h> file defines LC_MESSAGES. */
 #undef HAVE_LC_MESSAGES
 
+/* Define to 1 if you have the `link' function. */
+#undef HAVE_LINK
+
 /* Define to 1 if you have the <locale.h> header file. */
 #undef HAVE_LOCALE_H
 
@@ -112,6 +115,9 @@ 
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
diff --git a/gold/configure b/gold/configure
index a57025bd0b..c83a96682a 100755
--- a/gold/configure
+++ b/gold/configure
@@ -7977,7 +7977,7 @@  fi
 
 done
 
-for ac_func in chsize mmap
+for ac_func in chsize mmap link
 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"
@@ -9878,6 +9878,13 @@  _ACEOF
 fi
 done
 
+ac_fn_cxx_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
+if test "x$ac_cv_func_mkdtemp" = xyes; then :
+
+$as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h
+
+fi
+
 ac_fn_cxx_check_decl "$LINENO" "basename" "ac_cv_have_decl_basename" "$ac_includes_default"
 if test "x$ac_cv_have_decl_basename" = xyes; then :
   ac_have_decl=1
diff --git a/gold/configure.ac b/gold/configure.ac
index d9a1869070..50b540eb21 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -529,7 +529,7 @@  LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 AC_SUBST(LFS_CFLAGS)
 
 AC_CHECK_HEADERS(sys/mman.h)
-AC_CHECK_FUNCS(chsize mmap)
+AC_CHECK_FUNCS(chsize mmap link)
 AC_REPLACE_FUNCS(pread ftruncate ffsll)
 
 AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
@@ -614,6 +614,9 @@  esac
 AC_SUBST(DLOPEN_LIBS)
 
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
+AC_CHECK_FUNC([mkdtemp],
+              AC_DEFINE([HAVE_MKDTEMP], 1,
+              [Define to 1 if you have the `mkdtemp' function.]))
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 3415b914ad..70b83b4713 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -508,8 +508,20 @@  Plugin_recorder::init()
   // Create a temporary directory where we can stash the log and
   // copies of replacement files.
   char dir_template[] = "gold-recording-XXXXXX";
+#ifdef HAVE_MKDTEMP
   if (mkdtemp(dir_template) == NULL)
     return false;
+#else
+  if (mktemp(dir_template) == NULL)
+    return false;
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+  if (mkdir(dir_template) != 0)
+    return false;
+#else
+  if (mkdir(dir_template, 0700) != 0)
+    return false;
+#endif
+#endif
 
   size_t len = strlen(dir_template) + 1;
   char* tempdir = new char[len];
@@ -562,8 +574,10 @@  link_or_copy_file(const char* inname, const char* outname)
 {
   static char buf[4096];
 
+#ifdef HAVE_LINK
   if (::link(inname, outname) == 0)
     return true;
+#endif
 
   int in = ::open(inname, O_RDONLY);
   if (in < 0)
-- 
2.14.1