* 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.
This commit is contained in:
Cary Coutant
2012-06-06 22:12:47 +00:00
parent 8fe6640e15
commit 7c0640fa36
6 changed files with 52 additions and 18 deletions

View 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