diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2009-09-09 12:09:08 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2009-09-09 12:09:08 +0000 |
commit | d8b0630027ee12502ee16932ff22b865ed738594 (patch) | |
tree | 654e22144a4f87137a161f2d95c16444da8557bd /lib/System/Unix | |
parent | 581af5f10a1a49979ff7bcc5f0fc48d5fc287b19 (diff) | |
download | external_llvm-d8b0630027ee12502ee16932ff22b865ed738594.zip external_llvm-d8b0630027ee12502ee16932ff22b865ed738594.tar.gz external_llvm-d8b0630027ee12502ee16932ff22b865ed738594.tar.bz2 |
Add a shortcut for OS X to Path::GetMainExecutable. This gives a nice speedup on
clang's testsuite.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81333 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index d7aa711..89285b4 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -57,6 +57,10 @@ #include <dlfcn.h> #endif +#ifdef __APPLE__ +#include <mach-o/dyld.h> +#endif + // Put in a hack for Cygwin which falsely reports that the mkdtemp function // is available when it is not. #ifdef __CYGWIN__ @@ -336,7 +340,17 @@ getprogpath(char ret[PATH_MAX], const char *bin) /// GetMainExecutable - Return the path to the main executable, given the /// value of argv[0] from program startup. Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { -#if defined(__FreeBSD__) +#if defined(__APPLE__) + // On OS X the executable path is saved to the stack by dyld. Reading it + // from there is much faster than calling dladdr, especially for large + // binaries with symbols. + char exe_path[MAXPATHLEN]; + uint32_t size = sizeof(exe_path); + if (_NSGetExecutablePath(exe_path, &size) == 0) { + char link_path[MAXPATHLEN]; + return Path(std::string(realpath(exe_path, link_path))); + } +#elif defined(__FreeBSD__) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL) |