Skip to content

gh-101525: Skip test_gdb if the binary is relocated by BOLT. #118572

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

Merged
merged 10 commits into from
Sep 2, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented May 4, 2024

@corona10
Copy link
Member Author

corona10 commented May 4, 2024

Now the all tests are fully passed with BOLTed binary.

binary_path = sys.executable
with open(binary_path, 'rb') as f:
binary = f.read()
if b'.note.bolt_info' in binary:
Copy link

Choose a reason for hiding this comment

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

Can you call readelf -e <binary_path> and grep .note.bolt_info? Checking headers is efficient and robust.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also think it will be the best way to handle this issue. But I am not sure it will be okay to call external binary for this. I may need to get opinions from @vstinner and @erlend-aasland WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Why not checking sysconfig? This check looks slow and not reliable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not checking sysconfig? This check looks slow and not reliable.

Do you have any recommendation points? CFLAG does not guarantee the build is BOLTed.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe test:

'--enable-bolt' in sysconfig.get_config_var('CONFIG_ARGS')

Copy link
Member

Choose a reason for hiding this comment

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

Only put the code in test_gdb if you're worried that the the test is not reliable. And add a comment to explain it.

Copy link
Member Author

@corona10 corona10 May 5, 2024

Choose a reason for hiding this comment

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

Well then there is no way to display the optimization information but okay got it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot expect "readelf" to be available, it would be a new dependency. I dislike looking for a string in a binary without parsing the ELF binary.

We call external binaries in test.support to determine macOS features, so there is precedent for doing that sort of thing; is readelf a standalone package, or is it part of the compiler toolchain?

Copy link
Member Author

@corona10 corona10 May 6, 2024

Choose a reason for hiding this comment

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

; is readelf a standalone package, or is it part of the compiler toolchain?

AFAIK, it's part of binutils: https://sourceware.org/binutils/docs/binutils/readelf.html

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, it's part of binutils: https://sourceware.org/binutils/docs/binutils/readelf.html

Thanks. binutils is preinstalled on the Ubuntu runners GitHub provides, so there is no more dependencies for the CI there. Also, anyone who wants to build their own CPython probably already did apt install build-essential, which includes binutils. Looks to me like there are no more deps introduced. What about macOS?

@corona10 corona10 requested a review from vstinner May 6, 2024 13:33
@corona10 corona10 changed the title gh-101525: Skip test_gdb if the binary is BOLTed. [WIP] gh-101525: Skip test_gdb if the binary is BOLTed. May 6, 2024
@corona10 corona10 changed the title [WIP] gh-101525: Skip test_gdb if the binary is BOLTed. gh-101525: Skip test_gdb if the binary is BOLTed. May 6, 2024
@aaupov
Copy link

aaupov commented May 6, 2024

By the way, since -update-debug-sections is used (https://github.com/python/cpython/blob/main/configure.ac#L2185), do you really need to skip gdb tests?

@corona10
Copy link
Member Author

corona10 commented May 6, 2024

By the way, since -update-debug-sections is used (https://github.com/python/cpython/blob/main/configure.ac#L2185), do you really need to skip gdb tests?

Well, when I run a test_gdb with BOLTed binary, sometimes it fails, well let me try with other systems too.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner
Copy link
Member

vstinner commented May 7, 2024

I suggest to backport the change to 3.12, and maybe also to 3.11.

@@ -856,6 +856,14 @@ def check_cflags_pgo():
return any(option in cflags_nodist for option in pgo_options)


def check_bolt_optimized():
# Always return false, if the platform is WASI.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment only says what the code does, but not why. Could you rewrite it to state why this is happening? I can easily see by the code that we always return false if we're on WASI; there is no need to manifest that info into a comment ;)

@corona10
Copy link
Member Author

corona10 commented May 8, 2024

I suggest to backport the change to 3.12, and maybe also to 3.11.

@vstinner @erlend-aasland
BOLT is the experimental feature from 3.12 :)
Anyway, I will finalize this PR during the PyCon US. This week, I am too busy with all my tasks at my full-time job before the conference.

@corona10
Copy link
Member Author

corona10 commented Aug 31, 2024

@vstinner @erlend-aasland I've updated the staled PR, Can you please take a look again?

@corona10 corona10 added the needs backport to 3.12 only security fixes label Aug 31, 2024
@corona10 corona10 added the needs backport to 3.13 bugs and security fixes label Aug 31, 2024
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@corona10 corona10 enabled auto-merge (squash) September 2, 2024 13:01
@corona10 corona10 changed the title gh-101525: Skip test_gdb if the binary is BOLTed. gh-101525: Skip test_gdb if the binary is relocated by BOLT. Sep 2, 2024
@corona10 corona10 disabled auto-merge September 2, 2024 13:02
@corona10 corona10 enabled auto-merge (squash) September 2, 2024 13:02
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@corona10 corona10 merged commit f95fc4d into python:main Sep 2, 2024
42 checks passed
@miss-islington-app
Copy link

Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 2, 2024
…ythongh-118572)

(cherry picked from commit f95fc4d)

Co-authored-by: Donghee Na <donghee.na@python.org>
@miss-islington-app
Copy link

Sorry, @corona10, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker f95fc4de115ae03d7aa6dece678240df085cb4f6 3.12

@bedevere-app
Copy link

bedevere-app bot commented Sep 2, 2024

GH-123601 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Sep 2, 2024
corona10 added a commit that referenced this pull request Sep 2, 2024
…h-118572) (#123601)

gh-101525: Skip test_gdb if the binary is relocated by BOLT. (gh-118572)
(cherry picked from commit f95fc4d)

Co-authored-by: Donghee Na <donghee.na@python.org>
corona10 added a commit to corona10/cpython that referenced this pull request Sep 2, 2024
…OLT. (pythongh-118572)

(cherry picked from commit f95fc4d)

Co-authored-by: Donghee Na <donghee.na@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Sep 2, 2024

GH-123603 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Sep 2, 2024
corona10 added a commit that referenced this pull request Sep 2, 2024
#123603)

[3.12] gh-101525: Skip test_gdb if the binary is relocated by BOLT. (gh-118572)
(cherry picked from commit f95fc4d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants