summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-24 17:32:04 -0700
committerGitHub <noreply@github.com>2018-10-24 17:32:04 -0700
commit69a3f153a92fd8c86080e8da477ee50df18fc0d1 (patch)
tree3f9609886fc42185cc352870408b4d289a3b20c7 /configure.ac
parentb3223940091b1ea52b0fd856801d79e2281e5b19 (diff)
downloadcpython-git-69a3f153a92fd8c86080e8da477ee50df18fc0d1.tar.gz
bpo-28015: Support LTO build with clang (GH-9908)
.o generated by clang in LTO mode actually are LLVM bitcode files, which leads to a few errors during configure/build step: - add lto flags to the BASECFLAGS instead of CFLAGS, as CFLAGS are used to build autoconf test case, and some are not compatible with clang LTO (they assume binary in the .o, not bitcode) - force llvm-ar instead of ar, as ar is not aware of .o files generated by clang -flto (cherry picked from commit 5ad36f9b21a3aa3b2265b1b43d73522cc3322df2) Co-authored-by: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac67
1 files changed, 48 insertions, 19 deletions
diff --git a/configure.ac b/configure.ac
index 620b48a6e7..e322d0ae6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1302,6 +1302,26 @@ else
DEF_MAKE_RULE="all"
fi
+# Make llvm-relatec checks work on systems where llvm tools are not installed with their
+# normal names in the default $PATH (ie: Ubuntu). They exist under the
+# non-suffixed name in their versioned llvm directory.
+
+llvm_bin_dir=''
+llvm_path="${PATH}"
+if test "${CC}" = "clang"
+then
+ clang_bin=`which clang`
+ # Some systems install clang elsewhere as a symlink to the real path
+ # which is where the related llvm tools are located.
+ if test -L "${clang_bin}"
+ then
+ clang_dir=`dirname "${clang_bin}"`
+ clang_bin=`readlink "${clang_bin}"`
+ llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
+ llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
+ fi
+fi
+
# Enable LTO flags
AC_MSG_CHECKING(for --with-lto)
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in any build. Disabled by default.]),
@@ -1318,6 +1338,33 @@ fi],
if test "$Py_LTO" = 'true' ; then
case $CC in
*clang*)
+ AC_SUBST(LLVM_AR)
+ AC_PATH_TARGET_TOOL(LLVM_AR, llvm-ar, '', ${llvm_path})
+ AC_SUBST(LLVM_AR_FOUND)
+ if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
+ then
+ LLVM_AR_FOUND="found"
+ else
+ LLVM_AR_FOUND="not-found"
+ fi
+ if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
+ then
+ found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
+ if test -n "${found_llvm_ar}"
+ then
+ LLVM_AR='/usr/bin/xcrun llvm-ar'
+ LLVM_AR_FOUND=found
+ AC_MSG_NOTICE([llvm-ar found via xcrun: ${LLVM_AR}])
+ fi
+ fi
+ if test $LLVM_AR_FOUND = not-found
+ then
+ LLVM_PROFR_ERR=yes
+ AC_MSG_ERROR([llvm-ar is required for a --with-lto build with clang but could not be found.])
+ else
+ LLVM_AR_ERR=no
+ fi
+ AR="${LLVM_AR}"
case $ac_sys_system in
Darwin*)
# Any changes made here should be reflected in the GCC+Darwin case below
@@ -1347,7 +1394,7 @@ if test "$Py_LTO" = 'true' ; then
LTOFLAGS="$LTOFLAGS -g"
fi
- CFLAGS="$CFLAGS $LTOFLAGS"
+ BASECFLAGS="$BASECFLAGS $LTOFLAGS"
LDFLAGS="$LDFLAGS $LTOFLAGS"
fi
@@ -1357,24 +1404,6 @@ AC_SUBST(PGO_PROF_USE_FLAG)
AC_SUBST(LLVM_PROF_MERGER)
AC_SUBST(LLVM_PROF_FILE)
AC_SUBST(LLVM_PROF_ERR)
-# Make this work on systems where llvm tools are not installed with their
-# normal names in the default $PATH (ie: Ubuntu). They exist under the
-# non-suffixed name in their versioned llvm directory.
-llvm_bin_dir=''
-llvm_path="${PATH}"
-if test "${CC}" = "clang"
-then
- clang_bin=`which clang`
- # Some systems install clang elsewhere as a symlink to the real path
- # which is where the related llvm tools are located.
- if test -L "${clang_bin}"
- then
- clang_dir=`dirname "${clang_bin}"`
- clang_bin=`readlink "${clang_bin}"`
- llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
- llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
- fi
-fi
AC_SUBST(LLVM_PROFDATA)
AC_PATH_TARGET_TOOL(LLVM_PROFDATA, llvm-profdata, '', ${llvm_path})
AC_SUBST(LLVM_PROF_FOUND)