gold work on mingw/mingw64 support

Ian Lance Taylor iant@google.com
Tue Apr 12 18:06:00 GMT 2011


Vladimir Simonov <sv@sw.ru> writes:

> On 01/04/2011 08:35 PM, Ian Lance Taylor wrote:
>> Vladimir Simonov<sv@sw.ru>  writes:
>>
>>> IMO mremap.c, pread.c, etc. are a kind of such library.
>>> Analysis of target OS capabilities is overkill here, we
>>> know in advance - mingw doesn't have mmap and most probably
>>> won't have it.
>>
>> Sure, but there are other systems that also don't have mmap.  We don't
>> want to test for all of them.
>>
>>> If __MINGW32__ looks too OS specific it may be
>>> replaced with HAVE_NO_MMAP, HAVE_NO_CLOEXEC defined
>>> in config/mh-mingw. Really __MINGW32__ looks quite strange
>>> in the middle of descriptors.cc but I don't know how to do it
>>> better - fake function in mremap.h would be also strange,
>>> new fcntl.c - the same...
>>
>> I'm complaining in part about the __MINGW32__ and in part about the
>> #ifdef.  Apart from ENABLE_THREADS, the only #ifdefs in gold are very
>> small ones at the top of a few .cc files.  Let's keep it that way.
>>
>> Ian
>>
>
> OK. Here is a version without __MINGW32__, with sys/mman.h and mmap
> function presence detection and new mmap.h/mmap.c.
> It is larger but should satisfy you requirements.
> Could you comment?

Thanks.

I decided to go a different route.  It seems that mmap could in general
fail for a file which can nevertheless be read.  So I decided to go
ahead and change gold to handle the case of mmap failing.  This then
turns the mingw32 code into a matter of supporting systems which don't
provide mmap by providing a stub mmap which always fails.

I committed the appended patch.  Let me know if you find problems with
it.  This patch also cleans up mremap a bit even on systems which
provide mmap.

Ian


2011-04-12  Ian Lance Taylor  <iant@google.com>

	* configure.ac: Check for sys/mman.h and mmap.  Check for mremap
	with MREMAP_MAYMOVE.
	* output.h (class Output_file): Add map_is_allocated_ field.
	* output.cc: Only #include <sys/mman.h> if it exists.  If mmap is
	not available, provide stubs.  If mremap is not available, #define
	it to gold_mremap.
	(MREMAP_MAYMOVE): Define if not defined.
	(Output_file::Output_file): Initialize map_is_allocated_.
	(Output_file::resize): Check map_is_allocated_.
	(Output_file::map_anonymous): If mmap fails, use malloc.
	(Output_file::unmap): Don't do anything for an anonymous map.
	* fileread.cc: Only #include <sys/mman.h> if it exists.  If mmap
	is not available, provide stubs.
	(File_read::View::~View): Use free rather than delete[].
	(File_read::make_view): Use malloc rather than new[].  If mmap
	fails, use malloc.
	(File_read::find_or_make_view): Use malloc rather than new[].
	* gold.h: Remove HAVE_REMAP code.
	* mremap.c: #include <errno.h>.  Only #include <sys/mman.h> if it
	exists.  Rename mremap to gold_mremap.  If mmap is not available
	don't do anything.
	* configure, config.in: Rebuild.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-diff
Size: 13250 bytes
Desc: patch
URL: <https://sourceware.org/pipermail/binutils/attachments/20110412/4bddaaf8/attachment.bin>


More information about the Binutils mailing list