From Craig Silverstein: use tls.h in x86_64.cc.
[deliverable/binutils-gdb.git] / gold / fileread.h
index a77721d47bb87e63e33023acbf6739b7eae2bca7..cf4b3ab98aedcfa041513b7d26be52b8535b12c3 100644 (file)
@@ -45,8 +45,8 @@ class File_read
 {
  public:
   File_read()
-    : name_(), descriptor_(-1), lock_count_(0), views_(),
-      saved_views_(), contents_(NULL), contents_size_(0)
+    : name_(), descriptor_(-1), size_(0), lock_count_(0), views_(),
+      saved_views_(), contents_(NULL), mapped_bytes_(0)
   { }
 
   ~File_read();
@@ -80,49 +80,64 @@ class File_read
   bool
   is_locked();
 
+  // Return the size of the file.
+  off_t
+  filesize() const
+  { return this->size_; }
+
   // Return a view into the file starting at file offset START for
   // SIZE bytes.  The pointer will remain valid until the File_read is
   // unlocked.  It is an error if we can not read enough data from the
-  // file.
-  const unsigned char*
-  get_view(off_t start, off_t size);
-
-  // Return a view into the file starting at file offset START, for up
-  // to SIZE bytes.  Set *PBYTES to the number of bytes read.  This
-  // may be less than SIZE.  The pointer will remain valid until the
-  // File_read is unlocked.
+  // file.  The CACHE parameter is a hint as to whether it will be
+  // useful to cache this data for later accesses--i.e., later calls
+  // to get_view, read, or get_lasting_view which retrieve the same
+  // data.
   const unsigned char*
-  get_view_and_size(off_t start, off_t size, off_t* pbytes);
+  get_view(off_t start, off_t size, bool cache);
 
   // Read data from the file into the buffer P starting at file offset
   // START for SIZE bytes.
   void
   read(off_t start, off_t size, void* p);
 
-  // Read up to SIZE bytes from the file into the buffer P starting at
-  // file offset START.  Set *PBYTES to the number of bytes read.
-  void
-  read_up_to(off_t start, off_t size, void* p, off_t* pbytes);
-
   // Return a lasting view into the file starting at file offset START
   // for SIZE bytes.  This is allocated with new, and the caller is
   // responsible for deleting it when done.  The data associated with
   // this view will remain valid until the view is deleted.  It is an
-  // error if we can not read enough data from the file.
+  // error if we can not read enough data from the file.  The CACHE
+  // parameter is as in get_view.
   File_view*
-  get_lasting_view(off_t start, off_t size);
+  get_lasting_view(off_t start, off_t size, bool cache);
+
+  // Dump statistical information to stderr.
+  static void
+  print_stats();
 
  private:
   // This class may not be copied.
   File_read(const File_read&);
   File_read& operator=(const File_read&);
 
-  // A view into the file when not using mmap.
+  // Total bytes mapped into memory during the link.  This variable is
+  // only accessed from the main thread, when unlocking the object.
+  static unsigned long long total_mapped_bytes;
+
+  // Current number of bytes mapped into memory during the link.  This
+  // variable is only accessed from the main thread.
+  static unsigned long long current_mapped_bytes;
+
+  // High water mark of bytes mapped into memory during the link.
+  // This variable is only accessed from the main thread.
+  static unsigned long long maximum_mapped_bytes;
+
+  // A view into the file.
   class View
   {
    public:
-    View(off_t start, off_t size, const unsigned char* data)
-      : start_(start), size_(size), data_(data), lock_count_(0)
+    View(off_t start, off_t size, const unsigned char* data, bool cache,
+         bool mapped)
+      : start_(start), size_(size), data_(data), lock_count_(0),
+       cache_(cache), mapped_(mapped)
     { }
 
     ~View();
@@ -148,6 +163,14 @@ class File_read
     bool
     is_locked();
 
+    void
+    set_cache()
+    { this->cache_ = true; }
+
+    bool
+    should_cache() const
+    { return this->cache_; }
+
    private:
     View(const View&);
     View& operator=(const View&);
@@ -156,8 +179,11 @@ class File_read
     off_t size_;
     const unsigned char* data_;
     int lock_count_;
+    bool cache_;
+    bool mapped_;
   };
 
+  friend class View;
   friend class File_view;
 
   // Find a view into the file.
@@ -165,12 +191,12 @@ class File_read
   find_view(off_t start, off_t size);
 
   // Read data from the file into a buffer.
-  off_t
-  do_read(off_t start, off_t size, void* p, off_t* pbytes);
+  void
+  do_read(off_t start, off_t size, void* p);
 
   // Find or make a view into the file.
   View*
-  find_or_make_view(off_t start, off_t size, off_t* pbytes);
+  find_or_make_view(off_t start, off_t size, bool cache);
 
   // Clear the file views.
   void
@@ -199,6 +225,8 @@ class File_read
   std::string name_;
   // File descriptor.
   int descriptor_;
+  // File size.
+  off_t size_;
   // Number of locks on the file.
   int lock_count_;
   // Buffered views into the file.
@@ -208,8 +236,10 @@ class File_read
   Saved_views saved_views_;
   // Specified file contents.  Used only for testing purposes.
   const unsigned char* contents_;
-  // Specified file size.  Used only for testing purposes.
-  off_t contents_size_;
+  // 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_;
 };
 
 // A view of file data that persists even when the file is unlocked.
@@ -251,7 +281,8 @@ class Input_file
 {
  public:
   Input_file(const Input_file_argument* input_argument)
-    : input_argument_(input_argument), file_()
+    : input_argument_(input_argument), found_name_(), file_(),
+      is_in_sysroot_(false)
   { }
 
   // Create an input file with the contents already provided.  This is
@@ -263,16 +294,24 @@ class Input_file
   void
   open(const General_options&, const Dirsearch&);
 
-  // Return the name given by the user.
+  // Return the name given by the user.  For -lc this will return "c".
   const char*
   name() const
   { return this->input_argument_->name(); }
 
-  // Return the file name.
+  // Return the file name.  For -lc this will return something like
+  // "/usr/lib/libc.so".
   const std::string&
   filename() const
   { return this->file_.filename(); }
 
+  // Return the name under which we found the file, corresponding to
+  // the command line.  For -lc this will return something like
+  // "libc.so".
+  const std::string&
+  found_name() const
+  { return this->found_name_; }
+
   // Return the position dependent options.
   const Position_dependent_options&
   options() const
@@ -283,12 +322,26 @@ class Input_file
   file()
   { return this->file_; }
 
+  // Whether we found the file in a directory in the system root.
+  bool
+  is_in_sysroot() const
+  { return this->is_in_sysroot_; }
+
  private:
   Input_file(const Input_file&);
   Input_file& operator=(const Input_file&);
 
+  // The argument from the command line.
   const Input_file_argument* input_argument_;
+  // The name under which we opened the file.  This is like the name
+  // on the command line, but -lc turns into libc.so (or whatever).
+  // It only includes the full path if the path was on the command
+  // line.
+  std::string found_name_;
+  // The file after we open it.
   File_read file_;
+  // Whether we found the file in a directory in the system root.
+  bool is_in_sysroot_;
 };
 
 } // end namespace gold
This page took 0.0278 seconds and 4 git commands to generate.