diff -ruN binutils-2.21.orig/config/mh-mingw binutils-2.21/config/mh-mingw --- binutils-2.21.orig/config/mh-mingw 2008-11-27 20:22:09 +0300 +++ binutils-2.21/config/mh-mingw 2011-01-02 14:32:09 +0300 @@ -2,5 +2,6 @@ # Vista (see PR33281 for details). BOOT_CFLAGS += -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format CFLAGS += -D__USE_MINGW_ACCESS +CXXFLAGS += -D__USE_MINGW_ACCESS # Increase stack limit to same as Linux default. LDFLAGS += -Wl,--stack,8388608 diff -ruN binutils-2.21.orig/gold/descriptors.cc binutils-2.21/gold/descriptors.cc --- binutils-2.21.orig/gold/descriptors.cc 2010-07-14 14:38:59 +0400 +++ binutils-2.21/gold/descriptors.cc 2011-01-03 16:26:42 +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.orig/gold/fileread.cc binutils-2.21/gold/fileread.cc --- binutils-2.21.orig/gold/fileread.cc 2010-10-12 19:30:24 +0400 +++ binutils-2.21/gold/fileread.cc 2011-01-01 21:23:41 +0300 @@ -26,13 +26,13 @@ #include #include #include -#include #ifdef HAVE_READV #include #endif #include +#include "mremap.h" #include "filenames.h" #include "debug.h" diff -ruN binutils-2.21.orig/gold/gold.h binutils-2.21/gold/gold.h --- binutils-2.21.orig/gold/gold.h 2010-06-02 03:37:57 +0400 +++ binutils-2.21/gold/gold.h 2011-01-01 21:05:02 +0300 @@ -135,11 +135,6 @@ extern "C" int ftruncate(int, off_t); #endif -#ifndef HAVE_MREMAP -#define MREMAP_MAYMOVE 1 -extern "C" void *mremap(void *, size_t, size_t, int, ...); -#endif - #ifndef HAVE_FFSLL extern "C" int ffsll(long long); #endif diff -ruN binutils-2.21.orig/gold/mremap.c binutils-2.21/gold/mremap.c --- binutils-2.21.orig/gold/mremap.c 2009-03-28 08:22:30 +0300 +++ binutils-2.21/gold/mremap.c 2011-01-03 16:37:09 +0300 @@ -25,7 +25,11 @@ #include #include -#include +#ifdef HAVE_STDLIB_H +#include +#endif + +#include "mremap.h" /* This file implements mremap for systems which don't have it. The gold code requires support for mmap. However, there are systems @@ -57,3 +61,42 @@ (void) munmap (old_address, old_size); return ret; } + +#ifdef __MINGW32__ + +extern ssize_t pread (int, void *, size_t, off_t); + +void * +mmap64 (void *__addr, size_t __len, int __prot, + int __flags, int __fd, long long __offset) +{ + void *ret; + ssize_t count; + + if (__addr || (__fd != -1 && (__prot & PROT_WRITE)) + || (__flags & MAP_SHARED)) + return MAP_FAILED; + ret = malloc (__len); + if (!ret) + return MAP_FAILED; + + if (__fd == -1) + return ret; + + count = pread (__fd, ret, __len, __offset); + if ((size_t) count != __len) + { + free (ret); + return MAP_FAILED; + } + + return ret; +} + +int +munmap (void *__addr, size_t __len ATTRIBUTE_UNUSED) +{ + free (__addr); + return 0; +} +#endif diff -ruN binutils-2.21.orig/gold/mremap.h binutils-2.21/gold/mremap.h --- binutils-2.21.orig/gold/mremap.h 1970-01-01 03:00:00 +0300 +++ binutils-2.21/gold/mremap.h 2011-01-03 16:13:08 +0300 @@ -0,0 +1,81 @@ +/* mremap.h -- mmap family functions prototypes for gold. */ + +/* Copyright 2009 Free Software Foundation, Inc. + Written by Ian Lance Taylor + and Vladimir Simonov + + This file is part of gold. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#ifndef GOLD_MREMAP_H +#define GOLD_MREMAP_H + +#ifndef __MINGW32__ +#include +#endif + +#ifndef HAVE_MREMAP +#define MREMAP_MAYMOVE 1 +#ifdef __cplusplus +extern "C" +#endif +void *mremap(void *, size_t, size_t, int, ...); +#endif /* HAVE_MREMAP */ + +#ifdef __MINGW32__ +#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 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); +#ifdef __cplusplus +} +#endif +#endif /* __MINGW32__ */ + +#endif /* GOLD_MREMAP_H */ diff -ruN binutils-2.21.orig/gold/output.cc binutils-2.21/gold/output.cc --- binutils-2.21.orig/gold/output.cc 2010-11-18 11:24:22 +0300 +++ binutils-2.21/gold/output.cc 2011-01-01 21:10:09 +0300 @@ -27,11 +27,11 @@ #include #include #include -#include #include #include #include "libiberty.h" +#include "mremap.h" #include "parameters.h" #include "object.h" #include "symtab.h"