Skip to content

Commit 4a2dcac

Browse files
committed
gh-159437: Align release build functions to 64-byte boundaries
1 parent abd738f commit 4a2dcac

4 files changed

Lines changed: 95 additions & 1 deletion

File tree

‎Makefile.pre.in‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ CONFIGURE_LDFLAGS= @LDFLAGS@
102102
# command line to append to these values without stomping the pre-set
103103
# values.
104104
PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
105-
PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include/internal -I$(srcdir)/Include/internal/mimalloc
105+
# Configure validates function alignment once, but make-time CFLAGS can still
106+
# select a size-optimized build after configure has completed.
107+
PY_ALIGN_FUNCTIONS_CFLAGS=@FUNCTION_ALIGNMENT_CFLAGS@
108+
ifneq ($(filter -Os -Oz,$(PY_CFLAGS) $(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST)),)
109+
PY_ALIGN_FUNCTIONS_CFLAGS=
110+
endif
111+
PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) $(PY_ALIGN_FUNCTIONS_CFLAGS) -I$(srcdir)/Include/internal -I$(srcdir)/Include/internal/mimalloc
106112
# Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
107113
# be able to build extension modules using the directories specified in the
108114
# environment variables
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Request 64-byte function alignment for performance-oriented Linux and macOS builds. This can reduce performance variation caused by changes to the size of preceding functions.

‎configure‎

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,21 @@ then
24302430
esac
24312431
fi
24322432

2433+
# Keep performance-oriented release builds aligned on validated platforms
2434+
# without changing size-optimized, mobile, or third-party extension builds.
2435+
FUNCTION_ALIGNMENT_CFLAGS=
2436+
AS_CASE([$host],
2437+
[*-*-linux-android*], [],
2438+
[*-*-linux*|*-apple-darwin*], [
2439+
AS_VAR_IF([Py_DEBUG], [true], [], [
2440+
AS_CASE([" $OPT $CFLAGS "],
2441+
[*" -Os "*|*" -Oz "*], [],
2442+
[AX_CHECK_COMPILE_FLAG([-falign-functions=64], [
2443+
FUNCTION_ALIGNMENT_CFLAGS="-falign-functions=64"
2444+
], [], [-Werror])])
2445+
])
2446+
])
2447+
24332448
# WASM flags
24342449
AS_CASE([$ac_sys_system],
24352450
[Emscripten], [
@@ -2558,6 +2573,7 @@ AS_CASE([$enable_wasm_dynamic_linking],
25582573

25592574
AC_SUBST([BASECFLAGS])
25602575
AC_SUBST([CFLAGS_NODIST])
2576+
AC_SUBST([FUNCTION_ALIGNMENT_CFLAGS])
25612577
AC_SUBST([LDFLAGS_NODIST])
25622578
AC_SUBST([EXE_LDFLAGS])
25632579
AC_SUBST([LDFLAGS_NOLTO])

0 commit comments

Comments
 (0)