diff options
author | Derek Schuff <dschuff@chromium.org> | 2012-10-01 11:20:30 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2012-10-01 11:20:30 -0700 |
commit | b3423dd295c69f78bd731f1ad65ad90ce3efa36f (patch) | |
tree | 0e872df2f0333ed1806d9e0a6906b2f5ebd58512 /lib/Support/Unix/Path.inc | |
parent | a27c28b1427dc2082ab2b31efdbb25f9fde31b61 (diff) | |
parent | 72f0976c1b91c7ba50dce4d0ad0289dc14d37f81 (diff) |
Merge commit '72f0976c1b91c7ba50dce4d0ad0289dc14d37f81'
Conflicts:
lib/Target/ARM/ARMISelDAGToDAG.cpp
lib/Target/Mips/MipsISelLowering.cpp
lib/Target/Mips/MipsSubtarget.cpp
Diffstat (limited to 'lib/Support/Unix/Path.inc')
-rw-r--r-- | lib/Support/Unix/Path.inc | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index f70e60d3f5..b82371a7b6 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -267,7 +267,8 @@ Path::GetCurrentDirectory() { } #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ - defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) + defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \ + defined(__linux__) || defined(__CYGWIN__) static int test_dir(char buf[PATH_MAX], char ret[PATH_MAX], const char *dir, const char *bin) @@ -345,9 +346,17 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { return Path(exe_path); #elif defined(__linux__) || defined(__CYGWIN__) char exe_path[MAXPATHLEN]; - ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)); - if (len >= 0) - return Path(StringRef(exe_path, len)); + StringRef aPath("/proc/self/exe"); + if (sys::fs::exists(aPath)) { + // /proc is not always mounted under Linux (chroot for example). + ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path)); + if (len >= 0) + return Path(StringRef(exe_path, len)); + } else { + // Fall back to the classical detection. + if (getprogpath(exe_path, argv0) != NULL) + return Path(exe_path); + } #elif defined(HAVE_DLFCN_H) // Use dladdr to get executable path if available. Dl_info DLInfo; |