Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ad36f9

Browse files
serge-sans-paillevstinner
authored andcommitted
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
1 parent 890423f commit 5ad36f9

4 files changed

Lines changed: 235 additions & 83 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Have --with-lto works correctly with clang.

aclocal.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
1515
dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
16-
dnl serial 11 (pkg-config-0.29.1)
16+
dnl serial 11 (pkg-config-0.29)
1717
dnl
1818
dnl Copyright © 2004 Scott James Remnant <[email protected]>.
1919
dnl Copyright © 2012-2015 Dan Nicholson <[email protected]>
@@ -55,7 +55,7 @@ dnl
5555
dnl See the "Since" comment for each macro you use to see what version
5656
dnl of the macros you require.
5757
m4_defun([PKG_PREREQ],
58-
[m4_define([PKG_MACROS_VERSION], [0.29.1])
58+
[m4_define([PKG_MACROS_VERSION], [0.29])
5959
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
6060
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
6161
])dnl PKG_PREREQ

configure

Lines changed: 184 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,18 @@ BASECFLAGS
671671
CFLAGS_ALIASING
672672
OPT
673673
LLVM_PROF_FOUND
674-
target_os
675-
target_vendor
676-
target_cpu
677-
target
678674
LLVM_PROFDATA
679675
LLVM_PROF_ERR
680676
LLVM_PROF_FILE
681677
LLVM_PROF_MERGER
682678
PGO_PROF_USE_FLAG
683679
PGO_PROF_GEN_FLAG
680+
LLVM_AR_FOUND
681+
target_os
682+
target_vendor
683+
target_cpu
684+
target
685+
LLVM_AR
684686
DEF_MAKE_RULE
685687
DEF_MAKE_ALL_RULE
686688
ABIFLAGS
@@ -6388,6 +6390,26 @@ else
63886390
DEF_MAKE_RULE="all"
63896391
fi
63906392

6393+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
6394+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6395+
# non-suffixed name in their versioned llvm directory.
6396+
6397+
llvm_bin_dir=''
6398+
llvm_path="${PATH}"
6399+
if test "${CC}" = "clang"
6400+
then
6401+
clang_bin=`which clang`
6402+
# Some systems install clang elsewhere as a symlink to the real path
6403+
# which is where the related llvm tools are located.
6404+
if test -L "${clang_bin}"
6405+
then
6406+
clang_dir=`dirname "${clang_bin}"`
6407+
clang_bin=`readlink "${clang_bin}"`
6408+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
6409+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
6410+
fi
6411+
fi
6412+
63916413
# Enable LTO flags
63926414
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
63936415
$as_echo_n "checking for --with-lto... " >&6; }
@@ -6413,65 +6435,8 @@ fi
64136435
if test "$Py_LTO" = 'true' ; then
64146436
case $CC in
64156437
*clang*)
6416-
case $ac_sys_system in
6417-
Darwin*)
6418-
# Any changes made here should be reflected in the GCC+Darwin case below
6419-
LTOFLAGS="-flto -Wl,-export_dynamic"
6420-
;;
6421-
*)
6422-
LTOFLAGS="-flto"
6423-
;;
6424-
esac
6425-
;;
6426-
*gcc*)
6427-
case $ac_sys_system in
6428-
Darwin*)
6429-
LTOFLAGS="-flto -Wl,-export_dynamic"
6430-
;;
6431-
*)
6432-
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6433-
;;
6434-
esac
6435-
;;
6436-
esac
64376438

