Skip to content

Commit f83ee47

Browse files
stratakisserge-sans-paille
authored andcommitted
bpo-28015: Support LTO build with clang (GH-9908) (GH-10922)
.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 5ad36f9) Co-authored-by: serge-sans-paille <[email protected]>
1 parent df5d884 commit f83ee47

File tree

4 files changed

+235
-83
lines changed

4 files changed

+235
-83
lines changed
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
@@ -6493,6 +6495,26 @@ else
64936495
DEF_MAKE_RULE="all"
64946496
fi
64956497

6498+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
6499+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6500+
# non-suffixed name in their versioned llvm directory.
6501+
6502+
llvm_bin_dir=''
6503+
llvm_path="${PATH}"
6504+
if test "${CC}" = "clang"
6505+
then
6506+
clang_bin=`which clang`
6507+
# Some systems install clang elsewhere as a symlink to the real path
6508+
# which is where the related llvm tools are located.
6509+
if test -L "${clang_bin}"
6510+
then
6511+
clang_dir=`dirname "${clang_bin}"`
6512+
clang_bin=`readlink "${clang_bin}"`
6513+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
6514+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
6515+
fi
6516+
fi
6517+
64966518
# Enable LTO flags
64976519
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
64986520
$as_echo_n "checking for --with-lto... " >&6; }
@@ -6518,65 +6540,8 @@ fi
65186540
if test "$Py_LTO" = 'true' ; then
65196541
case $CC in
65206542
*clang*)
6521-
case $ac_sys_system in
6522-
Darwin*)
6523-
# Any changes made here should be reflected in the GCC+Darwin case below
6524-
LTOFLAGS="-flto -Wl,-export_dynamic"
6525-
;;
6526-
*)
6527-
LTOFLAGS="-flto"
6528-
;;
6529-
esac
6530-
;;
6531-
*gcc*)
6532-
case $ac_sys_system in
6533-
Darwin*)
6534-
LTOFLAGS="-flto -Wl,-export_dynamic"
6535-
;;
6536-
*)
6537-
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6538-
;;
6539-
esac
6540-
;;
6541-
esac
65426543

