gold/
authorCary Coutant <ccoutant@google.com>
Wed, 6 Jun 2012 22:12:47 +0000 (22:12 +0000)
committerCary Coutant <ccoutant@google.com>
Wed, 6 Jun 2012 22:12:47 +0000 (22:12 +0000)
* configure.ac: Add check for fallocate.
* configure: Regenerate.
* config.in: Regenerate.

* options.h (class General_options): Add --mmap-output-file and
--posix-fallocate options.
* output.cc: (posix_fallocate): Remove; replace with...
(gold_fallocate): New function.
(Output_file::map_no_anonymous): Call gold_fallocate.
(Output_file::map): Check --mmap-output-file option.

gold/ChangeLog
gold/config.in
gold/configure
gold/configure.ac
gold/options.h
gold/output.cc

index 6752c13bea5ae4eddf92f138792816e69b4e11c3..3d93e22322650aa137d2474bd54c28fe7e6d051c 100644 (file)
@@ -1,3 +1,16 @@
+2012-06-06  Cary Coutant  <ccoutant@google.com>
+
+       * configure.ac: Add check for fallocate.
+       * configure: Regenerate.
+       * config.in: Regenerate.
+
+       * options.h (class General_options): Add --mmap-output-file and
+       --posix-fallocate options.
+       * output.cc: (posix_fallocate): Remove; replace with...
+       (gold_fallocate): New function.
+       (Output_file::map_no_anonymous): Call gold_fallocate.
+       (Output_file::map): Check --mmap-output-file option.
+
 2012-06-05  Jing Yu  <jingyu@google.com>
 
        * gold.h (textdomain): Add do {} to empty while(0).
index dd0a0da335be110ac384e9a154035813795ad47a..ff4d5ee5b9eed9a82af85427b1e7eb99d264609a 100644 (file)
@@ -79,6 +79,9 @@
 /* Define to 1 if you have the <ext/hash_set> header file. */
 #undef HAVE_EXT_HASH_SET
 
+/* Define to 1 if you have the `fallocate' function. */
+#undef HAVE_FALLOCATE
+
 /* Define to 1 if you have the `ffsll' function. */
 #undef HAVE_FFSLL
 
index dec02dc896b1c05eb5a6654035beb26f6e1a5023..b84234a8483423b00c415aafe56dfbe0afe80150 100755 (executable)
@@ -3222,6 +3222,7 @@ am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
 ac_config_headers="$ac_config_headers config.h:config.in"
 
 
+# PR 14072
 
 
 
@@ -7123,7 +7124,7 @@ fi
 
 done
 
-for ac_func in mallinfo posix_fallocate readv sysconf times
+for ac_func in mallinfo posix_fallocate fallocate readv sysconf times
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
index a2c4875eb422b893087d71d9e563d58fe82aad5e..fdea6291edb918e6d7be147ec790a9625e50ddf6 100644 (file)
@@ -499,7 +499,7 @@ AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
-AC_CHECK_FUNCS(mallinfo posix_fallocate readv sysconf times)
+AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
index b244bd54b39490dda10acaaadf3f5359bdca3337..6463b809dde8be306c89e6a3c75e7631e12f1d0a 100644 (file)
@@ -889,6 +889,10 @@ class General_options
   DEFINE_string(m, options::EXACTLY_ONE_DASH, 'm', "",
                 N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
 
+  DEFINE_bool(mmap_output_file, options::TWO_DASHES, '\0', true,
+              N_("Map the output file for writing (default)."),
+              N_("Do not map the output file for writing."));
+
   DEFINE_bool(print_map, options::TWO_DASHES, 'M', false,
              N_("Write map file on standard output"), NULL);
   DEFINE_string(Map, options::ONE_DASH, '\0', NULL, N_("Write map file"),
@@ -939,6 +943,11 @@ class General_options
                  N_("Pass an option to the plugin"), N_("OPTION"));
 #endif
 
+  DEFINE_bool(posix_fallocate, options::TWO_DASHES, '\0', true,
+              N_("Use posix_fallocate to reserve space in the output file"
+                " (default)."),
+              N_("Use fallocate or ftruncate to reserve space."));
+
   DEFINE_bool(preread_archive_symbols, options::TWO_DASHES, '\0', false,
               N_("Preread archive symbols when multi-threaded"), NULL);
 
index 2236916054a7f55f713ff6318e265b967d4aab7c..99890ebae1e9ec21dfa5a208640964243dd586cb 100644 (file)
@@ -111,20 +111,6 @@ extern "C" void *gold_mremap(void *, size_t, size_t, int);
 # define MREMAP_MAYMOVE 1
 #endif
 
-#ifndef HAVE_POSIX_FALLOCATE
-// A dummy, non general, version of posix_fallocate.  Here we just set
-// the file size and hope that there is enough disk space.  FIXME: We
-// could allocate disk space by walking block by block and writing a
-// zero byte into each block.
-static int
-posix_fallocate(int o, off_t offset, off_t len)
-{
-  if (ftruncate(o, offset + len) < 0)
-    return errno;
-  return 0;
-}
-#endif // !defined(HAVE_POSIX_FALLOCATE)
-
 // Mingw does not have S_ISLNK.
 #ifndef S_ISLNK
 # define S_ISLNK(mode) 0
@@ -133,6 +119,27 @@ posix_fallocate(int o, off_t offset, off_t len)
 namespace gold
 {
 
+// A wrapper around posix_fallocate.  If we don't have posix_fallocate,
+// or the --no-posix-fallocate option is set, we try the fallocate
+// system call directly.  If that fails, we use ftruncate to set
+// the file size and hope that there is enough disk space.
+
+static int
+gold_fallocate(int o, off_t offset, off_t len)
+{
+#ifdef HAVE_POSIX_FALLOCATE
+  if (parameters->options().posix_fallocate())
+    return ::posix_fallocate(o, offset, len);
+#endif // defined(HAVE_POSIX_FALLOCATE)
+#ifdef HAVE_FALLOCATE
+  if (::fallocate(o, 0, offset, len) == 0)
+    return 0;
+#endif // defined(HAVE_FALLOCATE)
+  if (::ftruncate(o, offset + len) < 0)
+    return errno;
+  return 0;
+}
+
 // Output_data variables.
 
 bool Output_data::allocated_sizes_are_fixed;
@@ -5014,7 +5021,7 @@ Output_file::map_no_anonymous(bool writable)
   // but that would be a more significant performance hit.
   if (writable)
     {
-      int err = ::posix_fallocate(o, 0, this->file_size_);
+      int err = gold_fallocate(o, 0, this->file_size_);
       if (err != 0)
        gold_fatal(_("%s: %s"), this->name_, strerror(err));
     }
@@ -5041,7 +5048,8 @@ Output_file::map_no_anonymous(bool writable)
 void
 Output_file::map()
 {
-  if (this->map_no_anonymous(true))
+  if (parameters->options().mmap_output_file()
+      && this->map_no_anonymous(true))
     return;
 
   // The mmap call might fail because of file system issues: the file
This page took 0.038875 seconds and 4 git commands to generate.