6438-
if test "$ac_cv_prog_cc_g" = "yes"
6439-
then
6440-
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6441-
# to get debug symbols.
6442-
LTOFLAGS="$LTOFLAGS -g"
6443-
fi
6444-
6445-
CFLAGS="$CFLAGS $LTOFLAGS"
6446-
LDFLAGS="$LDFLAGS $LTOFLAGS"
6447-
fi
6448-
6449-
# Enable PGO flags.
6450-
6451-
6452-
6453-
6454-
6455-
# Make this work on systems where llvm tools are not installed with their
6456-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6457-
# non-suffixed name in their versioned llvm directory.
6458-
llvm_bin_dir=''
6459-
llvm_path="${PATH}"
6460-
if test "${CC}" = "clang"
6461-
then
6462-
clang_bin=`which clang`
6463-
# Some systems install clang elsewhere as a symlink to the real path
6464-
# which is where the related llvm tools are located.
6465-
if test -L "${clang_bin}"
6466-
then
6467-
clang_dir=`dirname "${clang_bin}"`
6468-
clang_bin=`readlink "${clang_bin}"`
6469-
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
6470-
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
6471-
fi
6472-
fi
6473-
6474-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
6439+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
64756440
$as_echo_n "checking target system type... " >&6; }
64766441
if ${ac_cv_target+:} false; then :
64776442
$as_echo_n "(cached) " >&6
@@ -6510,6 +6475,163 @@ test -n "$target_alias" &&
65106475
test "$program_prefix$program_suffix$program_transform_name" = \
65116476
NONENONEs,x,x, &&
65126477
program_prefix=${target_alias}-
6478+
# Extract the first word of "$target_alias-llvm-ar", so it can be a program name with args.
6479+
set dummy $target_alias-llvm-ar; ac_word=$2
6480+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6481+
$as_echo_n "checking for $ac_word... " >&6; }
6482+
if ${ac_cv_path_LLVM_AR+:} false; then :
6483+
$as_echo_n "(cached) " >&6
6484+
else
6485+
case $LLVM_AR in
6486+
[\\/]* | ?:[\\/]*)
6487+
ac_cv_path_LLVM_AR="$LLVM_AR" # Let the user override the test with a path.
6488+
;;
6489+
*)
6490+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6491+
for as_dir in ${llvm_path}
6492+
do
6493+
IFS=$as_save_IFS
6494+
test -z "$as_dir" && as_dir=.
6495+
for ac_exec_ext in '' $ac_executable_extensions; do
6496+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6497+
ac_cv_path_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6498+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6499+
break 2
6500+
fi
6501+
done
6502+
done
6503+
IFS=$as_save_IFS
6504+
6505+
;;
6506+
esac
6507+
fi
6508+
LLVM_AR=$ac_cv_path_LLVM_AR
6509+
if test -n "$LLVM_AR"; then
6510+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_AR" >&5
6511+
$as_echo "$LLVM_AR" >&6; }
6512+
else
6513+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6514+
$as_echo "no" >&6; }
6515+
fi
6516+
6517+
6518+
if test -z "$ac_cv_path_LLVM_AR"; then
6519+
if test "$build" = "$target"; then
6520+
ac_pt_LLVM_AR=$LLVM_AR
6521+
# Extract the first word of "llvm-ar", so it can be a program name with args.
6522+
set dummy llvm-ar; ac_word=$2
6523+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6524+
$as_echo_n "checking for $ac_word... " >&6; }
6525+
if ${ac_cv_path_ac_pt_LLVM_AR+:} false; then :
6526+
$as_echo_n "(cached) " >&6
6527+
else
6528+
case $ac_pt_LLVM_AR in
6529+
[\\/]* | ?:[\\/]*)
6530+
ac_cv_path_ac_pt_LLVM_AR="$ac_pt_LLVM_AR" # Let the user override the test with a path.
6531+
;;
6532+
*)
6533+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6534+
for as_dir in ${llvm_path}
6535+
do
6536+
IFS=$as_save_IFS
6537+
test -z "$as_dir" && as_dir=.
6538+
for ac_exec_ext in '' $ac_executable_extensions; do
6539+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6540+
ac_cv_path_ac_pt_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6541+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6542+
break 2
6543+
fi
6544+
done
6545+
done
6546+
IFS=$as_save_IFS
6547+
6548+
test -z "$ac_cv_path_ac_pt_LLVM_AR" && ac_cv_path_ac_pt_LLVM_AR="''"
6549+
;;
6550+
esac
6551+
fi
6552+
ac_pt_LLVM_AR=$ac_cv_path_ac_pt_LLVM_AR
6553+
if test -n "$ac_pt_LLVM_AR"; then
6554+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_LLVM_AR" >&5
6555+
$as_echo "$ac_pt_LLVM_AR" >&6; }
6556+
else
6557+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6558+
$as_echo "no" >&6; }
6559+
fi
6560+
6561+
LLVM_AR=$ac_pt_LLVM_AR
6562+
else
6563+
LLVM_AR="''"
6564+
fi
6565+
else
6566+
LLVM_AR="$ac_cv_path_LLVM_AR"
6567+
fi
6568+
6569+
6570+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
6571+
then
6572+
LLVM_AR_FOUND="found"
6573+
else
6574+
LLVM_AR_FOUND="not-found"
6575+
fi
6576+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
6577+
then
6578+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
6579+
if test -n "${found_llvm_ar}"
6580+
then
6581+
LLVM_AR='/usr/bin/xcrun llvm-ar'
6582+
LLVM_AR_FOUND=found
6583+
{ $as_echo "$as_me:${as_lineno-$LINENO}: llvm-ar found via xcrun: ${LLVM_AR}" >&5
6584+
$as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
6585+
fi
6586+
fi
6587+
if test $LLVM_AR_FOUND = not-found
6588+
then
6589+
LLVM_PROFR_ERR=yes
6590+
as_fn_error $? "llvm-ar is required for a --with-lto build with clang but could not be found." "$LINENO" 5
6591+
else
6592+
LLVM_AR_ERR=no
6593+
fi
6594+
AR="${LLVM_AR}"
6595+
case $ac_sys_system in
6596+
Darwin*)
6597+
# Any changes made here should be reflected in the GCC+Darwin case below
6598+
LTOFLAGS="-flto -Wl,-export_dynamic"
6599+
;;
6600+
*)
6601+
LTOFLAGS="-flto"
6602+
;;
6603+
esac
6604+
;;
6605+
*gcc*)
6606+
case $ac_sys_system in
6607+
Darwin*)
6608+
LTOFLAGS="-flto -Wl,-export_dynamic"
6609+
;;
6610+
*)
6611+
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6612+
;;
6613+
esac
6614+
;;
6615+
esac
6616+
6617+
if test "$ac_cv_prog_cc_g" = "yes"
6618+
then
6619+
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6620+
# to get debug symbols.
6621+
LTOFLAGS="$LTOFLAGS -g"
6622+
fi
6623+
6624+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
6625+
LDFLAGS="$LDFLAGS $LTOFLAGS"
6626+
fi
6627+
6628+
# Enable PGO flags.
6629+
6630+
6631+
6632+
6633+
6634+
65136635
# Extract the first word of "$target_alias-llvm-profdata", so it can be a program name with args.
65146636
set dummy $target_alias-llvm-profdata; ac_word=$2
65156637
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5

