public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* gold work on mingw/mingw64 support
@ 2010-12-30 18:19 Vladimir Simonov
  2010-12-30 18:24 ` Ralf Wildenhues
  2010-12-30 19:26 ` Ian Lance Taylor
  0 siblings, 2 replies; 19+ messages in thread
From: Vladimir Simonov @ 2010-12-30 18:19 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

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

Hi,

Attaching the patch which allows to build gold working
in mingw/mingw64 environment.

The patch's idea is to provide restricted emulation for
Linux-specific calls, like mremap, mremap, etc. And force
callers always to keep files in-memory.

Yes, this approach is a bit memory consuming but
IMO it is not a problem, especially for mingw64.
Really, for 32-bit Windows cygwin-based gold may be used.

It is a port of my patch against binutils 2.20.1 and
it was not tested deep. Original patch works
quite well - I saw only debug-info messing in very
large programs.

What do you think about this approach and the patch itself?

Thanks in advance
Vladimir Simonov


[-- Attachment #2: binutils-2.21-gold-migw.patch --]
[-- Type: text/plain, Size: 5831 bytes --]

diff -ruN binutils-2.21//gold/descriptors.cc ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/descriptors.cc
--- binutils-2.21//gold/descriptors.cc	2010-07-14 14:38:59.000000000 +0400
+++ binutils-2.21/gold/descriptors.cc	2010-12-29 11:41:04.744856600 +0300
@@ -130,10 +130,12 @@
 	  // header file but not supported by the kernel.
 	  // Unfortunately there doesn't seem to be any obvious way to
 	  // detect that, as unknown flags passed to open are ignored.
+#ifndef __MINGW32__
 	  if (O_CLOEXEC == 0
 	      && parameters->options_valid()
 	      && parameters->options().has_plugins())
 	    fcntl(new_descriptor, F_SETFD, FD_CLOEXEC);
+#endif
 
 	  {
 	    Hold_optional_lock hl(this->lock_);
diff -ruN binutils-2.21//gold/fileread.cc ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/fileread.cc
--- binutils-2.21//gold/fileread.cc	2010-10-12 19:30:24.000000000 +0400
+++ binutils-2.21/gold/fileread.cc	2010-12-29 11:41:04.994855000 +0300
@@ -26,7 +26,11 @@
 #include <cerrno>
 #include <fcntl.h>
 #include <unistd.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#else
+#include "mremap.h"
+#endif
 
 #ifdef HAVE_READV
 #include <sys/uio.h>
@@ -195,6 +199,7 @@
 {
   gold_assert(this->is_locked());
 
+#ifndef __MINGW32__
   if (!parameters->options_valid() || parameters->options().stats())
     {
       file_counts_initialize_lock.initialize();
@@ -204,6 +209,7 @@
       if (File_read::current_mapped_bytes > File_read::maximum_mapped_bytes)
 	File_read::maximum_mapped_bytes = File_read::current_mapped_bytes;
     }
+#endif
 
   this->mapped_bytes_ = 0;
 
@@ -414,7 +420,9 @@
     }
 
   File_read::View* v;
+#ifndef __MINGW32__
   if (byteshift != 0)
+#endif
     {
       unsigned char* p = new unsigned char[psize + byteshift];
       memset(p, 0, byteshift);
@@ -422,6 +430,7 @@
       v = new File_read::View(poff, psize, p, byteshift, cache,
                               View::DATA_ALLOCATED_ARRAY);
     }
+#ifndef __MINGW32__
   else
     {
       this->reopen_descriptor();
@@ -440,6 +449,7 @@
       v = new File_read::View(poff, psize, pbytes, 0, cache,
                               View::DATA_MMAPPED);
     }
+#endif
 
   this->add_view(v);
 
diff -ruN binutils-2.21//gold/incremental.cc ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/incremental.cc
--- binutils-2.21//gold/incremental.cc	2010-10-15 02:10:22.000000000 +0400
+++ binutils-2.21/gold/incremental.cc	2010-12-29 11:41:04.776106400 +0300
@@ -117,12 +117,19 @@
 void
 vexplain_no_incremental(const char* format, va_list args)
 {
+#ifndef __MINGW32__
   char* buf = NULL;
   if (vasprintf(&buf, format, args) < 0)
     gold_nomem();
   gold_info(_("the link might take longer: "
               "cannot perform incremental link: %s"), buf);
   free(buf);
+#else
+  char buf[4096];
+  vsnprintf(buf, sizeof(buf), format, args);
+  gold_info(_("the link might take longer: "
+              "cannot perform incremental link: %s"), buf);
+#endif
 }
 
 void
diff -ruN binutils-2.21//gold/mremap.c ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/mremap.c
--- binutils-2.21//gold/mremap.c	2009-03-28 08:22:30.000000000 +0300
+++ binutils-2.21/gold/mremap.c	2010-12-29 11:41:04.854230900 +0300
@@ -25,7 +25,14 @@
 
 #include <string.h>
 #include <sys/types.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#else
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include "mremap.h"
+#endif
 
 /* This file implements mremap for systems which don't have it.  The
    gold code requires support for mmap.  However, there are systems
@@ -57,3 +64,23 @@
   (void) munmap (old_address, old_size);
   return ret;
 }
+
+void *
+mmap64 (void *__addr, size_t __len, int __prot ATTRIBUTE_UNUSED,
+       int __flags, int __fd, long long  __offset ATTRIBUTE_UNUSED)
+{
+  void *ret;
+  if (__addr || __fd != -1 || (__flags & MAP_SHARED))
+    return MAP_FAILED;
+  ret = malloc(__len);
+  if (!ret)
+    return MAP_FAILED;
+  return ret;  
+}
+
+int
+munmap (void *__addr, size_t __len ATTRIBUTE_UNUSED)
+{
+  free(__addr);
+  return 0;
+}
diff -ruN binutils-2.21//gold/mremap.h ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/mremap.h
--- binutils-2.21//gold/mremap.h	1970-01-01 03:00:00.000000000 +0300
+++ binutils-2.21/gold/mremap.h	2010-12-29 11:41:04.869855800 +0300
@@ -0,0 +1,47 @@
+#ifndef GOLD_MREMAP_H
+#define GOLD_MREMAP_H
+
+#define PROT_READ 0x1
+#define PROT_WRITE 0x2
+#define PROT_EXEC 0x4
+#define PROT_NONE 0x0
+
+#define MAP_SHARED 0x01
+#define MAP_PRIVATE 0x02
+
+#define MAP_TYPE 0x0f
+
+#define MAP_FIXED 0x10
+
+#define MAP_FILE 0
+#define MAP_ANONYMOUS 0x20
+#define MAP_ANON MAP_ANONYMOUS
+#define MAP_32BIT 0x40
+
+#define MAP_GROWSDOWN 0x0100
+#define MAP_DENYWRITE 0x0800
+#define MAP_EXECUTABLE 0x1000
+#define MAP_LOCKED 0x2000
+#define MAP_NORESERVE 0x4000
+
+#define MREMAP_MAYMOVE 1
+
+#define MAP_FAILED ((void *) -1)
+
+#ifndef S_ISLNK
+#define S_ISLNK(x) (0)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern void *mmap64 (void *__addr, size_t __len, int __prot,
+                    int __flags, int __fd, long long __offset);
+#define mmap(p1, p2, p3, p4, p5, p6) mmap64(p1, p2, p3, p4, p5, p6)
+extern int munmap (void *__addr, size_t __len);
+extern void *mremap (void *, size_t, size_t, int, ...);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(GOLD_MREMAP_H) */
diff -ruN binutils-2.21//gold/output.cc ../i686-gcc-4.4.3-glibc-2.3.2-0.43/build/binutils-2.21/gold/output.cc
--- binutils-2.21//gold/output.cc	2010-11-18 11:24:22.000000000 +0300
+++ binutils-2.21/gold/output.cc	2010-12-29 11:41:04.947980300 +0300
@@ -27,7 +27,11 @@
 #include <cerrno>
 #include <fcntl.h>
 #include <unistd.h>
+#ifndef __MINGW32__
 #include <sys/mman.h>
+#else
+#include "mremap.h"
+#endif
 #include <sys/stat.h>
 #include <algorithm>
 #include "libiberty.h"


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

end of thread, other threads:[~2011-07-01  6:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-30 18:19 gold work on mingw/mingw64 support Vladimir Simonov
2010-12-30 18:24 ` Ralf Wildenhues
2010-12-30 19:26 ` Ian Lance Taylor
2011-01-04 17:02   ` Vladimir Simonov
2011-01-04 17:36     ` Ian Lance Taylor
2011-01-05 12:31       ` Vladimir Simonov
2011-04-12 11:35         ` NightStrike
2011-04-12 18:06         ` Ian Lance Taylor
2011-04-13  9:46           ` Vladimir Simonov
2011-04-13 14:25             ` Ian Lance Taylor
2011-04-13 16:23               ` Vladimir Simonov
2011-04-13 17:28                 ` Ian Lance Taylor
2011-04-18 15:49             ` Vladimir Simonov
2011-04-19 17:13               ` Vladimir Simonov
2011-04-19 17:33                 ` Ian Lance Taylor
2011-04-22 23:21               ` Ian Lance Taylor
2011-06-30  8:18                 ` Vladimir Simonov
2011-06-30 15:48                   ` Ian Lance Taylor
2011-07-01  6:42                     ` Vladimir Simonov

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