Skip to content

Commit 1fa5e07

Browse files
pablogsalzanieb
andauthored
[3.14] gh-128883: Store ELF perf trampoline templates in read-only data (GH-160366) (#160492)
CPython copies the trampoline templates into executable memory. Keep the ELF source in .rodata so BOLT preserves its bytes and boundaries. (cherry picked from commit 1ff83ad) Co-authored-by: Zanie Blue <contact@zanie.dev>
1 parent 4bea462 commit 1fa5e07

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎Lib/test/test_perf_profiler.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def tearDown(self) -> None:
6262
for file in files_to_delete:
6363
file.unlink()
6464

65-
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
6665
def test_trampoline_works(self):
6766
code = """if 1:
6867
def foo():
@@ -113,7 +112,6 @@ def baz():
113112
"Address should contain only hex characters",
114113
)
115114

116-
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
117115
def test_trampoline_with_unencodable_name(self):
118116
code = """if 1:
119117
import sys
@@ -123,7 +121,6 @@ def test_trampoline_with_unencodable_name(self):
123121
"""
124122
assert_python_ok("-c", code, PYTHON_JIT="0")
125123

126-
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
127124
def test_trampoline_works_with_forks(self):
128125
code = """if 1:
129126
import os, sys
@@ -193,7 +190,6 @@ def baz():
193190
self.assertNotIn(f"py::bar:{script}", child_perf_file_contents)
194191
self.assertNotIn(f"py::baz:{script}", child_perf_file_contents)
195192

196-
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
197193
def test_trampoline_works_after_fork_with_many_code_objects(self):
198194
code = """if 1:
199195
import gc, os, sys, signal
@@ -233,7 +229,6 @@ def test_trampoline_works_after_fork_with_many_code_objects(self):
233229
self.assertEqual(process.returncode, 0, stderr)
234230
self.assertEqual(stderr, "")
235231

236-
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
237232
def test_sys_api(self):
238233
code = """if 1:
239234
import sys
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crashes with ``-X perf`` and ``-X perf_jit`` in BOLT builds.
2+
The ELF perf trampoline templates now use read-only data sections.

‎Python/asm_trampoline.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "asm_trampoline_aarch64.h"
22

3+
/* CPython copies this template into executable memory. */
4+
#if defined(__ELF__)
5+
.section .rodata
6+
#else
37
.text
8+
#endif
49
.globl _Py_trampoline_func_start
510
# The following assembly is equivalent to:
611
# PyObject *

0 commit comments

Comments
 (0)