? gold/autom4te.cache ? gold/t.diff.txt Index: gold/fileread.cc =================================================================== RCS file: /cvs/src/src/gold/fileread.cc,v retrieving revision 1.53 diff -u -p -r1.53 fileread.cc --- gold/fileread.cc 30 Sep 2009 22:21:13 -0000 1.53 +++ gold/fileread.cc 7 Oct 2009 19:25:00 -0000 @@ -26,8 +26,14 @@ #include #include #include + +#ifndef _WIN32 #include #include +#else +#include +#endif + #include #include "filenames.h" @@ -52,7 +58,11 @@ File_read::View::~View() delete[] this->data_; else { +#ifdef _WIN32 + if (!UnmapViewOfFile(const_cast(this->data_))) +#else if (::munmap(const_cast(this->data_), this->size_) != 0) +#endif gold_warning(_("munmap failed: %s"), strerror(errno)); File_read::current_mapped_bytes -= this->size_; @@ -386,15 +396,49 @@ File_read::make_view(off_t start, sectio } else { + void *p; this->reopen_descriptor(); - void* p = ::mmap(NULL, psize, PROT_READ, MAP_PRIVATE, - this->descriptor_, poff); +#ifndef _WIN32 + p = ::mmap(NULL, psize, PROT_READ, MAP_PRIVATE, + this->descriptor_, poff); if (p == MAP_FAILED) gold_fatal(_("%s: mmap offset %lld size %lld failed: %s"), this->filename().c_str(), static_cast(poff), static_cast(psize), strerror(errno)); +#else + HANDLE fm; + HANDLE h = (HANDLE) _get_osfhandle (this->descriptor_); + + gold_assert(h != INVALID_HANDLE_VALUE); + + fm = CreateFileMapping(h, + NULL, + PAGE_READONLY, + 0, + 0, + NULL); + + if (fm == NULL) + gold_fatal(_("%s: CreateFileMapping failed: %d"), + this->filename().c_str(), + GetLastError()); + + p = MapViewOfFile(fm, + FILE_MAP_READ, + 0, + poff, + psize); + CloseHandle(fm); + if (p == NULL) + gold_fatal(_("%s: MapViewOfFile offset %lld size %lld failed: %d"), + this->filename().c_str(), + static_cast(poff), + static_cast(psize), + GetLastError()); + +#endif this->mapped_bytes_ += psize; Index: gold/fileread.h =================================================================== RCS file: /cvs/src/src/gold/fileread.h,v retrieving revision 1.36 diff -u -p -r1.36 fileread.h --- gold/fileread.h 6 Jul 2009 23:11:21 -0000 1.36 +++ gold/fileread.h 7 Oct 2009 19:25:01 -0000 @@ -357,7 +357,8 @@ class File_read clear_views(bool); // The size of a file page for buffering data. - static const off_t page_size = 8192; + // FIXME WIN32 requires 64k as the page size but this was 8k before. + static const off_t page_size = 64*1024; // Given a file offset, return the page offset. static off_t Index: gold/mremap.c =================================================================== RCS file: /cvs/src/src/gold/mremap.c,v retrieving revision 1.2 diff -u -p -r1.2 mremap.c --- gold/mremap.c 28 Mar 2009 05:22:30 -0000 1.2 +++ gold/mremap.c 7 Oct 2009 19:25:01 -0000 @@ -25,7 +25,11 @@ #include #include +#ifndef _WIN32 #include +#else +#include +#endif /* This file implements mremap for systems which don't have it. The gold code requires support for mmap. However, there are systems @@ -48,6 +52,26 @@ mremap (void *old_address, size_t old_si { void *ret; +#ifdef _WIN32 + HANDLE fm; + + fm = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, new_size, NULL); + + if (fm == NULL) + return NULL; + + ret = MapViewOfFile (fm, FILE_MAP_WRITE, 0, 0, new_size); + + CloseHandle (fm); + + if (ret == NULL) + return ret; + + memcpy (ret, old_address, + old_size < new_size ? old_size : new_size); + + UnmapViewOfFile (old_address); +#else ret = mmap (0, new_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ret == MAP_FAILED) @@ -55,5 +79,6 @@ mremap (void *old_address, size_t old_si memcpy (ret, old_address, old_size < new_size ? old_size : new_size); (void) munmap (old_address, old_size); +#endif return ret; } Index: gold/output.cc =================================================================== RCS file: /cvs/src/src/gold/output.cc,v retrieving revision 1.97 diff -u -p -r1.97 output.cc --- gold/output.cc 30 Sep 2009 22:21:13 -0000 1.97 +++ gold/output.cc 7 Oct 2009 19:25:01 -0000 @@ -27,7 +27,13 @@ #include #include #include + +#ifdef _WIN32 +#include +#else #include +#endif + #include #include #include "libiberty.h" @@ -3674,6 +3680,28 @@ Output_file::resize(off_t file_size) bool Output_file::map_anonymous() { +#ifdef _WIN32 + HANDLE fm; + fm = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, + this->file_size_, NULL); + + // If we fail to create a file mapping to the paging return NULL. + if (fm == NULL) + return false; + + void *addr = MapViewOfFile(fm, FILE_MAP_WRITE, 0, 0, this->file_size_); + + CloseHandle (fm); + + if (addr == NULL) + return false; + + this->map_is_anonymous_ = true; + this->base_ = static_cast(addr); + return true; + +#else + void* base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (base != MAP_FAILED) @@ -3683,6 +3711,7 @@ Output_file::map_anonymous() return true; } return false; +#endif } // Map the file into memory. Return whether the mapping succeeded. @@ -3713,6 +3742,26 @@ Output_file::map_no_anonymous() if (::posix_fallocate(o, 0, this->file_size_) < 0) gold_fatal(_("%s: %s"), this->name_, strerror(errno)); +#ifdef _WIN32 + HANDLE fm; + HANDLE h = (HANDLE) _get_osfhandle (o); + + gold_assert (h != INVALID_HANDLE_VALUE); + + fm = CreateFileMapping(h, NULL, PAGE_READWRITE, 0, 0, NULL); + + if (fm == NULL) + return false; + + base = MapViewOfFile (fm, FILE_MAP_WRITE, 0, 0, this->file_size_); + + CloseHandle (fm); + + if (base == NULL) + return false; + +#else + // Map the file into memory. base = ::mmap(NULL, this->file_size_, PROT_READ | PROT_WRITE, MAP_SHARED, o, 0); @@ -3722,6 +3771,8 @@ Output_file::map_no_anonymous() // mmap with PROT_WRITE. if (base == MAP_FAILED) return false; + +#endif this->map_is_anonymous_ = false; this->base_ = static_cast(base); @@ -3754,7 +3805,11 @@ Output_file::map() void Output_file::unmap() { +#ifdef _WIN32 + if (!UnmapViewOfFile(this->base_)) +#else if (::munmap(this->base_, this->file_size_) < 0) +#endif gold_error(_("%s: munmap: %s"), this->name_, strerror(errno)); this->base_ = NULL; }