Bug 1278135 - Link against less of Clang and LLVM statically when building the clang plugin, r=glandium
authorMichael Layzell <michael@thelayzells.com>
Thu, 02 Jun 2016 14:14:57 -0400
changeset 349711 0f7ec83d606e646f6c8732f21702361023bdd5dc
parent 349710 4ed23ebeb25b01a2b43cfb78683a88700eced6a4
child 349712 744db8f3ad0c72caf78aeac2e24df78b7a374d17
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1278135
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1278135 - Link against less of Clang and LLVM statically when building the clang plugin, r=glandium
build/autoconf/clang-plugin.m4
--- a/build/autoconf/clang-plugin.m4
+++ b/build/autoconf/clang-plugin.m4
@@ -32,34 +32,36 @@ if test -n "$ENABLE_CLANG_PLUGIN"; then
       AC_MSG_ERROR([Cannot find an llvm-config binary for building a clang plugin])
     fi
 
     AC_MSG_RESULT([$LLVMCONFIG])
 
     if test -z "$LLVMCONFIG"; then
         AC_MSG_ERROR([Cannot find an llvm-config binary for building a clang plugin])
     fi
-    LLVM_CXXFLAGS=`$LLVMCONFIG --cxxflags`
-    dnl The clang package we use on OSX is old, and its llvm-config doesn't
-    dnl recognize --system-libs, so ask for that separately.  llvm-config's
-    dnl failure here is benign, so we can ignore it if it happens.
-    dnl Use tr instead of xargs in order to avoid problems with path separators on Windows.
-    LLVM_LDFLAGS=`$LLVMCONFIG --system-libs | tr '\n' ' '`
-    LLVM_LDFLAGS="$LLVM_LDFLAGS `$LLVMCONFIG --ldflags --libs core mc analysis asmparser mcparser bitreader option profiledata | tr '\n' ' '`"
+    dnl For some reason the llvm-config downloaded from clang.llvm.org for clang3_8
+    dnl produces a -isysroot flag for a sysroot which might not ship when passed
+    dnl --cxxflags. We use sed to remove this argument so that builds work on OSX
+    LLVM_CXXFLAGS=`$LLVMCONFIG --cxxflags | sed -e 's/-isysroot [[^ ]]*//'`
+
+    dnl We are loaded into clang, so we don't need to link to very many things,
+    dnl we just need to link to clangASTMatchers because it is not used by clang
+    LLVM_LDFLAGS=`$LLVMCONFIG --ldflags | tr '\n' ' '`
 
     if test "${HOST_OS_ARCH}" = "Darwin"; then
-        CLANG_LDFLAGS="-lclangFrontend -lclangDriver -lclangSerialization"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangParse -lclangSema -lclangAnalysis"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangEdit -lclangAST -lclangLex"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangBasic -lclangASTMatchers"
+        dnl We need to make sure that we use the symbols coming from the clang
+        dnl binary. In order to do this, we need to pass -flat_namespace and
+        dnl -undefined suppress to the linker. This makes sure that we link the
+        dnl symbols into the flat namespace provided by clang, and thus get
+        dnl access to all of the symbols which are undefined in our dylib as we
+        dnl are building it right now, and also that we don't fail the build
+        dnl due to undefined symbols (which will be provided by clang).
+        CLANG_LDFLAGS="-Wl,-flat_namespace -Wl,-undefined,suppress -lclangASTMatchers"
     elif test "${HOST_OS_ARCH}" = "WINNT"; then
-        CLANG_LDFLAGS="clangFrontend.lib clangDriver.lib clangSerialization.lib"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS clangParse.lib clangSema.lib clangAnalysis.lib"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS clangEdit.lib clangAST.lib clangLex.lib"
-        CLANG_LDFLAGS="$CLANG_LDFLAGS clangBasic.lib clangASTMatchers.lib"
+        CLANG_LDFLAGS="clangASTMatchers.lib"
     else
         CLANG_LDFLAGS="-lclangASTMatchers"
     fi
 
     if test -n "$CLANG_CL"; then
         dnl The llvm-config coming with clang-cl may give us arguments in the
         dnl /ARG form, which in msys will be interpreted as a path name.  So we
         dnl need to split the args and convert the leading slashes that we find
@@ -97,24 +99,27 @@ if test -n "$ENABLE_CLANG_PLUGIN"; then
     dnl correctly, so we have to detect this at configure time.
     AC_CACHE_CHECK(for new ASTMatcher API,
                    ac_cv_have_new_ASTMatcher_api,
         [
             AC_LANG_SAVE
             AC_LANG_CPLUSPLUS
             _SAVE_CXXFLAGS="$CXXFLAGS"
             _SAVE_CXX="$CXX"
+            _SAVE_MACOSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET"
+            unset MACOSX_DEPLOYMENT_TARGET
             CXXFLAGS="${LLVM_CXXFLAGS}"
             CXX="${HOST_CXX}"
             AC_TRY_COMPILE([#include "clang/ASTMatchers/ASTMatchers.h"],
                            [clang::ast_matchers::cxxConstructExpr();],
                            ac_cv_have_new_ASTMatcher_names="yes",
                            ac_cv_have_new_ASTMatcher_names="no")
             CXX="$_SAVE_CXX"
             CXXFLAGS="$_SAVE_CXXFLAGS"
+            export MACOSX_DEPLOYMENT_TARGET="$_SAVE_MACOSX_DEPLOYMENT_TARGET"
             AC_LANG_RESTORE
         ])
     if test "$ac_cv_have_new_ASTMatcher_names" = "yes"; then
       LLVM_CXXFLAGS="$LLVM_CXXFLAGS -DHAVE_NEW_ASTMATCHER_NAMES"
     fi
 
     AC_DEFINE(MOZ_CLANG_PLUGIN)
 fi