Index: llvm/lib/Support/Unix/Path.inc =================================================================== --- llvm/lib/Support/Unix/Path.inc +++ llvm/lib/Support/Unix/Path.inc @@ -1075,15 +1075,18 @@ Expected readNativeFileSlice(file_t FD, MutableArrayRef Buf, uint64_t Offset) { + auto Read = [&](size_t Size) { #ifdef HAVE_PREAD - ssize_t NumRead = - sys::RetryAfterSignal(-1, ::pread, FD, Buf.data(), Buf.size(), Offset); + return sys::RetryAfterSignal(-1, ::pread, FD, Buf.data(), Size, Offset); #else - if (lseek(FD, Offset, SEEK_SET) == -1) - return errorCodeToError(std::error_code(errno, std::generic_category())); - ssize_t NumRead = - sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Buf.size()); + if (lseek(FD, Offset, SEEK_SET) == -1) + return -1; + return sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size); #endif + }; + ssize_t NumRead = Read(Buf.size()); + if (NumRead == -1 && errno == EINVAL) + NumRead = Read(Buf.size() / 2); // Try reading a smaller chunk. if (NumRead == -1) return errorCodeToError(std::error_code(errno, std::generic_category())); return NumRead;