[PATCH] D109374: [Support] Implement getMainExecutable on Solaris
Rainer Orth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 7 10:10:32 PDT 2021
ro created this revision.
ro added reviewers: jrtc27, dim, emaste, arichardson.
Herald added subscribers: dexonsmith, hiraditya, fedor.sergeev, krytarowski.
ro requested review of this revision.
Herald added a project: LLVM.
Many `flang` tests currently `FAIL` on Solaris because the module files aren't found. I could trace this to `sys::fs::getMainExecutable` not being implemented.
This patch does this and fixes all affected `flang` tests.
Tested on `amd64-pc-solaris2.11`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109374
Files:
llvm/lib/Support/Unix/Path.inc
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109374.371112.patch
Type: text/x-patch
Size: 1283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210907/ee7ff300/attachment.bin>
More information about the llvm-commits
mailing list