Skip to content

Commit 1ff83ad

Browse files
zaniebpablogsal
andauthored
gh-128883: Store ELF perf trampoline templates in read-only data (#160366)
CPython copies the trampoline templates into executable memory. Keep the ELF source in .rodata so BOLT preserves its bytes and boundaries. Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent b341b81 commit 1ff83ad

5 files changed

Lines changed: 14 additions & 6 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
for define_eval_hook in (False, True):
239234
code = """if 1:
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_aarch64.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
#define GNU_PROPERTY_AARCH64_GCS 0
3636
#endif
3737

38+
/* CPython copies this template into executable memory. */
39+
#if defined(__ELF__)
40+
.section .rodata
41+
#else
3842
.text
43+
#endif
3944
#if defined(__aarch64__) && defined(__AARCH64EL__) && !defined(__ILP32__)
4045
#if defined(__APPLE__)
4146
.globl __Py_trampoline_func_start

‎Python/asm_trampoline_riscv64.S‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.text
1+
/* CPython copies this template into executable memory. */
2+
.section .rodata
23
.globl _Py_trampoline_func_start
34
_Py_trampoline_func_start:
45
addi sp,sp,-16

‎Python/asm_trampoline_x86_64.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
/* CPython copies this template into executable memory. */
2+
#if defined(__ELF__)
3+
.section .rodata
4+
#else
15
.text
6+
#endif
27
#ifdef __x86_64__
38
#if defined(__APPLE__)
49
.globl __Py_trampoline_func_start

0 commit comments

Comments
 (0)