Skip to content

gh-96761: Fix lto-build for clang #96762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

matthiasgoergens
Copy link
Contributor

@matthiasgoergens matthiasgoergens commented Sep 12, 2022

When enabling link time optimization for clang, you eventually get the following error:

Modules/getbuildinfo.o: file not recognized: file format not recognized

This patch fixes that problem.

When enabling link time optimization for clang, you eventually get the
following error:

`Modules/getbuildinfo.o: file not recognized: file format not recognized`

This patch fixes that problem.
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

Please re-generate configure file by using the following command.

docker run --rm --pull=always -v$(pwd):/src quay.io/tiran/cpython_autoconf:269

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@corona10 corona10 requested a review from tiran September 12, 2022 08:17
configure.ac Outdated
@@ -1829,7 +1829,7 @@ if test "$Py_LTO" = 'true' ; then
case $CC in
*clang*)
dnl flag to disable lto during linking
LDFLAGS_NOLTO="-fno-lto"
LDFLAGS_NOLTO="-flto=${Py_LTO_POLICY}"
Copy link
Member

Choose a reason for hiding this comment

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

LDFLAGS_NOLTO should be linker flags without LTO, hence the name no lto.

Copy link
Contributor Author

@matthiasgoergens matthiasgoergens Sep 12, 2022

Choose a reason for hiding this comment

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

I guess I'll need to make a bigger change, that changes the name to something more descriptive.

# LDFLAGS_NOLTO is an extra flag to disable lto. It is used to speed up building
# of _bootstrap_python and _freeze_module tools, which don't need LTO.

For clang that seems to work better when they are the same as for the rest of the build. The thin-lto build is already plenty fast (and even then, a slow build is better than a broken one).

Copy link
Member

Choose a reason for hiding this comment

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

clang does not support linking with objects that have LTO information? It works fine for GCC. Could you please update the comment on line 1831?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not quite sure what the exact rootcause is. I just noticed that when I tried to build some things with LTO and some things (like _bootstrap_python) without LTO, I get an error from the linker via clang.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the comment.

Copy link
Member

Choose a reason for hiding this comment

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

Does thin LTO linking work with object files that are built with full LTO? This would speed up LTO builds a bit.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC, at this moment -flto=${Py_LTO_POLICY} could be -flto=default so it's wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, let me think about how to fix this. Or do you have a suggestion?

@matthiasgoergens
Copy link
Contributor Author

Please re-generate configure file by using the following command.

docker run --rm --pull=always -v$(pwd):/src quay.io/tiran/cpython_autoconf:269

Done!

@matthiasgoergens
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@corona10: please review the changes made to this pull request.

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Co-authored-by: Christian Heimes <[email protected]>
@matthiasgoergens
Copy link
Contributor Author

@corona10 Just to be sure: does your PR at #96766 obsolete this one?

If yes, I'll close mine.

@corona10
Copy link
Member

corona10 commented Sep 14, 2022

@matthiasgoergens cc @tiran
There are several consensuses on this issue.

A. Using ThinLTO as the default LTO policy for clang is not decided yet, #96766 will cover the issue.
B. If #96766 is merged we can use ThinLTO on clang for bootstrap_python if needed.
C. But A and B do not mean that bootstrap_python should be built with clang by using LTO. (If needed we should use it, but if it is not a root cause we don't need to use it) since I can not meet the same issue on macOS with clang so I need to reproduce the issue on Linux first. I need to know the root cause.

@corona10
Copy link
Member

@corona10 Just to be sure: does your PR at #96766 obsolete this one?

So in conclusion, it's a slightly different issue.

@dwvshell
Copy link

How do I put this to work

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

@matthiasgoergens

  • Please rebase the PR and regen configure with the suggested changes.
  • Please update the following comment also (for clang case).

    cpython/Makefile.pre.in

    Lines 94 to 95 in 1fc8bd3

    # LDFLAGS_NOLTO is an extra flag to disable lto. It is used to speed up building
    # of _bootstrap_python and _freeze_module tools, which don't need LTO.

Co-authored-by: Dong-hee Na <[email protected]>
@corona10 corona10 added the needs backport to 3.11 only security fixes label Sep 18, 2022
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

Would you like to regenerate the configure by using docker run --rm --pull=always -v$(pwd):/src quay.io/tiran/cpython_autoconf:269?

@matthiasgoergens
Copy link
Contributor Author

Closed in favour of #96945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants