This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold patch] Fix check for fallocate failure
> As long as you are looking at this you also need to fix the
> implementation of posix_fallocate for systems that don't have it, near
> the top of output.cc.
Sorry, I should have caught that. How's this?
-cary
2011-10-12 Cary Coutant <ccoutant@google.com>
* output.cc (posix_fallocate): Return 0 on success, errno on failure.
(Output_file::map_no_anonymous): Check for non-zero
return code from posix_fallocate.
commit 45aeed4e31dab07dd90d216a63f1e5033c46fb9a
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..3993864 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -119,7 +119,9 @@ extern "C" void *gold_mremap(void *, size_t, size_t, int);
static int
posix_fallocate(int o, off_t offset, off_t len)
{
- return ftruncate(o, offset + len);
+ if (ftruncate(o, offset + len) < 0)
+ return errno;
+ return 0;
}
#endif // !defined(HAVE_POSIX_FALLOCATE)
@@ -5075,8 +5077,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;