diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 21:25:48 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 21:25:48 +0000 |
commit | d88c1a5a572cdb661c111098831fa526e933756f (patch) | |
tree | 97b32c3372106ac47ded3d1a99f9c023a8530073 /contrib/llvm/lib/Support/Unix | |
parent | 715652a404ee99f10c09c0a5edbb5883961b8c25 (diff) | |
parent | b915e9e0fc85ba6f398b3fab0db6a81a8913af94 (diff) |
Update llvm to trunk r290819 and resolve conflicts.
Notes
Notes:
svn path=/projects/clang400-import/; revision=311142
Diffstat (limited to 'contrib/llvm/lib/Support/Unix')
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Memory.inc | 25 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Path.inc | 52 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Process.inc | 29 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Signals.inc | 42 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/TimeValue.inc | 54 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Unix.h | 40 |
6 files changed, 108 insertions, 134 deletions
diff --git a/contrib/llvm/lib/Support/Unix/Memory.inc b/contrib/llvm/lib/Support/Unix/Memory.inc index f3463e581735..edbc7938f0cb 100644 --- a/contrib/llvm/lib/Support/Unix/Memory.inc +++ b/contrib/llvm/lib/Support/Unix/Memory.inc @@ -91,17 +91,9 @@ Memory::allocateMappedMemory(size_t NumBytes, const size_t NumPages = (NumBytes+PageSize-1)/PageSize; int fd = -1; -#ifdef NEED_DEV_ZERO_FOR_MMAP - static int zero_fd = open("/dev/zero", O_RDWR); - if (zero_fd == -1) { - EC = std::error_code(errno, std::generic_category()); - return MemoryBlock(); - } - fd = zero_fd; -#endif int MMFlags = MAP_PRIVATE | -#ifdef HAVE_MMAP_ANONYMOUS +#ifdef MAP_ANONYMOUS MAP_ANONYMOUS #else MAP_ANON @@ -161,7 +153,10 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { int Protect = getPosixProtectionFlags(Flags); - int Result = ::mprotect((void*)((uintptr_t)M.Address & ~(PageSize-1)), PageSize*((M.Size+PageSize-1)/PageSize), Protect); + uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize); + uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize); + int Result = ::mprotect((void *)Start, End - Start, Protect); + if (Result != 0) return std::error_code(errno, std::generic_category()); @@ -185,17 +180,9 @@ Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock, size_t NumPages = (NumBytes+PageSize-1)/PageSize; int fd = -1; -#ifdef NEED_DEV_ZERO_FOR_MMAP - static int zero_fd = open("/dev/zero", O_RDWR); - if (zero_fd == -1) { - MakeErrMsg(ErrMsg, "Can't open /dev/zero device"); - return MemoryBlock(); - } - fd = zero_fd; -#endif int flags = MAP_PRIVATE | -#ifdef HAVE_MMAP_ANONYMOUS +#ifdef MAP_ANONYMOUS MAP_ANONYMOUS #else MAP_ANON diff --git a/contrib/llvm/lib/Support/Unix/Path.inc b/contrib/llvm/lib/Support/Unix/Path.inc index 84aafcb70d73..e0b11aaff007 100644 --- a/contrib/llvm/lib/Support/Unix/Path.inc +++ b/contrib/llvm/lib/Support/Unix/Path.inc @@ -53,7 +53,7 @@ #include <sys/attr.h> #endif -// Both stdio.h and cstdio are included via different pathes and +// Both stdio.h and cstdio are included via different paths and // stdcxx's cstdio doesn't include stdio.h, so it doesn't #undef the macros // either. #undef ferror @@ -90,7 +90,8 @@ namespace sys { namespace fs { #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \ - defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) + defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) || \ + defined(_AIX) static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { @@ -161,7 +162,7 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { } #elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ defined(__OpenBSD__) || defined(__minix) || defined(__DragonFly__) || \ - defined(__FreeBSD_kernel__) + defined(__FreeBSD_kernel__) || defined(_AIX) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL) @@ -197,16 +198,12 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { return ""; } -TimeValue file_status::getLastAccessedTime() const { - TimeValue Ret; - Ret.fromEpochTime(fs_st_atime); - return Ret; +TimePoint<> file_status::getLastAccessedTime() const { + return toTimePoint(fs_st_atime); } -TimeValue file_status::getLastModificationTime() const { - TimeValue Ret; - Ret.fromEpochTime(fs_st_mtime); - return Ret; +TimePoint<> file_status::getLastModificationTime() const { + return toTimePoint(fs_st_mtime); } UniqueID file_status::getUniqueID() const { @@ -288,6 +285,19 @@ std::error_code create_link(const Twine &to, const Twine &from) { return std::error_code(); } +std::error_code create_hard_link(const Twine &to, const Twine &from) { + // Get arguments. + SmallString<128> from_storage; + SmallString<128> to_storage; + StringRef f = from.toNullTerminatedStringRef(from_storage); + StringRef t = to.toNullTerminatedStringRef(to_storage); + + if (::link(t.begin(), f.begin()) == -1) + return std::error_code(errno, std::generic_category()); + + return std::error_code(); +} + std::error_code remove(const Twine &path, bool IgnoreNonExisting) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); @@ -329,8 +339,17 @@ std::error_code rename(const Twine &from, const Twine &to) { } std::error_code resize_file(int FD, uint64_t Size) { +#if defined(HAVE_POSIX_FALLOCATE) + // If we have posix_fallocate use it. Unlike ftruncate it always allocates + // space, so we get an error if the disk is full. + if (int Err = ::posix_fallocate(FD, 0, Size)) + return std::error_code(Err, std::generic_category()); +#else + // Use ftruncate as a fallback. It may or may not allocate space. At least on + // OS X with HFS+ it does. if (::ftruncate(FD, Size) == -1) return std::error_code(errno, std::generic_category()); +#endif return std::error_code(); } @@ -436,20 +455,17 @@ std::error_code status(int FD, file_status &Result) { return fillStatus(StatRet, Status, Result); } -std::error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { +std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time) { #if defined(HAVE_FUTIMENS) timespec Times[2]; - Times[0].tv_sec = Time.toEpochTime(); - Times[0].tv_nsec = 0; - Times[1] = Times[0]; + Times[0] = Times[1] = sys::toTimeSpec(Time); if (::futimens(FD, Times)) return std::error_code(errno, std::generic_category()); return std::error_code(); #elif defined(HAVE_FUTIMES) timeval Times[2]; - Times[0].tv_sec = Time.toEpochTime(); - Times[0].tv_usec = 0; - Times[1] = Times[0]; + Times[0] = Times[1] = sys::toTimeVal( + std::chrono::time_point_cast<std::chrono::microseconds>(Time)); if (::futimes(FD, Times)) return std::error_code(errno, std::generic_category()); return std::error_code(); diff --git a/contrib/llvm/lib/Support/Unix/Process.inc b/contrib/llvm/lib/Support/Unix/Process.inc index d81836b92dae..16f8f5a98e52 100644 --- a/contrib/llvm/lib/Support/Unix/Process.inc +++ b/contrib/llvm/lib/Support/Unix/Process.inc @@ -17,7 +17,6 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/MutexGuard.h" -#include "llvm/Support/TimeValue.h" #if HAVE_FCNTL_H #include <fcntl.h> #endif @@ -60,22 +59,14 @@ using namespace llvm; using namespace sys; -static std::pair<TimeValue, TimeValue> getRUsageTimes() { +static std::pair<std::chrono::microseconds, std::chrono::microseconds> getRUsageTimes() { #if defined(HAVE_GETRUSAGE) struct rusage RU; ::getrusage(RUSAGE_SELF, &RU); - return std::make_pair( - TimeValue( - static_cast<TimeValue::SecondsType>(RU.ru_utime.tv_sec), - static_cast<TimeValue::NanoSecondsType>( - RU.ru_utime.tv_usec * TimeValue::NANOSECONDS_PER_MICROSECOND)), - TimeValue( - static_cast<TimeValue::SecondsType>(RU.ru_stime.tv_sec), - static_cast<TimeValue::NanoSecondsType>( - RU.ru_stime.tv_usec * TimeValue::NANOSECONDS_PER_MICROSECOND))); + return { toDuration(RU.ru_utime), toDuration(RU.ru_stime) }; #else #warning Cannot get usage times on this platform - return std::make_pair(TimeValue(), TimeValue()); + return { std::chrono::microseconds::zero(), std::chrono::microseconds::zero() }; #endif } @@ -121,9 +112,9 @@ size_t Process::GetMallocUsage() { #endif } -void Process::GetTimeUsage(TimeValue &elapsed, TimeValue &user_time, - TimeValue &sys_time) { - elapsed = TimeValue::now(); +void Process::GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, + std::chrono::nanoseconds &sys_time) { + elapsed = std::chrono::system_clock::now(); std::tie(user_time, sys_time) = getRUsageTimes(); } @@ -429,7 +420,7 @@ const char *Process::ResetColor() { return "\033[0m"; } -#if !defined(HAVE_DECL_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM +#if !HAVE_DECL_ARC4RANDOM static unsigned GetRandomNumberSeed() { // Attempt to get the initial seed from /dev/urandom, if possible. int urandomFD = open("/dev/urandom", O_RDONLY); @@ -449,13 +440,13 @@ static unsigned GetRandomNumberSeed() { // Otherwise, swizzle the current time and the process ID to form a reasonable // seed. - TimeValue Now = TimeValue::now(); - return hash_combine(Now.seconds(), Now.nanoseconds(), ::getpid()); + const auto Now = std::chrono::high_resolution_clock::now(); + return hash_combine(Now.time_since_epoch().count(), ::getpid()); } #endif unsigned llvm::sys::Process::GetRandomNumber() { -#if defined(HAVE_DECL_ARC4RANDOM) && HAVE_DECL_ARC4RANDOM +#if HAVE_DECL_ARC4RANDOM return arc4random(); #else static int x = (static_cast<void>(::srand(GetRandomNumberSeed())), 0); diff --git a/contrib/llvm/lib/Support/Unix/Signals.inc b/contrib/llvm/lib/Support/Unix/Signals.inc index 55fd76d375a2..3750d7f4c09d 100644 --- a/contrib/llvm/lib/Support/Unix/Signals.inc +++ b/contrib/llvm/lib/Support/Unix/Signals.inc @@ -14,6 +14,7 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/Support/Format.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" @@ -33,9 +34,6 @@ #if HAVE_SYS_STAT_H #include <sys/stat.h> #endif -#if HAVE_CXXABI_H -#include <cxxabi.h> -#endif #if HAVE_DLFCN_H #include <dlfcn.h> #endif @@ -45,15 +43,15 @@ #if HAVE_LINK_H #include <link.h> #endif -#if HAVE_UNWIND_BACKTRACE +#ifdef HAVE__UNWIND_BACKTRACE // FIXME: We should be able to use <unwind.h> for any target that has an // _Unwind_Backtrace function, but on FreeBSD the configure test passes // despite the function not existing, and on Android, <unwind.h> conflicts // with <link.h>. -#ifdef __GLIBC__ +#if defined(__GLIBC__) || defined(__APPLE__) #include <unwind.h> #else -#undef HAVE_UNWIND_BACKTRACE +#undef HAVE__UNWIND_BACKTRACE #endif #endif @@ -120,14 +118,15 @@ static void RegisterHandler(int Signal) { } #if defined(HAVE_SIGALTSTACK) -// Hold onto the old alternate signal stack so that it's not reported as a leak. -// We don't make any attempt to remove our alt signal stack if we remove our -// signal handlers; that can't be done reliably if someone else is also trying -// to do the same thing. +// Hold onto both the old and new alternate signal stack so that it's not +// reported as a leak. We don't make any attempt to remove our alt signal +// stack if we remove our signal handlers; that can't be done reliably if +// someone else is also trying to do the same thing. static stack_t OldAltStack; +static void* NewAltStackPointer; static void CreateSigAltStack() { - const size_t AltStackSize = MINSIGSTKSZ + 8192; + const size_t AltStackSize = MINSIGSTKSZ + 64 * 1024; // If we're executing on the alternate stack, or we already have an alternate // signal stack that we're happy with, there's nothing for us to do. Don't @@ -140,6 +139,7 @@ static void CreateSigAltStack() { stack_t AltStack = {}; AltStack.ss_sp = reinterpret_cast<char *>(malloc(AltStackSize)); + NewAltStackPointer = AltStack.ss_sp; // Save to avoid reporting a leak. AltStack.ss_size = AltStackSize; if (sigaltstack(&AltStack, &OldAltStack) != 0) free(AltStack.ss_sp); @@ -284,7 +284,7 @@ bool llvm::sys::RemoveFileOnSignal(StringRef Filename, void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) { sys::SmartScopedLock<true> Guard(*SignalsMutex); std::vector<std::string>::reverse_iterator RI = - std::find(FilesToRemove->rbegin(), FilesToRemove->rend(), Filename); + find(reverse(*FilesToRemove), Filename); std::vector<std::string>::iterator I = FilesToRemove->end(); if (RI != FilesToRemove->rend()) I = FilesToRemove->erase(RI.base()-1); @@ -298,7 +298,7 @@ void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { RegisterHandlers(); } -#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) && HAVE_LINK_H && \ +#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && HAVE_LINK_H && \ (defined(__linux__) || defined(__FreeBSD__) || \ defined(__FreeBSD_kernel__) || defined(__NetBSD__)) struct DlIteratePhdrData { @@ -353,9 +353,9 @@ static bool findModulesAndOffsets(void **StackTrace, int Depth, StringSaver &StrPool) { return false; } -#endif // defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) && ... +#endif // defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && ... -#if defined(ENABLE_BACKTRACES) && defined(HAVE_UNWIND_BACKTRACE) +#if ENABLE_BACKTRACES && defined(HAVE__UNWIND_BACKTRACE) static int unwindBacktrace(void **StackTrace, int MaxEntries) { if (MaxEntries < 0) return 0; @@ -393,7 +393,7 @@ static int unwindBacktrace(void **StackTrace, int MaxEntries) { // On glibc systems we have the 'backtrace' function, which works nicely, but // doesn't demangle symbols. void llvm::sys::PrintStackTrace(raw_ostream &OS) { -#if defined(ENABLE_BACKTRACES) +#if ENABLE_BACKTRACES static void *StackTrace[256]; int depth = 0; #if defined(HAVE_BACKTRACE) @@ -401,7 +401,7 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) { if (!depth) depth = backtrace(StackTrace, static_cast<int>(array_lengthof(StackTrace))); #endif -#if defined(HAVE_UNWIND_BACKTRACE) +#if defined(HAVE__UNWIND_BACKTRACE) // Try _Unwind_Backtrace() if backtrace() failed. if (!depth) depth = unwindBacktrace(StackTrace, @@ -441,12 +441,8 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) { if (dlinfo.dli_sname != nullptr) { OS << ' '; -# if HAVE_CXXABI_H int res; - char* d = abi::__cxa_demangle(dlinfo.dli_sname, nullptr, nullptr, &res); -# else - char* d = NULL; -# endif + char* d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res); if (!d) OS << dlinfo.dli_sname; else OS << d; free(d); @@ -479,7 +475,7 @@ void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0, AddSignalHandler(PrintStackTraceSignalHandler, nullptr); -#if defined(__APPLE__) && defined(ENABLE_CRASH_OVERRIDES) +#if defined(__APPLE__) && ENABLE_CRASH_OVERRIDES // Environment variable to disable any kind of crash dialog. if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) { mach_port_t self = mach_task_self(); diff --git a/contrib/llvm/lib/Support/Unix/TimeValue.inc b/contrib/llvm/lib/Support/Unix/TimeValue.inc deleted file mode 100644 index 042e0dacc346..000000000000 --- a/contrib/llvm/lib/Support/Unix/TimeValue.inc +++ /dev/null @@ -1,54 +0,0 @@ -//===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the Unix specific portion of the TimeValue class. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic UNIX code that -//=== is guaranteed to work on *all* UNIX variants. -//===----------------------------------------------------------------------===// - -#include "Unix.h" - -namespace llvm { - using namespace sys; - -std::string TimeValue::str() const { - time_t OurTime = time_t(this->toEpochTime()); - struct tm Storage; - struct tm *LT = ::localtime_r(&OurTime, &Storage); - assert(LT); - char Buffer1[sizeof("YYYY-MM-DD HH:MM:SS")]; - strftime(Buffer1, sizeof(Buffer1), "%Y-%m-%d %H:%M:%S", LT); - char Buffer2[sizeof("YYYY-MM-DD HH:MM:SS.MMMUUUNNN")]; - snprintf(Buffer2, sizeof(Buffer2), "%s.%.9u", Buffer1, this->nanoseconds()); - return std::string(Buffer2); -} - -TimeValue TimeValue::now() { - struct timeval the_time; - timerclear(&the_time); - if (0 != ::gettimeofday(&the_time,nullptr)) { - // This is *really* unlikely to occur because the only gettimeofday - // errors concern the timezone parameter which we're passing in as 0. - // In the unlikely case it does happen, just return MinTime, no error - // message needed. - return MinTime(); - } - - return TimeValue( - static_cast<TimeValue::SecondsType>( the_time.tv_sec + - PosixZeroTimeSeconds ), - static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * - NANOSECONDS_PER_MICROSECOND ) ); -} - -} diff --git a/contrib/llvm/lib/Support/Unix/Unix.h b/contrib/llvm/lib/Support/Unix/Unix.h index 871e612f6c16..239a6d60aaef 100644 --- a/contrib/llvm/lib/Support/Unix/Unix.h +++ b/contrib/llvm/lib/Support/Unix/Unix.h @@ -19,7 +19,8 @@ //=== is guaranteed to work on all UNIX variants. //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Support/Chrono.h" #include "llvm/Support/Errno.h" #include <algorithm> #include <assert.h> @@ -48,6 +49,10 @@ # include <dlfcn.h> #endif +#ifdef HAVE_FCNTL_H +# include <fcntl.h> +#endif + /// This function builds an error message into \p ErrMsg using the \p prefix /// string and the Unix error number given by \p errnum. If errnum is -1, the /// default then the value of errno is used. @@ -65,4 +70,37 @@ static inline bool MakeErrMsg( return true; } +namespace llvm { +namespace sys { + +/// Convert a struct timeval to a duration. Note that timeval can be used both +/// as a time point and a duration. Be sure to check what the input represents. +inline std::chrono::microseconds toDuration(const struct timeval &TV) { + return std::chrono::seconds(TV.tv_sec) + + std::chrono::microseconds(TV.tv_usec); +} + +/// Convert a time point to struct timespec. +inline struct timespec toTimeSpec(TimePoint<> TP) { + using namespace std::chrono; + + struct timespec RetVal; + RetVal.tv_sec = toTimeT(TP); + RetVal.tv_nsec = (TP.time_since_epoch() % seconds(1)).count(); + return RetVal; +} + +/// Convert a time point to struct timeval. +inline struct timeval toTimeVal(TimePoint<std::chrono::microseconds> TP) { + using namespace std::chrono; + + struct timeval RetVal; + RetVal.tv_sec = toTimeT(TP); + RetVal.tv_usec = (TP.time_since_epoch() % seconds(1)).count(); + return RetVal; +} + +} // namespace sys +} // namespace llvm + #endif |