Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,14 @@ also be used to improve performance.
Enable Link Time Optimization (LTO) in any build (disabled by default).

The C compiler Clang requires ``llvm-ar`` for LTO (``ar`` on macOS), as well
as an LTO-aware linker (``ld.gold`` or ``lld``).
as an LTO-aware linker (``ld.gold`` or ``lld``). GNU linkers require the
``LLVMgold.so`` plugin for Clang LTO; ``lld`` does not. On platforms other
than macOS, configure tries ``-fuse-ld=lld`` if the configured linker cannot
link a Clang LTO program.

.. versionchanged:: 3.16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionchanged:: 3.16
.. versionchanged:: next

Fall back to ``lld`` when the configured linker cannot link Clang LTO
programs.

.. versionadded:: 3.6

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
When building with ``--with-lto`` and Clang, :program:`configure` now checks
that the linker can link LTO objects and falls back to ``lld``
(``-fuse-ld=lld``) if it cannot. This fixes LTO builds on systems where the
default GNU linker lacks the ``LLVMgold.so`` plugin, such as Debian 13.
62 changes: 62 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,30 @@ if test "$Py_LTO" = 'true' ; then
else
LTOFLAGS="-flto=${Py_LTO_POLICY}"
fi
LTOCFLAGS="$LTOFLAGS"
# GNU ld needs LLVMgold.so for Clang LTO. If the configured linker
# cannot link LTO objects, try lld, which does not need that plugin.
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $LDFLAGS_NODIST $LTOFLAGS"
Comment on lines +2226 to +2227

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use the SAVE_ENV macro here

AC_MSG_CHECKING([whether Clang LTO works with the configured linker])
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [clang_lto_link=yes], [clang_lto_link=no])
AC_MSG_RESULT([$clang_lto_link])
if test "$clang_lto_link" = no; then
LDFLAGS="$LDFLAGS -fuse-ld=lld"
AC_MSG_CHECKING([whether Clang LTO works with lld])
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [clang_lto_link=yes], [clang_lto_link=no])
AC_MSG_RESULT([$clang_lto_link])
if test "$clang_lto_link" = no; then
AC_MSG_ERROR([m4_normalize([
Clang LTO requires a working LTO-aware linker.
Install lld or the LLVMgold.so plugin, select a linker
with LDFLAGS, or disable LTO with --without-lto.
])])
fi
LTOFLAGS="$LTOFLAGS -fuse-ld=lld"
LDFLAGS_NOLTO="$LDFLAGS_NOLTO -fuse-ld=lld"
fi
LDFLAGS="$save_LDFLAGS"
;;
esac
;;
Expand Down
Loading