--- binutils-2.23.1/gold/output.cc 2012-11-09 01:21:28.000000000 -0700
+++ binutils-2.23.1/gold/output.cc 2013-01-01 01:45:50.721203685 -0700
@@ -22,6 +22,7 @@
#include "gold.h"
+#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
@@ -127,9 +128,15 @@
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);
+#if defined(HAVE_POSIX_FALLOCATE)
+ if (parameters->options().posix_fallocate()) {
+ // posix_fallocate on Solaris will fail if len == 0
+ int ret = ::posix_fallocate(o, offset, len);
+ // try ::ftruncate(3C) is posix_fallocate(3C) failed.
+ if (ret != 0)
+ ret = ::ftruncate(o, offset + len);
+ return ret;
+ }
#endif // defined(HAVE_POSIX_FALLOCATE)
#ifdef HAVE_FALLOCATE
if (::fallocate(o, 0, offset, len) == 0)