Skip to content

Commit 4adde68

Browse files
committed
Disable unsafe identical code folding in BOLT
astral-sh/uv#13610 reported a misbehavior that is the result of a subclass of str incorrectly having its ->tp_as_number->nb_add slot filled in with the value of PyUnicode_Type->tp_as_sequence->sq_concat. There are some times when this is an appropriate thing to do iwhen subclassing, but this is not one of them. The logic to prevent it in this case relies on two helper functions in the file, wrap_binaryfunc and wrap_binaryfunc_l, having different addresses, even though they contain identical code. For some reason BOLT does not do this optimization in the shared library (even though those are static functions and not exported), so we only started seeing this in the static build.
1 parent 482a9bc commit 4adde68

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
271271
# https://github.com/python/cpython/issues/128514
272272
patch -p1 -i ${ROOT}/patch-configure-bolt-apply-flags-128514.patch
273273

274+
# Disable unsafe identical code folding. Objects/typeobject.c
275+
# update_one_slot requires that wrap_binaryfunc != wrap_binaryfunc_l,
276+
# despite the functions being identical.
277+
patch -p1 -i ${ROOT}/patch-configure-bolt-icf-safe.patch
278+
274279
# Tweak --skip-funcs to work with our toolchain.
275280
patch -p1 -i ${ROOT}/patch-configure-bolt-skip-funcs.patch
276281
fi
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index 902f425cf87..8001d0deb07 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -2261,7 +2261,7 @@ then
6+
-reorder-functions=cdsort
7+
-split-functions
8+
-split-strategy=cdsplit
9+
- -icf=1
10+
+ -icf=safe
11+
-inline-all
12+
-split-eh
13+
-reorder-functions-use-hot-size

0 commit comments

Comments
 (0)