diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -125,7 +125,8 @@ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ - defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) + defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \ + (defined(__sun__) && defined(__svr4__)) static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { @@ -283,6 +284,20 @@ // Fall back to the classical detection. if (getprogpath(exe_path, argv0)) return exe_path; +#elif defined(__sun__) && defined(__svr4__) + char exe_path[PATH_MAX]; + const char *aPath = "/proc/self/execname"; + if (sys::fs::exists(aPath)) { + int fd = open(aPath, O_RDONLY); + if (fd == -1) + return ""; + if (read(fd, exe_path, sizeof(exe_path)) < 0) + return ""; + return exe_path; + } + // Fall back to the classical detection. + if (getprogpath(exe_path, argv0) != NULL) + return exe_path; #elif defined(__MVS__) int token = 0; W_PSPROC buf;