6543-
if test "$ac_cv_prog_cc_g" = "yes"
6544-
then
6545-
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6546-
# to get debug symbols.
6547-
LTOFLAGS="$LTOFLAGS -g"
6548-
fi
6549-
6550-
CFLAGS="$CFLAGS $LTOFLAGS"
6551-
LDFLAGS="$LDFLAGS $LTOFLAGS"
6552-
fi
6553-
6554-
# Enable PGO flags.
6555-
6556-
6557-
6558-
6559-
6560-
# Make this work on systems where llvm tools are not installed with their
6561-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6562-
# non-suffixed name in their versioned llvm directory.
6563-
llvm_bin_dir=''
6564-
llvm_path="${PATH}"
6565-
if test "${CC}" = "clang"
6566-
then
6567-
clang_bin=`which clang`
6568-
# Some systems install clang elsewhere as a symlink to the real path
6569-
# which is where the related llvm tools are located.
6570-
if test -L "${clang_bin}"
6571-
then
6572-
clang_dir=`dirname "${clang_bin}"`
6573-
clang_bin=`readlink "${clang_bin}"`
6574-
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
6575-
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
6576-
fi
6577-
fi
6578-
6579-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
6544+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
65806545
$as_echo_n "checking target system type... " >&6; }
65816546
if ${ac_cv_target+:} false; then :
65826547
$as_echo_n "(cached) " >&6
@@ -6615,6 +6580,163 @@ test -n "$target_alias" &&
66156580
test "$program_prefix$program_suffix$program_transform_name" = \
66166581
NONENONEs,x,x, &&
66176582
program_prefix=${target_alias}-
6583+
# Extract the first word of "$target_alias-llvm-ar", so it can be a program name with args.
6584+
set dummy $target_alias-llvm-ar; ac_word=$2
6585+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6586+
$as_echo_n "checking for $ac_word... " >&6; }
6587+
if ${ac_cv_path_LLVM_AR+:} false; then :
6588+
$as_echo_n "(cached) " >&6
6589+
else
6590+
case $LLVM_AR in
6591+
[\\/]* | ?:[\\/]*)
6592+
ac_cv_path_LLVM_AR="$LLVM_AR" # Let the user override the test with a path.
6593+
;;
6594+
*)
6595+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6596+
for as_dir in ${llvm_path}
6597+
do
6598+
IFS=$as_save_IFS
6599+
test -z "$as_dir" && as_dir=.
6600+
for ac_exec_ext in '' $ac_executable_extensions; do
6601+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6602+
ac_cv_path_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6603+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6604+
break 2
6605+
fi
6606+
done
6607+
done
6608+
IFS=$as_save_IFS
6609+
6610+
;;
6611+
esac
6612+
fi
6613+
LLVM_AR=$ac_cv_path_LLVM_AR
6614+
if test -n "$LLVM_AR"; then
6615+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_AR" >&5
6616+
$as_echo "$LLVM_AR" >&6; }
6617+
else
6618+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6619+
$as_echo "no" >&6; }
6620+
fi
6621+
6622+
6623+
if test -z "$ac_cv_path_LLVM_AR"; then
6624+
if test "$build" = "$target"; then
6625+
ac_pt_LLVM_AR=$LLVM_AR
6626+
# Extract the first word of "llvm-ar", so it can be a program name with args.
6627+
set dummy llvm-ar; ac_word=$2
6628+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6629+
$as_echo_n "checking for $ac_word... " >&6; }
6630+
if ${ac_cv_path_ac_pt_LLVM_AR+:} false; then :
6631+
$as_echo_n "(cached) " >&6
6632+
else
6633+
case $ac_pt_LLVM_AR in
6634+
[\\/]* | ?:[\\/]*)
6635+
ac_cv_path_ac_pt_LLVM_AR="$ac_pt_LLVM_AR" # Let the user override the test with a path.
6636+
;;
6637+
*)
6638+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6639+
for as_dir in ${llvm_path}
6640+
do
6641+
IFS=$as_save_IFS
6642+
test -z "$as_dir" && as_dir=.
6643+
for ac_exec_ext in '' $ac_executable_extensions; do
6644+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6645+
ac_cv_path_ac_pt_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6646+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6647+
break 2
6648+
fi
6649+
done
6650+
done
6651+
IFS=$as_save_IFS
6652+
6653+
test -z "$ac_cv_path_ac_pt_LLVM_AR" && ac_cv_path_ac_pt_LLVM_AR="''"
6654+
;;
6655+
esac
6656+
fi
6657+
ac_pt_LLVM_AR=$ac_cv_path_ac_pt_LLVM_AR
6658+
if test -n "$ac_pt_LLVM_AR"; then
6659+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_LLVM_AR" >&5
6660+
$as_echo "$ac_pt_LLVM_AR" >&6; }
6661+
else
6662+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6663+
$as_echo "no" >&6; }
6664+
fi
6665+
6666+
LLVM_AR=$ac_pt_LLVM_AR
6667+
else
6668+
LLVM_AR="''"
6669+
fi
6670+
else
6671+
LLVM_AR="$ac_cv_path_LLVM_AR"
6672+
fi
6673+
6674+
6675+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
6676+
then
6677+
LLVM_AR_FOUND="found"
6678+
else
6679+
LLVM_AR_FOUND="not-found"
6680+
fi
6681+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
6682+
then
6683+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
6684+
if test -n "${found_llvm_ar}"
6685+
then
6686+
LLVM_AR='/usr/bin/xcrun llvm-ar'
6687+
LLVM_AR_FOUND=found
6688+
{ $as_echo "$as_me:${as_lineno-$LINENO}: llvm-ar found via xcrun: ${LLVM_AR}" >&5
6689+
$as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
6690+
fi
6691+
fi
6692+
if test $LLVM_AR_FOUND = not-found
6693+
then
6694+
LLVM_PROFR_ERR=yes
6695+
as_fn_error $? "llvm-ar is required for a --with-lto build with clang but could not be found." "$LINENO" 5
6696+
else
6697+
LLVM_AR_ERR=no
6698+
fi
6699+
AR="${LLVM_AR}"
6700+
case $ac_sys_system in
6701+
Darwin*)
6702+
# Any changes made here should be reflected in the GCC+Darwin case below
6703+
LTOFLAGS="-flto -Wl,-export_dynamic"
6704+
;;
6705+
*)
6706+
LTOFLAGS="-flto"
6707+
;;
6708+
esac
6709+
;;
6710+
*gcc*)
6711+
case $ac_sys_system in
6712+
Darwin*)
6713+
LTOFLAGS="-flto -Wl,-export_dynamic"
6714+
;;
6715+
*)
6716+
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6717+
;;
6718+
esac
6719+
;;
6720+
esac
6721+
6722+
if test "$ac_cv_prog_cc_g" = "yes"
6723+
then
6724+
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6725+
# to get debug symbols.
6726+
LTOFLAGS="$LTOFLAGS -g"
6727+
fi
6728+
6729+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
6730+
LDFLAGS="$LDFLAGS $LTOFLAGS"
6731+
fi
6732+
6733+
# Enable PGO flags.
6734+
6735+
6736+
6737+
6738+
6739+
66186740
# Extract the first word of "$target_alias-llvm-profdata", so it can be a program name with args.
66196741
set dummy $target_alias-llvm-profdata; ac_word=$2
66206742
{ $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
@@ -1308,6 +1308,26 @@ else
13081308
DEF_MAKE_RULE="all"
13091309
fi
13101310

1311+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
1312+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1313+
# non-suffixed name in their versioned llvm directory.
1314+
1315+
llvm_bin_dir=''
1316+
llvm_path="${PATH}"
1317+
if test "${CC}" = "clang"
1318+
then
1319+
clang_bin=`which clang`
1320+
# Some systems install clang elsewhere as a symlink to the real path
1321+
# which is where the related llvm tools are located.
1322+
if test -L "${clang_bin}"
1323+
then
1324+
clang_dir=`dirname "${clang_bin}"`
1325+
clang_bin=`readlink "${clang_bin}"`
1326+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1327+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1328+
fi
1329+
fi
1330+
13111331
# Enable LTO flags
13121332
AC_MSG_CHECKING(for --with-lto)
13131333
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in any build. Disabled by default.]),
@@ -1324,6 +1344,33 @@ fi],
13241344
if test "$Py_LTO" = 'true' ; then
13251345
case $CC in
13261346
*clang*)
1347+
AC_SUBST(LLVM_AR)
1348+
AC_PATH_TARGET_TOOL(LLVM_AR, llvm-ar, '', ${llvm_path})
1349+
AC_SUBST(LLVM_AR_FOUND)
1350+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
1351+
then
1352+
LLVM_AR_FOUND="found"
1353+
else
1354+
LLVM_AR_FOUND="not-found"
1355+
fi
1356+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
1357+
then
1358+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
1359+
if test -n "${found_llvm_ar}"
1360+
then
1361+
LLVM_AR='/usr/bin/xcrun llvm-ar'
1362+
LLVM_AR_FOUND=found
1363+
AC_MSG_NOTICE([llvm-ar found via xcrun: ${LLVM_AR}])
1364+
fi
1365+
fi
1366+
if test $LLVM_AR_FOUND = not-found
1367+
then
1368+
LLVM_PROFR_ERR=yes
1369+
AC_MSG_ERROR([llvm-ar is required for a --with-lto build with clang but could not be found.])
1370+
else
1371+
LLVM_AR_ERR=no
1372+
fi
1373+
AR="${LLVM_AR}"
13271374
case $ac_sys_system in
13281375
Darwin*)
13291376
# Any changes made here should be reflected in the GCC+Darwin case below
@@ -1353,7 +1400,7 @@ if test "$Py_LTO" = 'true' ; then
13531400
LTOFLAGS="$LTOFLAGS -g"
13541401
fi
13551402

