Skip to content

Commit 3222e53

Browse files
committed
gh-117174: Skip test_gdb if Python is built with LTO
Add support.check_ldflags_lto().
1 parent 4dcbe06 commit 3222e53

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

Lib/test/libregrtest/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ def get_build_info():
386386

387387
# --with-lto
388388
optimizations = []
389-
if '-flto=thin' in ldflags_nodist:
390-
optimizations.append('ThinLTO')
391-
elif '-flto' in ldflags_nodist:
392-
optimizations.append('LTO')
389+
if support.check_ldflags_lto():
390+
if '-flto=thin' in ldflags_nodist:
391+
optimizations.append('ThinLTO')
392+
else:
393+
optimizations.append('LTO')
393394

394395
if support.check_cflags_pgo():
395396
# PGO (--enable-optimizations)

Lib/test/support/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def python_is_optimized():
852852
def check_cflags_pgo():
853853
# Check if Python was built with ./configure --enable-optimizations:
854854
# with Profile Guided Optimization (PGO).
855-
cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST') or ''
855+
cflags_nodist = (sysconfig.get_config_var('PY_CFLAGS_NODIST') or '')
856856
pgo_options = [
857857
# GCC
858858
'-fprofile-use',
@@ -867,13 +867,24 @@ def check_cflags_pgo():
867867
return any(option in cflags_nodist for option in pgo_options)
868868

869869

870+
def check_ldflags_lto():
871+
# Check if Python was built with ./configure --with-lto:
872+
# with Link Time Optimization (PGO).
873+
ldflags_nodist = (sysconfig.get_config_var('PY_LDFLAGS_NODIST') or '')
874+
lto_options = {
875+
'-flto',
876+
'-flto=thin',
877+
}
878+
return any(option in ldflags_nodist for option in lto_options)
879+
880+
870881
def check_bolt_optimized():
871882
# Always return false, if the platform is WASI,
872883
# because BOLT optimization does not support WASM binary.
873884
if is_wasi:
874885
return False
875-
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
876-
return '--enable-bolt' in config_args
886+
config_args = (sysconfig.get_config_var('CONFIG_ARGS') or '')
887+
return ('--enable-bolt' in config_args)
877888

878889

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

Lib/test/test_gdb/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
if support.check_cflags_pgo():
2525
raise unittest.SkipTest("test_gdb is not reliable on PGO builds")
2626

27+
if support.check_ldflags_lto():
28+
raise unittest.SkipTest("test_gdb is not reliable on LTO builds")
29+
2730
if support.check_bolt_optimized():
2831
raise unittest.SkipTest("test_gdb is not reliable on BOLT optimized builds")
2932

Lib/test/test_support.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ def test_get_signal_name(self):
744744
self.assertEqual(support.get_signal_name(exitcode), expected,
745745
exitcode)
746746

747+
def test_compiler_flags(self):
748+
self.assertIsInstance(support.check_cflags_pgo(), bool)
749+
self.assertIsInstance(support.check_ldflags_lto(), bool)
750+
self.assertIsInstance(support.check_bolt_optimized(), bool)
751+
747752
# XXX -follows a list of untested API
748753
# make_legacy_pyc
749754
# is_resource_enabled
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Skip test_gdb if Python is built with Link Time Optimization (LTO). Patch by
2+
Victor Stinner.

0 commit comments

Comments
 (0)