[PATCH 21/21] Fix gold linker build issues for mingw
Jovan Dmitrovic
jovan.dmitrovic@htecgroup.com
Wed Apr 2 12:18:48 GMT 2025
From: Faraz Shahbazker <fshahbazker@wavecomp.com>
Release branch only.
These functions are not defined as of mingw-w64 v6.0.0, so we
work around them as follows:
mkdtemp: simulate using tempnam and mkdir
link: omit usage and fall back to file copy
NOTE: use of tempnam is a security risk. Find a better solution!!
Cherry-picked cf1e966
from https://github.com/MIPS/binutils-gdb
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Milica Matic <milica.matic@htecgroup.com>
---
gold/plugin.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/gold/plugin.cc b/gold/plugin.cc
index 89f2e3bb182..545c0d96e16 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -509,8 +509,12 @@ Plugin_recorder::init()
// copies of replacement files.
char dir_template[] = "gold-recording-XXXXXX";
#ifdef HAVE_MKDTEMP
- if (mkdtemp(dir_template) == NULL)
- return false;
+ #ifdef __MINGW32__
+ if (mkdir (tmpnam(dir_template)) == 0)
+ #else
+ if (mkdtemp(dir_template) == NULL)
+ #endif
+ return false;
#else
if (mktemp(dir_template) == NULL)
return false;
@@ -574,7 +578,7 @@ link_or_copy_file(const char* inname, const char* outname)
{
static char buf[4096];
-#ifdef HAVE_LINK
+#if defined(HAVE_LINK) && !defined(__MINGW32__)
if (::link(inname, outname) == 0)
return true;
#endif
--
2.34.1
More information about the Binutils
mailing list