llvm.org GIT mirror llvm / bec3ce0
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 Sylvestre Ledru 6 years ago
1 changed file(s) with 13 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
260260 }
261261
262262 #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
263 defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__)
263 defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
264 defined(__linux__) || defined(__CYGWIN__)
264265 static int
265266 test_dir(char buf[PATH_MAX], char ret[PATH_MAX],
266267 const char *dir, const char *bin)
336337 return Path(exe_path);
337338 #elif defined(__linux__) || defined(__CYGWIN__)
338339 char exe_path[MAXPATHLEN];
339 ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
340 if (len >= 0)
341 return Path(StringRef(exe_path, len));
340 StringRef aPath("/proc/self/exe");
341 if (sys::fs::exists(aPath)) {
342 // /proc is not always mounted under Linux (chroot for example).
343 ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path));
344 if (len >= 0)
345 return Path(StringRef(exe_path, len));
346 } else {
347 // Fall back to the classical detection.
348 if (getprogpath(exe_path, argv0) != NULL)
349 return Path(exe_path);
350 }
342351 #elif defined(HAVE_DLFCN_H)
343352 // Use dladdr to get executable path if available.
344353 Dl_info DLInfo;