<div dir="ltr">Looks like this caused <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/204/steps/check-clang%20msan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/204/steps/check-clang%20msan/logs/stdio</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 29, 2014 at 4:09 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chandlerc<br>
Date: Mon Dec 29 06:09:08 2014<br>
New Revision: 224924<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224924&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=224924&view=rev</a><br>
Log:<br>
[multilib] Teach Clang's code about multilib by threading<br>
a CLANG_LIBDIR_SUFFIX down from the build system and using that as part<br>
of the default resource dir computation.<br>
<br>
Without this, essentially nothing that uses the clang driver works when<br>
building clang with a libdir suffix. This is probably the single biggest<br>
missing piece of support for multilib as without this people could hack<br>
clang to end up installed in the correct location, but it would then<br>
fail to find its own basic resources. I know of at least one distro that<br>
has some variation on this patch to hack around this; hopefully they'll<br>
be able to use the libdir suffix functionality directly as the rest of<br>
these bits land.<br>
<br>
This required fixing a copy of the code to compute Clang's resource<br>
directory that is buried inside of the frontend (!!!). It had bitrotted<br>
significantly relative to the driver code. I've made it essentially<br>
a clone of the driver code in order to keep tests (which use cc1<br>
heavily) passing. This copy should probably just be removed and the<br>
frontend taught to always rely on an explicit resource directory from<br>
the driver, but that is a much more invasive change for another day.<br>
<br>
I've also updated one test which actually encoded the resource directory<br>
in its checked output to tolerate multilib suffixes.<br>
<br>
Note that this relies on a prior LLVM commit to add a stub to the<br>
autoconf build system for this variable.<br>
<br>
Modified:<br>
    cfe/trunk/CMakeLists.txt<br>
    cfe/trunk/include/clang/Config/config.h.cmake<br>
    cfe/trunk/include/clang/Config/<a href="http://config.h.in" target="_blank">config.h.in</a><br>
    cfe/trunk/lib/Driver/Driver.cpp<br>
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
    cfe/trunk/test/Preprocessor/iwithprefix.c<br>
<br>
Modified: cfe/trunk/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/CMakeLists.txt (original)<br>
+++ cfe/trunk/CMakeLists.txt Mon Dec 29 06:09:08 2014<br>
@@ -193,6 +193,9 @@ endif()<br>
 set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING<br>
   "Vendor-specific uti.")<br>
<br>
+# The libdir suffix must exactly match whatever LLVM's configuration used.<br>
+set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")<br>
+<br>
 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})<br>
 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Config/config.h.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.cmake?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.cmake?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Config/config.h.cmake (original)<br>
+++ cfe/trunk/include/clang/Config/config.h.cmake Mon Dec 29 06:09:08 2014<br>
@@ -8,6 +8,9 @@<br>
 /* Bug report URL. */<br>
 #define BUG_REPORT_URL "${BUG_REPORT_URL}"<br>
<br>
+/* Multilib suffix for libdir. */<br>
+#define CLANG_LIBDIR_SUFFIX "${CLANG_LIBDIR_SUFFIX}"<br>
+<br>
 /* Relative directory for resource files */<br>
 #define CLANG_RESOURCE_DIR "${CLANG_RESOURCE_DIR}"<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Config/<a href="http://config.h.in" target="_blank">config.h.in</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.in?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.in?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Config/<a href="http://config.h.in" target="_blank">config.h.in</a> (original)<br>
+++ cfe/trunk/include/clang/Config/<a href="http://config.h.in" target="_blank">config.h.in</a> Mon Dec 29 06:09:08 2014<br>
@@ -8,6 +8,9 @@<br>
 /* Bug report URL. */<br>
 #undef BUG_REPORT_URL<br>
<br>
+/* Multilib suffix for libdir. */<br>
+#undef CLANG_LIBDIR_SUFFIX<br>
+<br>
 /* Relative directory for resource files */<br>
 #undef CLANG_RESOURCE_DIR<br>
