Closed matthiasgoergens closed 2 years ago
-no-lto flag was first introduced at https://github.com/python/cpython/pull/29859 by @tiran Would you like to take a look at this issue please?
@corona10 Thanks! That seems to be mostly about speeding up the GCC build. LLVM is already pretty fast with thin-lto.
I will try to reproduce the issue in my Linux environment with clang14 before reviewing the PR. cc @tiran
Okay, I am able to reproduce the issue even with the lld.
Thanks for confirming that it's not just some idiosyncratic weirdness of my environment.
For @matthiasgoergens, @tiran @vstinner cc @pablogsal as release manager.
Modules/*.o
are actually LLVM bitcode not object files. -flto
it doesn't transform to object files for the traditional linker.-fno-lto
but it could be complicated, I prefer using https://github.com/python/cpython/pull/96762 as a workaround approach and we need to backport to Python 3.11 too.corona10@python-dev:~/cpython$ file Modules/getbuildinfo.o
Modules/getbuildinfo.o: LLVM IR bitcode
Why is this only affecting 3.11 and not previous version?
Why is this only affecting 3.11 and not previous version?
because https://github.com/python/cpython/pull/29859 was first introduced in Python 3.11 for _bootstrap_python
.
When building the final binary for CPython, we actually pass the -flto
flags that the process will transform the LLVM bitcode into object files, so this issue only affects while building the _bootstrap_python
.
I didn't check if the issue will affect to old versions (< 3.10)
Manual transformation example:
corona10@python-dev:~/cpython$ llc-14 -filetype=obj Modules/getbuildinfo.o -o Modules/getbuildinfo.o
corona10@python-dev:~/cpython$ file Modules/getbuildinfo.o
Modules/getbuildinfo.o: ELF 64-bit LSB relocatable, x86-64, version 1 (GNU/Linux), with debug_info, not stripped
Thanks for the quick answer and great analysis @corona10. I think the fix for this should go to 3.11.1 as this likely involve configure changes unless someone fundamentally disagrees.
As far as I can tell, building _bootstrap_python
with different flags than the full Python binary was only a hack to speed up the build, wasn't it?
Thin LTO is pretty fast, and compatible with the other LTO settings (apart perhaps from no-LTO), so we can build the bootstrap with that one, if any LTO is requested for the main build?
Thin LTO is pretty fast, and compatible with the other LTO settings (apart perhaps from no-LTO), so we can build the bootstrap with that one, if any LTO is requested for the main build?
Please follow my last review: https://github.com/python/cpython/pull/96762#discussion_r973207014 Since we should support all C11 compilers including old clangs which doesn't support ThinLTO, the configuration should use ThinLTO only if the compiler supports it. We should not break the build for old compilers too. see: https://clang.llvm.org/c_status.html and https://peps.python.org/pep-0007/#c-dialect
@corona10 Yes, definitely. I need to add checks.
All patches are merged. Feel free to reopen if we need other solutions. cc @tiran @pablogsal
I tried to enable link time optimizations for clang.
Eventually building reaches this step:
And fails:
Your environment
I'm on Archlinux x86-64.
I tested against main.