This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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.


2011-10-12  Cary Coutant  <>

	* gold/ (Output_file::map_no_anonymous): Check for non-zero
	return code from posix_fallocate.

commit 8cbae59d553fa09d23c1461e7f65fb18c5cdcde0
Author: Cary Coutant <>
Date:   Wed Oct 12 22:43:56 2011 -0700

    Fix check of posix_fallocate return value.

diff --git a/gold/ b/gold/
index 7b272e8..949d9ef 100644
--- a/gold/
+++ b/gold/
@@ -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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]