<br>
<br>
Modified: cfe/trunk/lib/Driver/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Driver.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Dec 29 06:09:08 2014<br>
@@ -65,10 +65,13 @@ Driver::Driver(StringRef ClangExecutable<br>
   // Compute the path to the resource directory.<br>
   StringRef ClangResourceDir(CLANG_RESOURCE_DIR);<br>
   SmallString<128> P(Dir);<br>
-  if (ClangResourceDir != "")<br>
+  if (ClangResourceDir != "") {<br>
     llvm::sys::path::append(P, ClangResourceDir);<br>
-  else<br>
-    llvm::sys::path::append(P, "..", "lib", "clang", CLANG_VERSION_STRING);<br>
+  } else {<br>
+    StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);<br>
+    llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",<br>
+                            CLANG_VERSION_STRING);<br>
+  }<br>
   ResourceDir = P.str();<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Dec 29 06:09:08 2014<br>
@@ -10,6 +10,7 @@<br>
 #include "clang/Frontend/CompilerInvocation.h"<br>
 #include "clang/Basic/FileManager.h"<br>
 #include "clang/Basic/Version.h"<br>
+#include "clang/Config/config.h"<br>
 #include "clang/Driver/DriverDiagnostic.h"<br>
 #include "clang/Driver/Options.h"<br>
 #include "clang/Driver/Util.h"<br>
@@ -982,14 +983,18 @@ static InputKind ParseFrontendArgs(Front<br>
<br>
 std::string CompilerInvocation::GetResourcesPath(const char *Argv0,<br>
                                                  void *MainAddr) {<br>
-  SmallString<128> P(llvm::sys::fs::getMainExecutable(Argv0, MainAddr));<br>
+  StringRef ClangExecutable = llvm::sys::fs::getMainExecutable(Argv0, MainAddr);<br>
+  StringRef Dir = llvm::sys::path::parent_path(ClangExecutable);<br>
<br>
-  if (!P.empty()) {<br>
-    llvm::sys::path::remove_filename(P); // Remove /clang from foo/bin/clang<br>
-    llvm::sys::path::remove_filename(P); // Remove /bin   from foo/bin<br>
-<br>
-    // Get foo/lib/clang/<version>/include<br>
-    llvm::sys::path::append(P, "lib", "clang", CLANG_VERSION_STRING);<br>
+  // Compute the path to the resource directory.<br>
+  StringRef ClangResourceDir(CLANG_RESOURCE_DIR);<br>
+  SmallString<128> P(Dir);<br>
+  if (ClangResourceDir != "") {<br>
+    llvm::sys::path::append(P, ClangResourceDir);<br>
+  } else {<br>
+    StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);<br>
+    llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",<br>
+                            CLANG_VERSION_STRING);<br>
   }<br>
<br>
   return P.str();<br>
<br>
Modified: cfe/trunk/test/Preprocessor/iwithprefix.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/iwithprefix.c?rev=224924&r1=224923&r2=224924&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/iwithprefix.c?rev=224924&r1=224923&r2=224924&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Preprocessor/iwithprefix.c (original)<br>
+++ cfe/trunk/test/Preprocessor/iwithprefix.c Mon Dec 29 06:09:08 2014<br>
@@ -9,7 +9,7 @@<br>
<br>
 // CHECK: #include <...> search starts here:<br>
 // CHECK: {{.*}}.tmps/first<br>
-// CHECK: {{/|\\}}lib{{/|\\}}clang{{/|\\}}{{[.0-9]+}}{{/|\\}}include<br>
+// CHECK: {{/|\\}}lib{{(32|64)?}}{{/|\\}}clang{{/|\\}}{{[.0-9]+}}{{/|\\}}include<br>
 // CHECK: {{.*}}.tmps/second<br>
 // CHECK-NOT: {{.*}}.tmps<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div>