This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] gold: extend Output_file to support read/write access to existing files.


Mikolaj Zalewski <mikolajz@google.com> writes:

>> 2) I didn't see any reason to include the map_include_original_content_
>> Â field.
>   This was added to avoid such a scenario:
>   1. The program opens a file with Output_file::open_for_modification,
> the mapping succeeds.
>   2. The programs calls Output_file::resize, this calls unmap() and map()
>   3. Without map_include_original_content_, if inside
> Output_file::map() mapping this file fails but anonymous mapping
> succeeds, we loose all the contents of the file.
>
>   I don't think this would happen often but could, in theory, happen
> if e.g. the first map in 3. failed because of lack of address space
> for the larger mapping but the second succeeded because another
> threads freed some space between the calls.
>   However, it seems this could also be a problem for new files created
> with Output_file::open if someone wrote to them before calling
> resize(). Maybe the solution is to change map to map_no_anonymous in
> Output_file::resize?

Good point.  Thanks for spotting that.  I committed this patch.

Ian


2009-09-02  Ian Lance Taylor  <iant@google.com>

	* output.cc (Output_file::resize): Call map_no_anonymous rather
	than map.


Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.93
diff -p -u -r1.93 output.cc
--- output.cc	1 Sep 2009 17:32:20 -0000	1.93
+++ output.cc	2 Sep 2009 16:38:33 -0000
@@ -3497,7 +3497,8 @@ Output_file::resize(off_t file_size)
     {
       this->unmap();
       this->file_size_ = file_size;
-      this->map();
+      if (!this->map_no_anonymous())
+	gold_fatal(_("%s: mmap: %s"), this->name_, strerror(errno));
     }
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]