Repository navigation
Link-time-optimization with clang is broken #96761
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 12, 2022 matthiasgoergens commented
on Sep 12, 2022 ContributorAuthorMore actions@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 @tiranOkay, I am able to reproduce the issue even with the lld.
Reacted by Matthias Görgensmatthiasgoergens commented
on Sep 17, 2022 ContributorAuthorMore actionsThanks for confirming that it's not just some idiosyncratic weirdness of my environment.
- added3.11only security fixesonly security fixes3.12only security fixesonly security fixes
on Sep 18, 2022 For @matthiasgoergens, @tiran @vstinner cc @pablogsal as release manager.
My conclusion
- At this moment
Modules/*.oare actually LLVM bitcode not object files. - so the LTO processor needs to transform the LLVM bitcode into the object file for the traditional linker but looks like without
-fltoit doesn't transform to object files for the traditional linker. - This issue not only happens for ThinLTO but also in full LTO because both processes have the phase for transforming the LLVM bitcode into the object file.
- see http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html
- IMHO we can add the transformation phase for
-fno-ltobut it could be complicated, I prefer using gh-96761: Fix lto-build for clang #96762 as a workaround approach and we need to backport to Python 3.11 too. - But I am still curious about the fact why apple clang does not raise this issue.
Reference
file format
corona10@python-dev:~/cpython$ file Modules/getbuildinfo.o Modules/getbuildinfo.o: LLVM IR bitcodeclang full LTO process
clang ThinLTO process
Reacted by Matthias Görgens and Claudia PellegrinoReacted by Matthias Görgens and Rin Arakaki- At this moment
Why is this only affecting 3.11 and not previous version?
Why is this only affecting 3.11 and not previous version?
because #29859 was first introduced in Python 3.11 for
_bootstrap_python.When building the final binary for CPython, we actually pass the
-fltoflags 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 strippedThanks 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.
Reacted by Donghee Namatthiasgoergens commented
on Sep 18, 2022 ContributorAuthorMore actionsAs far as I can tell, building
_bootstrap_pythonwith 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: #96762 (comment)
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-dialectmatthiasgoergens commented
on Sep 19, 2022 ContributorAuthorMore actions@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.