diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-16 16:51:38 +0000 | 
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-16 16:51:38 +0000 | 
| commit | c69102774f9739c81ae1285ed9ae62405071c63c (patch) | |
| tree | 458dd25677a43aef6390ecadb4423817f00e08b0 /lib/System | |
| parent | ea5b2dd11c0526581803e7eb58224a2eabf191e6 (diff) | |
Notes
Diffstat (limited to 'lib/System')
| -rw-r--r-- | lib/System/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | lib/System/DynamicLibrary.cpp | 42 | ||||
| -rw-r--r-- | lib/System/Memory.cpp | 3 | ||||
| -rw-r--r-- | lib/System/SearchForAddressOfSpecialSymbol.cpp | 64 | ||||
| -rw-r--r-- | lib/System/Unix/Program.inc | 3 | ||||
| -rw-r--r-- | lib/System/Valgrind.cpp | 54 | ||||
| -rw-r--r-- | lib/System/Win32/Path.inc | 22 | 
7 files changed, 139 insertions, 51 deletions
diff --git a/lib/System/CMakeLists.txt b/lib/System/CMakeLists.txt index a56a1f78bb72..b43c3afa5248 100644 --- a/lib/System/CMakeLists.txt +++ b/lib/System/CMakeLists.txt @@ -12,10 +12,12 @@ add_llvm_library(LLVMSystem    Process.cpp    Program.cpp    RWMutex.cpp +  SearchForAddressOfSpecialSymbol.cpp    Signals.cpp    ThreadLocal.cpp    Threading.cpp    TimeValue.cpp +  Valgrind.cpp    Unix/Alarm.inc    Unix/Host.inc    Unix/Memory.inc diff --git a/lib/System/DynamicLibrary.cpp b/lib/System/DynamicLibrary.cpp index 63baa6d787c2..d6f3140a88e8 100644 --- a/lib/System/DynamicLibrary.cpp +++ b/lib/System/DynamicLibrary.cpp @@ -69,44 +69,8 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,    return false;  } -static void *SearchForAddressOfSpecialSymbol(const char* symbolName) { -#define EXPLICIT_SYMBOL(SYM) \ -   extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM - -  // If this is darwin, it has some funky issues, try to solve them here.  Some -  // important symbols are marked 'private external' which doesn't allow -  // SearchForAddressOfSymbol to find them.  As such, we special case them here, -  // there is only a small handful of them. - -#ifdef __APPLE__ -  { -    EXPLICIT_SYMBOL(__ashldi3); -    EXPLICIT_SYMBOL(__ashrdi3); -    EXPLICIT_SYMBOL(__cmpdi2); -    EXPLICIT_SYMBOL(__divdi3); -    EXPLICIT_SYMBOL(__eprintf); -    EXPLICIT_SYMBOL(__fixdfdi); -    EXPLICIT_SYMBOL(__fixsfdi); -    EXPLICIT_SYMBOL(__fixunsdfdi); -    EXPLICIT_SYMBOL(__fixunssfdi); -    EXPLICIT_SYMBOL(__floatdidf); -    EXPLICIT_SYMBOL(__floatdisf); -    EXPLICIT_SYMBOL(__lshrdi3); -    EXPLICIT_SYMBOL(__moddi3); -    EXPLICIT_SYMBOL(__udivdi3); -    EXPLICIT_SYMBOL(__umoddi3); -  } -#endif - -#ifdef __CYGWIN__ -  { -    EXPLICIT_SYMBOL(_alloca); -    EXPLICIT_SYMBOL(__main); -  } -#endif - -#undef EXPLICIT_SYMBOL -  return 0; +namespace llvm { +void *SearchForAddressOfSpecialSymbol(const char* symbolName);  }  void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) { @@ -132,7 +96,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {      }    } -  if (void *Result = SearchForAddressOfSpecialSymbol(symbolName)) +  if (void *Result = llvm::SearchForAddressOfSpecialSymbol(symbolName))      return Result;  // This macro returns the address of a well-known, explicit symbol diff --git a/lib/System/Memory.cpp b/lib/System/Memory.cpp index e2d838dce026..ef23b8d12aab 100644 --- a/lib/System/Memory.cpp +++ b/lib/System/Memory.cpp @@ -13,6 +13,7 @@  //===----------------------------------------------------------------------===//  #include "llvm/System/Memory.h" +#include "llvm/System/Valgrind.h"  #include "llvm/Config/config.h"  namespace llvm { @@ -68,4 +69,6 @@ void llvm::sys::Memory::InvalidateInstructionCache(const void *Addr,  #  endif  #endif  // end apple + +  ValgrindDiscardTranslations(Addr, Len);  } diff --git a/lib/System/SearchForAddressOfSpecialSymbol.cpp b/lib/System/SearchForAddressOfSpecialSymbol.cpp new file mode 100644 index 000000000000..73b484c2e917 --- /dev/null +++ b/lib/System/SearchForAddressOfSpecialSymbol.cpp @@ -0,0 +1,64 @@ +//===- SearchForAddressOfSpecialSymbol.cpp - Function addresses -*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +//  This file pulls the addresses of certain symbols out of the linker.  It must +//  include as few header files as possible because it declares the symbols as +//  void*, which would conflict with the actual symbol type if any header +//  declared it. +// +//===----------------------------------------------------------------------===// + +#include <string.h> + +// Must declare the symbols in the global namespace. +static void *DoSearch(const char* symbolName) { +#define EXPLICIT_SYMBOL(SYM) \ +   extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM + +  // If this is darwin, it has some funky issues, try to solve them here.  Some +  // important symbols are marked 'private external' which doesn't allow +  // SearchForAddressOfSymbol to find them.  As such, we special case them here, +  // there is only a small handful of them. + +#ifdef __APPLE__ +  { +    EXPLICIT_SYMBOL(__ashldi3); +    EXPLICIT_SYMBOL(__ashrdi3); +    EXPLICIT_SYMBOL(__cmpdi2); +    EXPLICIT_SYMBOL(__divdi3); +    EXPLICIT_SYMBOL(__eprintf); +    EXPLICIT_SYMBOL(__fixdfdi); +    EXPLICIT_SYMBOL(__fixsfdi); +    EXPLICIT_SYMBOL(__fixunsdfdi); +    EXPLICIT_SYMBOL(__fixunssfdi); +    EXPLICIT_SYMBOL(__floatdidf); +    EXPLICIT_SYMBOL(__floatdisf); +    EXPLICIT_SYMBOL(__lshrdi3); +    EXPLICIT_SYMBOL(__moddi3); +    EXPLICIT_SYMBOL(__udivdi3); +    EXPLICIT_SYMBOL(__umoddi3); +  } +#endif + +#ifdef __CYGWIN__ +  { +    EXPLICIT_SYMBOL(_alloca); +    EXPLICIT_SYMBOL(__main); +  } +#endif + +#undef EXPLICIT_SYMBOL +  return 0; +} + +namespace llvm { +void *SearchForAddressOfSpecialSymbol(const char* symbolName) { +  return DoSearch(symbolName); +} +}  // namespace llvm diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index c10498a375ac..b4cc875df8c7 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -113,8 +113,9 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {    }    // Install it as the requested FD -  if (-1 == dup2(InFD, FD)) { +  if (dup2(InFD, FD) == -1) {      MakeErrMsg(ErrMsg, "Cannot dup2"); +    close(InFD);      return true;    }    close(InFD);      // Close the original FD diff --git a/lib/System/Valgrind.cpp b/lib/System/Valgrind.cpp new file mode 100644 index 000000000000..c76cfe40d3e0 --- /dev/null +++ b/lib/System/Valgrind.cpp @@ -0,0 +1,54 @@ +//===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +//  Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is +//  defined.  If we have valgrind.h but valgrind isn't running, its macros are +//  no-ops. +// +//===----------------------------------------------------------------------===// + +#include "llvm/System/Valgrind.h" +#include "llvm/Config/config.h" + +#if HAVE_VALGRIND_VALGRIND_H +#include <valgrind/valgrind.h> + +static bool InitNotUnderValgrind() { +  return !RUNNING_ON_VALGRIND; +} + +// This bool is negated from what we'd expect because code may run before it +// gets initialized.  If that happens, it will appear to be 0 (false), and we +// want that to cause the rest of the code in this file to run the +// Valgrind-provided macros. +static const bool NotUnderValgrind = InitNotUnderValgrind(); + +bool llvm::sys::RunningOnValgrind() { +  if (NotUnderValgrind) +    return false; +  return RUNNING_ON_VALGRIND; +} + +void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { +  if (NotUnderValgrind) +    return; + +  VALGRIND_DISCARD_TRANSLATIONS(Addr, Len); +} + +#else  // !HAVE_VALGRIND_VALGRIND_H + +bool llvm::sys::RunningOnValgrind() { +  return false; +} + +void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { +} + +#endif  // !HAVE_VALGRIND_VALGRIND_H diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index b5f63743c9c9..5a0052f3cb21 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -126,7 +126,7 @@ Path::isValid() const {  }  void Path::makeAbsolute() { -  TCHAR  FullPath[MAX_PATH + 1] = {0};  +  TCHAR  FullPath[MAX_PATH + 1] = {0};    LPTSTR FilePart = NULL;    DWORD RetLength = ::GetFullPathNameA(path.c_str(), @@ -161,7 +161,7 @@ Path::isAbsolute(const char *NameStart, unsigned NameLen) {    }  } -bool  +bool  Path::isAbsolute() const {    // FIXME: This does not handle correctly an absolute path starting from    // a drive letter or in UNC format. @@ -174,9 +174,9 @@ Path::isAbsolute() const {      default:        return path[0] == '/' || (path[1] == ':' && path[2] == '/');    } -}  +} -static Path *TempDirectory = NULL; +static Path *TempDirectory;  Path  Path::GetTemporaryDirectory(std::string* ErrMsg) { @@ -266,7 +266,7 @@ Path  Path::GetCurrentDirectory() {    char pathname[MAX_PATH];    ::GetCurrentDirectoryA(MAX_PATH,pathname); -  return Path(pathname);   +  return Path(pathname);  }  /// GetMainExecutable - Return the path to the main executable, given the @@ -448,7 +448,7 @@ Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {      MakeErrMsg(ErrMsg, path + ": can't get status of file");      return true;    } -     +    if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {      if (ErrMsg)        *ErrMsg = path + ": not a directory"; @@ -617,7 +617,7 @@ Path::createDirectoryOnDisk(bool create_parents, std::string* ErrMsg) {        *next = 0;        if (!CreateDirectory(pathname, NULL) &&            GetLastError() != ERROR_ALREADY_EXISTS) -          return MakeErrMsg(ErrMsg,  +          return MakeErrMsg(ErrMsg,              std::string(pathname) + ": Can't create directory: ");        *next++ = '/';      } @@ -649,7 +649,7 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {    WIN32_FILE_ATTRIBUTE_DATA fi;    if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))      return true; -     +    if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {      // If it doesn't exist, we're done.      if (!exists()) @@ -706,7 +706,7 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {      pathname[lastchar] = 0;      if (!RemoveDirectory(pathname)) -      return MakeErrMsg(ErrStr,  +      return MakeErrMsg(ErrStr,          std::string(pathname) + ": Can't destroy directory: ");      return false;    } else { @@ -753,7 +753,7 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {  bool  Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {    if (!MoveFileEx(path.c_str(), newName.c_str(), MOVEFILE_REPLACE_EXISTING)) -    return MakeErrMsg(ErrMsg, "Can't move '" + path + "' to '" + newName.path  +    return MakeErrMsg(ErrMsg, "Can't move '" + path + "' to '" + newName.path          + "': ");    return false;  } @@ -764,7 +764,7 @@ Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrMsg) const {    if (!si.isFile) {      return true;    } -   +    HANDLE h = CreateFile(path.c_str(),                          FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,                          FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,  | 