configure.ac

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,26 @@ else
12651265
DEF_MAKE_RULE="all"
12661266
fi
12671267

1268+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
1269+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1270+
# non-suffixed name in their versioned llvm directory.
1271+
1272+
llvm_bin_dir=''
1273+
llvm_path="${PATH}"
1274+
if test "${CC}" = "clang"
1275+
then
1276+
clang_bin=`which clang`
1277+
# Some systems install clang elsewhere as a symlink to the real path
1278+
# which is where the related llvm tools are located.
1279+
if test -L "${clang_bin}"
1280+
then
1281+
clang_dir=`dirname "${clang_bin}"`
1282+
clang_bin=`readlink "${clang_bin}"`
1283+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1284+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1285+
fi
1286+
fi
1287+
12681288
# Enable LTO flags
12691289
AC_MSG_CHECKING(for --with-lto)
12701290
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in any build. Disabled by default.]),
@@ -1281,6 +1301,33 @@ fi],
12811301
if test "$Py_LTO" = 'true' ; then
12821302
case $CC in
12831303
*clang*)
1304+
AC_SUBST(LLVM_AR)
1305+
AC_PATH_TARGET_TOOL(LLVM_AR, llvm-ar, '', ${llvm_path})
1306+
AC_SUBST(LLVM_AR_FOUND)
1307+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
1308+
then
1309+
LLVM_AR_FOUND="found"
1310+
else
1311+
LLVM_AR_FOUND="not-found"
1312+
fi
1313+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
1314+
then
1315+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
1316+
if test -n "${found_llvm_ar}"
1317+
then
1318+
LLVM_AR='/usr/bin/xcrun llvm-ar'
1319+
LLVM_AR_FOUND=found
1320+
AC_MSG_NOTICE([llvm-ar found via xcrun: ${LLVM_AR}])
1321+
fi
1322+
fi
1323+
if test $LLVM_AR_FOUND = not-found
1324+
then
1325+
LLVM_PROFR_ERR=yes
1326+
AC_MSG_ERROR([llvm-ar is required for a --with-lto build with clang but could not be found.])
1327+
else
1328+
LLVM_AR_ERR=no
1329+
fi
1330+
AR="${LLVM_AR}"
12841331
case $ac_sys_system in
12851332
Darwin*)
12861333
# Any changes made here should be reflected in the GCC+Darwin case below
@@ -1310,7 +1357,7 @@ if test "$Py_LTO" = 'true' ; then
13101357
LTOFLAGS="$LTOFLAGS -g"
13111358
fi
13121359

1313-
CFLAGS="$CFLAGS $LTOFLAGS"
1360+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
13141361
LDFLAGS="$LDFLAGS $LTOFLAGS"
13151362
fi
13161363

@@ -1320,24 +1367,6 @@ AC_SUBST(PGO_PROF_USE_FLAG)
13201367
AC_SUBST(LLVM_PROF_MERGER)
13211368
AC_SUBST(LLVM_PROF_FILE)
13221369
AC_SUBST(LLVM_PROF_ERR)
1323-
# Make this work on systems where llvm tools are not installed with their
1324-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1325-
# non-suffixed name in their versioned llvm directory.
1326-
llvm_bin_dir=''
1327-
llvm_path="${PATH}"
1328-
if test "${CC}" = "clang"
1329-
then
1330-
clang_bin=`which clang`
1331-
# Some systems install clang elsewhere as a symlink to the real path
1332-
# which is where the related llvm tools are located.
1333-
if test -L "${clang_bin}"
1334-
then
1335-
clang_dir=`dirname "${clang_bin}"`
1336-
clang_bin=`readlink "${clang_bin}"`
1337-
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1338-
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1339-
fi
1340-
fi
13411370
AC_SUBST(LLVM_PROFDATA)
13421371
AC_PATH_TARGET_TOOL(LLVM_PROFDATA, llvm-profdata, '', ${llvm_path})
13431372
AC_SUBST(LLVM_PROF_FOUND)

0 commit comments

Comments
 (0)