Skip to content

gh-117174: Skip test_gdb if Python is built with LTO #131143

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,11 @@ def get_build_info():

# --with-lto
optimizations = []
if '-flto=thin' in ldflags_nodist:
optimizations.append('ThinLTO')
elif '-flto' in ldflags_nodist:
optimizations.append('LTO')
if support.check_ldflags_lto():
if '-flto=thin' in ldflags_nodist:
optimizations.append('ThinLTO')
else:
optimizations.append('LTO')

if support.check_cflags_pgo():
# PGO (--enable-optimizations)
Expand Down
17 changes: 14 additions & 3 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ def python_is_optimized():
def check_cflags_pgo():
# Check if Python was built with ./configure --enable-optimizations:
# with Profile Guided Optimization (PGO).
cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST') or ''
cflags_nodist = (sysconfig.get_config_var('PY_CFLAGS_NODIST') or '')
pgo_options = [
# GCC
'-fprofile-use',
Expand All @@ -867,13 +867,24 @@ def check_cflags_pgo():
return any(option in cflags_nodist for option in pgo_options)


def check_ldflags_lto():
# Check if Python was built with ./configure --with-lto:
# with Link Time Optimization (PGO).
ldflags_nodist = (sysconfig.get_config_var('PY_LDFLAGS_NODIST') or '')
lto_options = {
'-flto',
'-flto=thin',
}
return any(option in ldflags_nodist for option in lto_options)


def check_bolt_optimized():
# Always return false, if the platform is WASI,
# because BOLT optimization does not support WASM binary.
if is_wasi:
return False
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
return '--enable-bolt' in config_args
config_args = (sysconfig.get_config_var('CONFIG_ARGS') or '')
return ('--enable-bolt' in config_args)


Py_GIL_DISABLED = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
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_ldflags_lto():
raise unittest.SkipTest("test_gdb is not reliable on LTO builds")

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

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ def test_get_signal_name(self):
self.assertEqual(support.get_signal_name(exitcode), expected,
exitcode)

def test_compiler_flags(self):
self.assertIsInstance(support.check_cflags_pgo(), bool)
self.assertIsInstance(support.check_ldflags_lto(), bool)
self.assertIsInstance(support.check_bolt_optimized(), bool)

# XXX -follows a list of untested API
# make_legacy_pyc
# is_resource_enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Skip test_gdb if Python is built with Link Time Optimization (LTO). Patch by
Victor Stinner.
Loading