This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold patch] Fix check for fallocate failure
- From: Cary Coutant <ccoutant at google dot com>
- To: Ian Lance Taylor <iant at google dot com>, Binutils <binutils at sourceware dot org>
- Date: Wed, 12 Oct 2011 22:55:15 -0700
- Subject: [gold patch] Fix check for fallocate failure
The posix_fallocate() routine returns an errno code directly and does
not set errno. Gold checks for a negative return value to indicate
failure, misses the failure, and ends up seg faulting when it tries to
write past the end of the available space. This patch fixes the check.
Tested on x86_64, with a tmpfs file system too small for the output file.
-cary
2011-10-12 Cary Coutant <ccoutant@google.com>
* gold/output.cc (Output_file::map_no_anonymous): Check for non-zero
return code from posix_fallocate.
commit 8cbae59d553fa09d23c1461e7f65fb18c5cdcde0
Author: Cary Coutant <ccoutant@google.com>
Date: Wed Oct 12 22:43:56 2011 -0700
Fix check of posix_fallocate return value.
diff --git a/gold/output.cc b/gold/output.cc
index 7b272e8..949d9ef 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -5075,8 +5075,12 @@ Output_file::map_no_anonymous(bool writable)
// output file will wind up incomplete, but we will have already
// exited. The alternative to fallocate would be to use fdatasync,
// but that would be a more significant performance hit.
- if (writable && ::posix_fallocate(o, 0, this->file_size_) < 0)
- gold_fatal(_("%s: %s"), this->name_, strerror(errno));
+ if (writable)
+ {
+ int err = ::posix_fallocate(o, 0, this->file_size_);
+ if (err != 0)
+ gold_fatal(_("%s: %s"), this->name_, strerror(err));
+ }
// Map the file into memory.
int prot = PROT_READ;