Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Nov 2019 15:10:01 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r354707 - head/contrib/llvm/lib/Support/Unix
Message-ID:  <201911141510.xAEFA1xS002152@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Thu Nov 14 15:10:01 2019
New Revision: 354707
URL: https://svnweb.freebsd.org/changeset/base/354707

Log:
  llvm: use elf_aux_info to get executable's path, if available
  
  Obtained from:	LLVM a0a38b81ea
  MFC with:	r354692
  Sponsored by:	The FreeBSD Foundation

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

Modified: head/contrib/llvm/lib/Support/Unix/Path.inc
==============================================================================
--- head/contrib/llvm/lib/Support/Unix/Path.inc	Thu Nov 14 12:14:55 2019	(r354706)
+++ head/contrib/llvm/lib/Support/Unix/Path.inc	Thu Nov 14 15:10:01 2019	(r354707)
@@ -39,8 +39,13 @@
 #include <sys/attr.h>
 #include <copyfile.h>
 #elif defined(__FreeBSD__)
+#include <osreldate.h>
+#if __FreeBSD_version >= 1300057
+#include <sys/auxv.h>
+#else
 #include <machine/elf.h>
 extern char **environ;
+#endif
 #elif defined(__DragonFly__)
 #include <sys/mount.h>
 #endif
@@ -192,10 +197,17 @@ std::string getMainExecutable(const char *argv0, void 
   // sysctl may not return the desired path if there are multiple hardlinks
   // to the file.
   char exe_path[PATH_MAX];
+#if __FreeBSD_version >= 1300057
+  if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0)
+    return exe_path;
+#else
+  // elf_aux_info(AT_EXECPATH, ... is not available on older FreeBSD.  Fall
+  // back to finding the ELF auxiliary vectors after the processes's
+  // environment.
   char **p = ::environ;
   while (*p++ != 0)
     ;
-  // ELF auxiliary vectors immediately follow the process's environment.
+  // Iterate through auxiliary vectors for AT_EXECPATH.
   for (;;) {
     switch (*(uintptr_t *)p++) {
     case AT_EXECPATH:
@@ -205,6 +217,7 @@ std::string getMainExecutable(const char *argv0, void 
     }
     p++;
   }
+#endif
   // Fall back to argv[0] if auxiliary vectors are not available.
   if (getprogpath(exe_path, argv0) != NULL)
     return exe_path;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911141510.xAEFA1xS002152>