1356-
CFLAGS="$CFLAGS $LTOFLAGS"
1403+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
13571404
LDFLAGS="$LDFLAGS $LTOFLAGS"
13581405
fi
13591406

@@ -1363,24 +1410,6 @@ AC_SUBST(PGO_PROF_USE_FLAG)
13631410
AC_SUBST(LLVM_PROF_MERGER)
13641411
AC_SUBST(LLVM_PROF_FILE)
13651412
AC_SUBST(LLVM_PROF_ERR)
1366-
# Make this work on systems where llvm tools are not installed with their
1367-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1368-
# non-suffixed name in their versioned llvm directory.
1369-
llvm_bin_dir=''
1370-
llvm_path="${PATH}"
1371-
if test "${CC}" = "clang"
1372-
then
1373-
clang_bin=`which clang`
1374-
# Some systems install clang elsewhere as a symlink to the real path
1375-
# which is where the related llvm tools are located.
1376-
if test -L "${clang_bin}"
1377-
then
1378-
clang_dir=`dirname "${clang_bin}"`
1379-
clang_bin=`readlink "${clang_bin}"`
1380-
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1381-
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1382-
fi
1383-
fi
13841413
AC_SUBST(LLVM_PROFDATA)
13851414
AC_PATH_TARGET_TOOL(LLVM_PROFDATA, llvm-profdata, '', ${llvm_path})
13861415
AC_SUBST(LLVM_PROF_FOUND)

0 commit comments

Comments
 (0)