Bug#911817: llvm-toolchain-6.0: on hurd-i386 llvm-config returns bogus values

Samuel Thibault sthibault at debian.org
Thu Oct 25 11:49:00 BST 2018


Samuel Thibault, le jeu. 25 oct. 2018 09:22:29 +0200, a ecrit:
> I will NMU the attached patch to fix it.

I have NMU-ed the attached debdiff.

Samuel
-------------- next part --------------
diff -Nru llvm-toolchain-6.0-6.0.1/debian/changelog llvm-toolchain-6.0-6.0.1/debian/changelog
--- llvm-toolchain-6.0-6.0.1/debian/changelog	2018-10-16 22:18:39.000000000 +0200
+++ llvm-toolchain-6.0-6.0.1/debian/changelog	2018-10-25 00:44:54.000000000 +0200
@@ -1,3 +1,11 @@
+llvm-toolchain-6.0 (1:6.0.1-9.2) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * debian/patches/D53557-hurd-self-exe-realpath.diff: Fix paths returned by
+    llvm-config (Closes: Bug#911817).
+
+ -- Samuel Thibault <sthibault at debian.org>  Wed, 24 Oct 2018 22:44:54 +0000
+
 llvm-toolchain-6.0 (1:6.0.1-9.1) unstable; urgency=medium
 
   * Non-maintainer upload.
diff -Nru llvm-toolchain-6.0-6.0.1/debian/patches/D53557-hurd-self-exe-realpath.diff llvm-toolchain-6.0-6.0.1/debian/patches/D53557-hurd-self-exe-realpath.diff
--- llvm-toolchain-6.0-6.0.1/debian/patches/D53557-hurd-self-exe-realpath.diff	1970-01-01 01:00:00.000000000 +0100
+++ llvm-toolchain-6.0-6.0.1/debian/patches/D53557-hurd-self-exe-realpath.diff	2018-10-25 00:44:54.000000000 +0200
@@ -0,0 +1,72 @@
+[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 -Nru llvm-toolchain-6.0-6.0.1/debian/patches/series llvm-toolchain-6.0-6.0.1/debian/patches/series
--- llvm-toolchain-6.0-6.0.1/debian/patches/series	2018-10-16 22:18:39.000000000 +0200
+++ llvm-toolchain-6.0-6.0.1/debian/patches/series	2018-10-25 00:44:54.000000000 +0200
@@ -70,3 +70,4 @@
 powerpcspe-add-missing-include-path.diff
 hurd-lib_Support_Unix_Path.inc.diff
 hurd-tools_llvm-shlib_CMakeLists.txt.diff
+D53557-hurd-self-exe-realpath.diff


More information about the Pkg-llvm-team mailing list