[llvm] 69d79f1 - [Support] Implement getMainExecutable for OpenBSD

Brad Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 16:47:49 PDT 2023


Author: Brad Smith
Date: 2023-09-01T19:47:28-04:00
New Revision: 69d79f1f77147e5787efc8aa0300ea12dec95932

URL: https://github.com/llvm/llvm-project/commit/69d79f1f77147e5787efc8aa0300ea12dec95932
DIFF: https://github.com/llvm/llvm-project/commit/69d79f1f77147e5787efc8aa0300ea12dec95932.diff

LOG: [Support] Implement getMainExecutable for OpenBSD

This uses just argv[0] on OpenBSD. OpenBSD does not support the /proc filesystem.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159168

Added: 
    

Modified: 
    llvm/lib/Support/Unix/Path.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index a907efbf5506ff..68ca58fda3b8fe 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -233,8 +233,8 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
   // Fall back to argv[0] if auxiliary vectors are not available.
   if (getprogpath(exe_path, argv0) != NULL)
     return exe_path;
-#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || \
-    defined(__FreeBSD_kernel__) || defined(_AIX)
+#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || \
+    defined(__NetBSD__)
   const char *curproc = "/proc/curproc/file";
   char exe_path[PATH_MAX];
   if (sys::fs::exists(curproc)) {
@@ -283,6 +283,11 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
   // Fall back to the classical detection.
   if (getprogpath(exe_path, argv0))
     return exe_path;
+#elif defined(__OpenBSD__)
+  char exe_path[PATH_MAX];
+  // argv[0] only
+  if (getprogpath(exe_path, argv0) != NULL)
+    return exe_path;
 #elif defined(__sun__) && defined(__svr4__)
   char exe_path[PATH_MAX];
   const char *aPath = "/proc/self/execname";
@@ -951,7 +956,7 @@ ErrorOr<basic_file_status> directory_entry::status() const {
 // FreeBSD optionally provides /proc/self/fd, but it is incompatible with
 // Linux. The thing to use is realpath.
 //
-#if !defined(__FreeBSD__)
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
 #define TRY_PROC_SELF_FD
 #endif
 


        


More information about the llvm-commits mailing list