summaryrefslogtreecommitdiff
path: root/gold/output.cc
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@google.com>2012-06-06 22:12:47 +0000
committerCary Coutant <ccoutant@google.com>2012-06-06 22:12:47 +0000
commit7c0640fa36c37d0e17b1db3ab9b1c66792f8a5fb (patch)
tree2bad952e9bfe9eda450d7e2082215e2c62fd5c5a /gold/output.cc
parent8fe6640e153236e68f3531b8d8151be2f8c61193 (diff)
gold/
* 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.
Diffstat (limited to 'gold/output.cc')
-rw-r--r--gold/output.cc40
1 files changed, 24 insertions, 16 deletions
diff --git a/gold/output.cc b/gold/output.cc
index 2236916054..99890ebae1 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -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