[PATCH] D53557: [hurd] Make getMainExecutable get the real binary path
Samuel Thibault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 23 00:46:09 PDT 2018
sthibaul created this revision.
Herald added subscribers: llvm-commits, kristina.
On GNU/Hurd, llvm-config is returning bogus value, such as:
$ llvm-config-6.0 --includedir
/usr/include
while it should be:
$ llvm-config-6.0 --includedir
/usr/lib/llvm-6.0/include
This is because getMainExecutable does not get the actual installation path. On GNU/Hurd, /proc/self/exe is indeed a symlink to the path that was used to start the program, and not the eventual binary file. Llvm's getMainExecutable thus needs to run realpath over it to get the actual place where llvm was installed (/usr/lib/llvm-6.0/bin/llvm-config), and not /usr/bin/llvm-config-6.0. This will not change the result on Linux, where /proc/self/exe already points to the eventual file.
Repository:
rL LLVM
https://reviews.llvm.org/D53557
Files:
lib/Support/Unix/Path.inc
Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -180,8 +180,22 @@
if (sys::fs::exists(aPath)) {
// /proc is not always mounted under Linux (chroot for example).
ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path));
- if (len >= 0)
- return std::string(exe_path, len);
+ if (len >= 0) {
+ if (len >= sizeof(exe_path))
+ len = sizeof(exe_path)-1;
+ exe_path[len] = '\0';
+
+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
+ char *real_path = realpath(exe_path, NULL);
+ std::string ret = std::string(real_path);
+ free(real_path);
+ return ret;
+#else
+ char real_path[MAXPATHLEN];
+ realpath(exe_path, real_path);
+ return std::string(real_path);
+#endif
+ }
} else {
// Fall back to the classical detection.
if (getprogpath(exe_path, argv0))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53557.170577.patch
Type: text/x-patch
Size: 1032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181023/7440fc65/attachment.bin>
More information about the llvm-commits
mailing list