8000 gh-101525: Skip test_gdb if the binary is relocated by BOLT. by corona10 · Pull Request #118572 · python/cpython · GitHub
[go: up one dir, main page]

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-101525: Skip test_gdb if the binary is BOLTed.
  • Loading branch information
corona10 committed Aug 31, 2024
commit 8755316d185be2d8625474f61c63efd7987f6f92
4 changes: 4 additions & 0 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ def get_build_info():
if support.check_cflags_pgo():
# PGO (--enable-optimizations)
optimizations.append('PGO')

if support.check_bolt_optimized():
optimizations.append('BOLT')

if optimizations:
build.append('+'.join(optimizations))

Expand Down
11 changes: 11 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,17 @@ def check_cflags_pgo():
return any(option in cflags_nodist for option in pgo_options)


def check_bolt_optimized():
# BOLTed binary can be checked based on ELF information.
# link: https://github.com/llvm/llvm-project/issues/60253
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?

return True
return False


Py_GIL_DISABLED = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))

def requires_gil_enabled(msg="needs the GIL enabled"):
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_gdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
if support.check_cflags_pgo():
raise unittest.SkipTest("test_gdb is not reliable on PGO builds")

if support.check_bolt_optimized():
raise unittest.SkipTest("test_gdb is not reliable on BOLT optimized builds")


def load_tests(*args):
return support.load_package_tests(os.path.dirname(__file__), *args)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip test_gdb if the binary is BOLTed. Patch by Donghee Na.
0