summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-11-22 12:31:53 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-11-22 12:31:53 +0000
commit5745fbce1674b29f4dce6b6e31556c4c1e83dc89 (patch)
treea5aaefd6d9fb122e4f744a855d20e57df129b7e9
parentf264568bae482601431e4ac923172fa3671eb9e7 (diff)
downloadexternal_llvm-5745fbce1674b29f4dce6b6e31556c4c1e83dc89.zip
external_llvm-5745fbce1674b29f4dce6b6e31556c4c1e83dc89.tar.gz
external_llvm-5745fbce1674b29f4dce6b6e31556c4c1e83dc89.tar.bz2
Add configure checking for pread(2) and use it to save a syscall when reading files.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145061 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--autoconf/configure.ac2
-rwxr-xr-xcmake/config-ix.cmake2
-rwxr-xr-xconfigure3
-rw-r--r--include/llvm/Config/config.h.cmake3
-rw-r--r--include/llvm/Config/config.h.in3
-rw-r--r--lib/Support/MemoryBuffer.cpp7
6 files changed, 18 insertions, 2 deletions
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 090f5dc..d777553 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1293,7 +1293,7 @@ AC_CHECK_FUNCS([backtrace ceilf floorf roundf rintf nearbyintf getcwd ])
AC_CHECK_FUNCS([powf fmodf strtof round ])
AC_CHECK_FUNCS([getpagesize getrusage getrlimit setrlimit gettimeofday ])
AC_CHECK_FUNCS([isatty mkdtemp mkstemp ])
-AC_CHECK_FUNCS([mktemp posix_spawn realpath sbrk setrlimit strdup ])
+AC_CHECK_FUNCS([mktemp posix_spawn pread realpath sbrk setrlimit strdup ])
AC_CHECK_FUNCS([strerror strerror_r setenv ])
AC_CHECK_FUNCS([strtoll strtoq sysconf malloc_zone_statistics ])
AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp writev])
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 62699fa..0943ae7 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -126,6 +126,8 @@ check_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
+check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
+check_symbol_exists(pread unistd.h HAVE_PREAD)
check_symbol_exists(rindex strings.h HAVE_RINDEX)
check_symbol_exists(strchr string.h HAVE_STRCHR)
check_symbol_exists(strcmp string.h HAVE_STRCMP)
diff --git a/configure b/configure
index 09173d2..bfd61dd 100755
--- a/configure
+++ b/configure
@@ -17151,7 +17151,8 @@ done
-for ac_func in mktemp posix_spawn realpath sbrk setrlimit strdup
+
+for ac_func in mktemp posix_spawn pread realpath sbrk setrlimit strdup
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 69e3eef..11e5b5a 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -297,6 +297,9 @@
/* Define to 1 if you have the `powf' function. */
#cmakedefine HAVE_POWF ${HAVE_POWF}
+/* Define to 1 if you have the `pread' function. */
+#cmakedefine HAVE_PREAD ${HAVE_PREAD}
+
/* Define if libtool can extract symbol lists from object files. */
#undef HAVE_PRELOADED_SYMBOLS
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 813c6eb..b3a9590 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -295,6 +295,9 @@
/* Define to 1 if you have the `powf' function. */
#undef HAVE_POWF
+/* Define to 1 if you have the `pread' function. */
+#undef HAVE_PREAD
+
/* Define if libtool can extract symbol lists from object files. */
#undef HAVE_PRELOADED_SYMBOLS
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 5803381..1a40972 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -14,6 +14,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Config/config.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Path.h"
@@ -320,11 +321,17 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
char *BufPtr = const_cast<char*>(SB->getBufferStart());
size_t BytesLeft = MapSize;
+#ifndef HAVE_PREAD
if (lseek(FD, Offset, SEEK_SET) == -1)
return error_code(errno, posix_category());
+#endif
while (BytesLeft) {
+#ifdef HAVE_PREAD
+ ssize_t NumRead = ::pread(FD, BufPtr, BytesLeft, MapSize-BytesLeft+Offset);
+#else
ssize_t NumRead = ::read(FD, BufPtr, BytesLeft);
+#endif
if (NumRead == -1) {
if (errno == EINTR)
continue;