Modules/getbuildinfo.o: file not recognized: file format not recognized
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
At this moment Modules/*.o are 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 -flto it 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.
IMHO we can add the transformation phase for -fno-lto but 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 bitcode
clang full LTO process
clang ThinLTO process
Reacted by Matthias Görgens and Claudia Pellegrino
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)
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?
Activity
corona10 commented on Sep 12, 2022
-no-lto flag was first introduced at #29859 by @tiran
Would you like to take a look at this issue please?
matthiasgoergens commented on Sep 12, 2022
@corona10 Thanks! That seems to be mostly about speeding up the GCC build. LLVM is already pretty fast with thin-lto.
corona10 commented on Sep 13, 2022
I will try to reproduce the issue in my Linux environment with clang14 before reviewing the PR.
cc @tiran
corona10 commented on Sep 16, 2022
Okay, I am able to reproduce the issue even with the lld.
matthiasgoergens commented on Sep 17, 2022
Thanks for confirming that it's not just some idiosyncratic weirdness of my environment.
corona10 commented on Sep 18, 2022
For @matthiasgoergens, @tiran @vstinner cc @pablogsal as release manager.
My conclusion
Reference
file format
corona10@python-dev:~/cpython$ file Modules/getbuildinfo.o Modules/getbuildinfo.o: LLVM IR bitcodeclang full LTO process
clang ThinLTO process
pablogsal commented on Sep 18, 2022
Why is this only affecting 3.11 and not previous version?
corona10 commented on Sep 18, 2022
because #29859 was first introduced in Python 3.11 for _bootstrap_python.
corona10 commented on Sep 18, 2022
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)
corona10 commented on Sep 18, 2022
Manual transformation example:
pablogsal commented on Sep 18, 2022
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.
matthiasgoergens commented on Sep 18, 2022
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?
corona10 commented on Sep 19, 2022
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-dialect
matthiasgoergens commented on Sep 19, 2022
@corona10 Yes, definitely. I need to add checks.
pythongh-96761: Fix build process of the clang compiler for _bootstra…
gh-96761: Fix build process of the clang compiler for _bootstrap_pyth…
pythongh-96761: Fix build process of the clang compiler for _bootstra…
gh-96761: Fix build process of the clang compiler for _bootstrap_pyth…
corona10 commented on Sep 23, 2022
All patches are merged.
Feel free to reopen if we need other solutions.
cc @tiran @pablogsal