svn commit: r354707 - head/contrib/llvm/lib/Support/Unix
Ed Maste
emaste at FreeBSD.org
Thu Nov 14 15:10:01 UTC 2019
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;
More information about the svn-src-all
mailing list