From bec3ce0cb50895d9b41a78938b079672e6999e15 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 26 Sep 2012 08:30:35 +0000 Subject: The assumption that /proc/self/exe always exists is incorrect. For example, under a Linux chroot, /proc/ might not be mounted. Therefor, we test if this file exist. If it is the case, use it (the current behavior). Otherwise, we fall back to the detection used by *BSD. The issue has been reported initially on the Debian bug tracker: http://bugs.debian.org/674588 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164676 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Path.inc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/Support/Unix') diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 6bddbdf7bd..6a5ebb8cd9 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -261,7 +261,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) @@ -337,9 +338,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; -- cgit v1.2.3-18-g5258 From 53347ed2f8b6a80a36b0450a13eaa44da983ac3d Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 28 Sep 2012 10:10:46 +0000 Subject: Make backtraces work again with both the configure and cmake build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164817 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Signals.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Support/Unix') diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 7d161a6a05..cf64fa8f38 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -243,7 +243,7 @@ void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { // On glibc systems we have the 'backtrace' function, which works nicely, but // doesn't demangle symbols. static void PrintStackTrace(void *) { -#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACE) +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) static void* StackTrace[256]; // Use backtrace() to output a backtrace on Linux systems with glibc. int depth = backtrace(StackTrace, -- cgit v1.2.3-18-g5258