Skip to content

Commit 69a3f15

Browse files
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 5ad36f9) Co-authored-by: serge-sans-paille <[email protected]>
1 parent b322394 commit 69a3f15

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
@@ -672,16 +672,18 @@ BASECFLAGS
672672
CFLAGS_ALIASING
673673
OPT
674674
LLVM_PROF_FOUND
675-
target_os
676-
target_vendor
677-
target_cpu
678-
target
679675
LLVM_PROFDATA
680676
LLVM_PROF_ERR
681677
LLVM_PROF_FILE
682678
LLVM_PROF_MERGER
683679
PGO_PROF_USE_FLAG
684680
PGO_PROF_GEN_FLAG
681+
LLVM_AR_FOUND
682+
target_os
683+
target_vendor
684+
target_cpu
685+
target
686+
LLVM_AR
685687
DEF_MAKE_RULE
686688
DEF_MAKE_ALL_RULE
687689
ABIFLAGS
@@ -6432,6 +6434,26 @@ else
64326434
DEF_MAKE_RULE="all"
64336435
fi
64346436

6437+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
6438+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6439+
# non-suffixed name in their versioned llvm directory.
6440+
6441+
llvm_bin_dir=''
6442+
llvm_path="${PATH}"
6443+
if test "${CC}" = "clang"
6444+
then
6445+
clang_bin=`which clang`
6446+
# Some systems install clang elsewhere as a symlink to the real path
6447+
# which is where the related llvm tools are located.
6448+
if test -L "${clang_bin}"
6449+
then
6450+
clang_dir=`dirname "${clang_bin}"`
6451+
clang_bin=`readlink "${clang_bin}"`
6452+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
6453+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
6454+
fi
6455+
fi
6456+
64356457
# Enable LTO flags
64366458
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
64376459
$as_echo_n "checking for --with-lto... " >&6; }
@@ -6457,65 +6479,8 @@ fi
64576479
if test "$Py_LTO" = 'true' ; then
64586480
case $CC in
64596481
*clang*)
6460-
case $ac_sys_system in
6461-
Darwin*)
6462-
# Any changes made here should be reflected in the GCC+Darwin case below
6463-
LTOFLAGS="-flto -Wl,-export_dynamic"
6464-
;;
6465-
*)
6466-
LTOFLAGS="-flto"
6467-
;;
6468-
esac
6469-
;;
6470-
*gcc*)
6471-
case $ac_sys_system in
6472-
Darwin*)
6473-
LTOFLAGS="-flto -Wl,-export_dynamic"
6474-
;;
6475-
*)
6476-
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6477-
;;
6478-
esac
6479-
;;
6480-
esac
64816482

