diff options
author | Ian Lance Taylor <ian@airs.com> | 2009-10-28 00:42:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2009-10-28 00:42:34 +0000 |
commit | 2c849493874929a145d42c2a977e693fe6faa19b (patch) | |
tree | f0280e29e8a4377877d64b0c67326cb01fab0302 /gold/fileread.h | |
parent | 2499805399b431a88cae733b292b04916e1295d6 (diff) | |
download | fsf-binutils-gdb-2c849493874929a145d42c2a977e693fe6faa19b.zip fsf-binutils-gdb-2c849493874929a145d42c2a977e693fe6faa19b.tar.gz fsf-binutils-gdb-2c849493874929a145d42c2a977e693fe6faa19b.tar.bz2 |
* fileread.cc: (File_read::View::~View): Use the new
data_ownership_ filed.
(File_read::~File_read): Dispose the new whole_file_view_.
(File_read::open): Mmap the whole file if needed.
(File_read::open): Use whole_file_view_ instead of contents_.
(File_read::find_view): Use whole_file_view_ if applicable.
(File_read::do_read): Use whole_file_view_ instead of contents_.
(File_read::make_view): Use whole_file_view_ instead of contents_,
update File_read::View::View call.
(File_read::find_or_make_view): Update File_read::View::View
call.
* fileread.h: (File_read::File_read): Initialize whole_file_view_,
remove contents_
(File_read::View::Data_ownership): New enum.
(File_read::View::View): Replace bool mapped_ with Data_ownership
argument.
(File_read::View::mapped_): Remove (replaced by data_ownership_).
(File_read::View::data_ownership_): New field.
(File_read::contents_): Remove (replaced by whole_file_view_).
(File_read::whole_file_view_): New field.
* options.h (class General_options): Add --keep-files-mapped.
Diffstat (limited to 'gold/fileread.h')
-rw-r--r-- | gold/fileread.h | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/gold/fileread.h b/gold/fileread.h index bdffdd1..47c8e0f 100644 --- a/gold/fileread.h +++ b/gold/fileread.h @@ -65,8 +65,8 @@ class File_read public: File_read() : name_(), descriptor_(-1), is_descriptor_opened_(false), object_count_(0), - size_(0), token_(false), views_(), saved_views_(), contents_(NULL), - mapped_bytes_(0), released_(true) + size_(0), token_(false), views_(), saved_views_(), mapped_bytes_(0), + released_(true), whole_file_view_(NULL) { } ~File_read(); @@ -234,10 +234,23 @@ class File_read class View { public: + // Specifies how to dispose the data on destruction of the view. + enum Data_ownership + { + // Data owned by File object - nothing done in destructor. + DATA_NOT_OWNED, + // Data alocated with new[] and owned by this object - should + // use delete[]. + DATA_ALLOCATED_ARRAY, + // Data mmapped and owned by this object - should munmap. + DATA_MMAPPED + }; + View(off_t start, section_size_type size, const unsigned char* data, - unsigned int byteshift, bool cache, bool mapped) + unsigned int byteshift, bool cache, Data_ownership data_ownership) : start_(start), size_(size), data_(data), lock_count_(0), - byteshift_(byteshift), cache_(cache), mapped_(mapped), accessed_(true) + byteshift_(byteshift), cache_(cache), data_ownership_(data_ownership), + accessed_(true) { } ~View(); @@ -311,7 +324,7 @@ class File_read bool cache_; // Whether the view is mapped into memory. If not, data_ points // to memory allocated using new[]. - bool mapped_; + Data_ownership data_ownership_; // Whether the view has been accessed recently. bool accessed_; }; @@ -400,14 +413,18 @@ class File_read // List of views which were locked but had to be removed from views_ // because they were not large enough. Saved_views saved_views_; - // Specified file contents. Used only for testing purposes. - const unsigned char* contents_; // Total amount of space mapped into memory. This is only changed // while the file is locked. When we unlock the file, we transfer // the total to total_mapped_bytes, and reset this to zero. size_t mapped_bytes_; // Whether the file was released. bool released_; + // A view containing the whole file. May be NULL if we mmap only + // the relevant parts of the file. Not NULL if: + // - Flag --mmap_whole_files is set (default on 64-bit hosts). + // - The contents was specified in the constructor. Used only for + // testing purposes). + View* whole_file_view_; }; // A view of file data that persists even when the file is unlocked. |