From 8b68a85095a525a9722b7b70735a95ac42a1d8f5 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Thu, 22 Nov 2018 19:50:33 +0100 Subject: [PATCH] hurd: Fix paths returned by llvm-config D53557-hurd-self-exe-realpath.diff (See Bug#911817) --- debian/changelog | 7 ++ .../D53557-hurd-self-exe-realpath.diff | 74 +++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 82 insertions(+) create mode 100644 debian/patches/D53557-hurd-self-exe-realpath.diff diff --git a/debian/changelog b/debian/changelog index 7a099dd4..7c6af0b2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +llvm-toolchain-7 (1:7.0.1~+rc2-6) UNRELEASED; urgency=medium + + * D53557-hurd-self-exe-realpath.diff: Fix paths returned by + llvm-config (See Bug#911817). + + -- Samuel Thibault Thu, 22 Nov 2018 19:49:52 +0100 + llvm-toolchain-7 (1:7.0.1~+rc2-5) unstable; urgency=medium [ Samuel Thibault ] diff --git a/debian/patches/D53557-hurd-self-exe-realpath.diff b/debian/patches/D53557-hurd-self-exe-realpath.diff new file mode 100644 index 00000000..216b6ba9 --- /dev/null +++ b/debian/patches/D53557-hurd-self-exe-realpath.diff @@ -0,0 +1,74 @@ +r345104 | rnk | 2018-10-24 01:35:43 +0200 (mer. 24 oct. 2018) | 25 lignes + +[hurd] Make getMainExecutable get the real binary path + +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. + +Patch by Samuel Thibault! + +While making changes here, I reformatted this block a bit to reduce +indentation and match 2 space indent style. + +Differential Revision: https://reviews.llvm.org/D53557 + +Index: llvm-toolchain-6.0-6.0.1/lib/Support/Unix/Path.inc +=================================================================== +--- llvm-toolchain-6.0-6.0.1.orig/lib/Support/Unix/Path.inc ++++ llvm-toolchain-6.0-6.0.1/lib/Support/Unix/Path.inc +@@ -191,14 +191,34 @@ std::string getMainExecutable(const char + char exe_path[MAXPATHLEN]; + StringRef aPath("/proc/self/exe"); + 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); ++ // /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 ""; ++ ++ // Null terminate the string for realpath. readlink never null ++ // terminates its output. ++ len = std::min(len, ssize_t(sizeof(exe_path) - 1)); ++ exe_path[len] = '\0'; ++ ++ // At least on GNU/Hurd, /proc/self/exe is a symlink to the path that ++ // was used to start the program, and not the eventual binary file. ++ // We thus needs to run realpath over it to get the actual place ++ // where llvm was installed. ++#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)) +- return exe_path; ++ // Fall back to the classical detection. ++ if (getprogpath(exe_path, argv0)) ++ return exe_path; + } + #elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) + // Use dladdr to get executable path if available. diff --git a/debian/patches/series b/debian/patches/series index 07afa1e2..fb2276fc 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -97,3 +97,4 @@ D54378-hurd-triple.diff D54379-hurd-triple-clang.diff D54677-hurd-path_max.diff hurd-cxx-paths.diff +D53557-hurd-self-exe-realpath.diff