6482-
if test "$ac_cv_prog_cc_g" = "yes"
6483-
then
6484-
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6485-
# to get debug symbols.
6486-
LTOFLAGS="$LTOFLAGS -g"
6487-
fi
6488-
6489-
CFLAGS="$CFLAGS $LTOFLAGS"
6490-
LDFLAGS="$LDFLAGS $LTOFLAGS"
6491-
fi
6492-
6493-
# Enable PGO flags.
6494-
6495-
6496-
6497-
6498-
6499-
# Make this work on systems where llvm tools are not installed with their
6500-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
6501-
# non-suffixed name in their versioned llvm directory.
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-
6518-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
6483+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
65196484
$as_echo_n "checking target system type... " >&6; }
65206485
if ${ac_cv_target+:} false; then :
65216486
$as_echo_n "(cached) " >&6
@@ -6554,6 +6519,163 @@ test -n "$target_alias" &&
65546519
test "$program_prefix$program_suffix$program_transform_name" = \
65556520
NONENONEs,x,x, &&
65566521
program_prefix=${target_alias}-
6522+
# Extract the first word of "$target_alias-llvm-ar", so it can be a program name with args.
6523+
set dummy $target_alias-llvm-ar; ac_word=$2
6524+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6525+
$as_echo_n "checking for $ac_word... " >&6; }
6526+
if ${ac_cv_path_LLVM_AR+:} false; then :
6527+
$as_echo_n "(cached) " >&6
6528+
else
6529+
case $LLVM_AR in
6530+
[\\/]* | ?:[\\/]*)
6531+
ac_cv_path_LLVM_AR="$LLVM_AR" # Let the user override the test with a path.
6532+
;;
6533+
*)
6534+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6535+
for as_dir in ${llvm_path}
6536+
do
6537+
IFS=$as_save_IFS
6538+
test -z "$as_dir" && as_dir=.
6539+
for ac_exec_ext in '' $ac_executable_extensions; do
6540+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6541+
ac_cv_path_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6542+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6543+
break 2
6544+
fi
6545+
done
6546+
done
6547+
IFS=$as_save_IFS
6548+
6549+
;;
6550+
esac
6551+
fi
6552+
LLVM_AR=$ac_cv_path_LLVM_AR
6553+
if test -n "$LLVM_AR"; then
6554+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_AR" >&5
6555+
$as_echo "$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+
6562+
if test -z "$ac_cv_path_LLVM_AR"; then
6563+
if test "$build" = "$target"; then
6564+
ac_pt_LLVM_AR=$LLVM_AR
6565+
# Extract the first word of "llvm-ar", so it can be a program name with args.
6566+
set dummy llvm-ar; ac_word=$2
6567+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
6568+
$as_echo_n "checking for $ac_word... " >&6; }
6569+
if ${ac_cv_path_ac_pt_LLVM_AR+:} false; then :
6570+
$as_echo_n "(cached) " >&6
6571+
else
6572+
case $ac_pt_LLVM_AR in
6573+
[\\/]* | ?:[\\/]*)
6574+
ac_cv_path_ac_pt_LLVM_AR="$ac_pt_LLVM_AR" # Let the user override the test with a path.
6575+
;;
6576+
*)
6577+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6578+
for as_dir in ${llvm_path}
6579+
do
6580+
IFS=$as_save_IFS
6581+
test -z "$as_dir" && as_dir=.
6582+
for ac_exec_ext in '' $ac_executable_extensions; do
6583+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
6584+
ac_cv_path_ac_pt_LLVM_AR="$as_dir/$ac_word$ac_exec_ext"
6585+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
6586+
break 2
6587+
fi
6588+
done
6589+
done
6590+
IFS=$as_save_IFS
6591+
6592+
test -z "$ac_cv_path_ac_pt_LLVM_AR" && ac_cv_path_ac_pt_LLVM_AR="''"
6593+
;;
6594+
esac
6595+
fi
6596+
ac_pt_LLVM_AR=$ac_cv_path_ac_pt_LLVM_AR
6597+
if test -n "$ac_pt_LLVM_AR"; then
6598+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_LLVM_AR" >&5
6599+
$as_echo "$ac_pt_LLVM_AR" >&6; }
6600+
else
6601+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6602+
$as_echo "no" >&6; }
6603+
fi
6604+
6605+
LLVM_AR=$ac_pt_LLVM_AR
6606+
else
6607+
LLVM_AR="''"
6608+
fi
6609+
else
6610+
LLVM_AR="$ac_cv_path_LLVM_AR"
6611+
fi
6612+
6613+
6614+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
6615+
then
6616+
LLVM_AR_FOUND="found"
6617+
else
6618+
LLVM_AR_FOUND="not-found"
6619+
fi
6620+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
6621+
then
6622+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
6623+
if test -n "${found_llvm_ar}"
6624+
then
6625+
LLVM_AR='/usr/bin/xcrun llvm-ar'
6626+
LLVM_AR_FOUND=found
6627+
{ $as_echo "$as_me:${as_lineno-$LINENO}: llvm-ar found via xcrun: ${LLVM_AR}" >&5
6628+
$as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
6629+
fi
6630+
fi
6631+
if test $LLVM_AR_FOUND = not-found
6632+
then
6633+
LLVM_PROFR_ERR=yes
6634+
as_fn_error $? "llvm-ar is required for a --with-lto build with clang but could not be found." "$LINENO" 5
6635+
else
6636+
LLVM_AR_ERR=no
6637+
fi
6638+
AR="${LLVM_AR}"
6639+
case $ac_sys_system in
6640+
Darwin*)
6641+
# Any changes made here should be reflected in the GCC+Darwin case below
6642+
LTOFLAGS="-flto -Wl,-export_dynamic"
6643+
;;
6644+
*)
6645+
LTOFLAGS="-flto"
6646+
;;
6647+
esac
6648+
;;
6649+
*gcc*)
6650+
case $ac_sys_system in
6651+
Darwin*)
6652+
LTOFLAGS="-flto -Wl,-export_dynamic"
6653+
;;
6654+
*)
6655+
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6656+
;;
6657+
esac
6658+
;;
6659+
esac
6660+
6661+
if test "$ac_cv_prog_cc_g" = "yes"
6662+
then
6663+
# bpo-30345: Add -g to LDFLAGS when compiling with LTO
6664+
# to get debug symbols.
6665+
LTOFLAGS="$LTOFLAGS -g"
6666+
fi
6667+
6668+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
6669+
LDFLAGS="$LDFLAGS $LTOFLAGS"
6670+
fi
6671+
6672+
# Enable PGO flags.
6673+
6674+
6675+
6676+
6677+
6678+
65576679
# Extract the first word of "$target_alias-llvm-profdata", so it can be a program name with args.
65586680
set dummy $target_alias-llvm-profdata; ac_word=$2
65596681
{ $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
@@ -1302,6 +1302,26 @@ else
13021302
DEF_MAKE_RULE="all"
13031303
fi
13041304

1305+
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
1306+
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1307+
# non-suffixed name in their versioned llvm directory.
1308+
1309+
llvm_bin_dir=''
1310+
llvm_path="${PATH}"
1311+
if test "${CC}" = "clang"
1312+
then
1313+
clang_bin=`which clang`
1314+
# Some systems install clang elsewhere as a symlink to the real path
1315+
# which is where the related llvm tools are located.
1316+
if test -L "${clang_bin}"
1317+
then
1318+
clang_dir=`dirname "${clang_bin}"`
1319+
clang_bin=`readlink "${clang_bin}"`
1320+
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1321+
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1322+
fi
1323+
fi
1324+
13051325
# Enable LTO flags
13061326
AC_MSG_CHECKING(for --with-lto)
13071327
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in any build. Disabled by default.]),
@@ -1318,6 +1338,33 @@ fi],
13181338
if test "$Py_LTO" = 'true' ; then
13191339
case $CC in
13201340
*clang*)
1341+
AC_SUBST(LLVM_AR)
1342+
AC_PATH_TARGET_TOOL(LLVM_AR, llvm-ar, '', ${llvm_path})
1343+
AC_SUBST(LLVM_AR_FOUND)
1344+
if test -n "${LLVM_AR}" -a -x "${LLVM_AR}"
1345+
then
1346+
LLVM_AR_FOUND="found"
1347+
else
1348+
LLVM_AR_FOUND="not-found"
1349+
fi
1350+
if test "$ac_sys_system" = "Darwin" -a "${LLVM_AR_FOUND}" = "not-found"
1351+
then
1352+
found_llvm_ar=`/usr/bin/xcrun -find llvm-ar 2>/dev/null`
1353+
if test -n "${found_llvm_ar}"
1354+
then
1355+
LLVM_AR='/usr/bin/xcrun llvm-ar'
1356+
LLVM_AR_FOUND=found
1357+
AC_MSG_NOTICE([llvm-ar found via xcrun: ${LLVM_AR}])
1358+
fi
1359+
fi
1360+
if test $LLVM_AR_FOUND = not-found
1361+
then
1362+
LLVM_PROFR_ERR=yes
1363+
AC_MSG_ERROR([llvm-ar is required for a --with-lto build with clang but could not be found.])
1364+
else
1365+
LLVM_AR_ERR=no
1366+
fi
1367+
AR="${LLVM_AR}"
13211368
case $ac_sys_system in
13221369
Darwin*)
13231370
# Any changes made here should be reflected in the GCC+Darwin case below
@@ -1347,7 +1394,7 @@ if test "$Py_LTO" = 'true' ; then
13471394
LTOFLAGS="$LTOFLAGS -g"
13481395
fi
13491396

1350-
CFLAGS="$CFLAGS $LTOFLAGS"
1397+
BASECFLAGS="$BASECFLAGS $LTOFLAGS"
13511398
LDFLAGS="$LDFLAGS $LTOFLAGS"
13521399
fi
13531400

@@ -1357,24 +1404,6 @@ AC_SUBST(PGO_PROF_USE_FLAG)
13571404
AC_SUBST(LLVM_PROF_MERGER)
13581405
AC_SUBST(LLVM_PROF_FILE)
13591406
AC_SUBST(LLVM_PROF_ERR)
1360-
# Make this work on systems where llvm tools are not installed with their
1361-
# normal names in the default $PATH (ie: Ubuntu). They exist under the
1362-
# non-suffixed name in their versioned llvm directory.
1363-
llvm_bin_dir=''
1364-
llvm_path="${PATH}"
1365-
if test "${CC}" = "clang"
1366-
then
1367-
clang_bin=`which clang`
1368-
# Some systems install clang elsewhere as a symlink to the real path
1369-
# which is where the related llvm tools are located.
1370-
if test -L "${clang_bin}"
1371-
then
1372-
clang_dir=`dirname "${clang_bin}"`
1373-
clang_bin=`readlink "${clang_bin}"`
1374-
llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
1375-
llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
1376-
fi
1377-
fi
13781407
AC_SUBST(LLVM_PROFDATA)
13791408
AC_PATH_TARGET_TOOL(LLVM_PROFDATA, llvm-profdata, '', ${llvm_path})
13801409
AC_SUBST(LLVM_PROF_FOUND)

0 commit comments

Comments
 (0)