From bc60b61355e5cb0c9195a8b329ac8b19274e58b4 Mon Sep 17 00:00:00 2001 From: zaniebot <242828183+zaniebot@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:51:05 +0000 Subject: [PATCH] gh-119696: Apply BOLT profiles to relocatable install binaries --- Doc/using/configure.rst | 1 - Makefile.pre.in | 16 ++++++++++++++-- ...026-10-22-22-11-00.gh-issue-119696.RlocBt.rst | 3 +++ configure | 7 ------- configure.ac | 4 ---- 5 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-10-22-22-11-00.gh-issue-119696.RlocBt.rst diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 0e4e35ffcdb7db..ba07babe6f1271 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -1084,7 +1084,6 @@ Linker options Currently, this sets relative runtime library paths on Linux and for non-framework macOS builds. Framework relocation is not implemented yet. Combining this option with :option:`--enable-framework` is an error. - Combining it with :option:`--enable-bolt` is an error. Move the installation as a unit. It must use the default ``bin`` and ``lib`` directories under a common prefix. :option:`--with-platlibdir` may select diff --git a/Makefile.pre.in b/Makefile.pre.in index 87a0c2cbcb8295..86752f28bf6b94 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -887,6 +887,10 @@ profile-opt: profile-run-stamp # List of binaries that BOLT runs on. BOLT_BINARIES := @BOLT_BINARIES@ +ifeq ($(RELOCATABLE),yes) +# Optimize libraries before the interpreter, which depends on their timestamps. +RELOCATABLE_BOLT_BINARIES = $(addprefix $(RELOCATABLE_DIR)/,$(filter-out $(BUILDPYTHON),$(BOLT_BINARIES)) $(BUILDPYTHON)) +endif BOLT_INSTRUMENT_FLAGS := @BOLT_INSTRUMENT_FLAGS@ BOLT_APPLY_FLAGS := @BOLT_APPLY_FLAGS@ @@ -896,13 +900,13 @@ clean-bolt: # Profile data. rm -f *.fdata # Pristine binaries before BOLT optimization. - rm -f *.prebolt + rm -f *.prebolt $(RELOCATABLE_DIR)/*.prebolt # BOLT instrumented binaries. rm -f *.bolt_inst profile-bolt-stamp: $(BUILDPYTHON) # Ensure a pristine, pre-BOLT copy of the binary and no profile data from last run. - for bin in $(BOLT_BINARIES); do \ + for bin in $(BOLT_BINARIES) $(RELOCATABLE_BOLT_BINARIES); do \ prebolt="$${bin}.prebolt"; \ if [ -e "$${prebolt}" ]; then \ echo "Restoring pre-BOLT binary $${prebolt}"; \ @@ -928,6 +932,14 @@ profile-bolt-stamp: $(BUILDPYTHON) @LLVM_BOLT@ "$${bin}.prebolt" -o "$${bin}.bolt" -data="$${bin}.fdata" $(BOLT_APPLY_FLAGS); \ mv "$${bin}.bolt" "$${bin}"; \ done + # Install variants are linked from the same objects, so reuse the function profiles. + for bin in $(RELOCATABLE_BOLT_BINARIES); do \ + @LLVM_BOLT@ "$${bin}.prebolt" -o "$${bin}.bolt" -data="$${bin##*/}.fdata" $(BOLT_APPLY_FLAGS); \ + mv "$${bin}.bolt" "$${bin}"; \ + done + if test "$(RELOCATABLE)" = yes && test -n "$(filter $(INSTSONAME),$(BOLT_BINARIES))"; then \ + $(LN) -f $(RELOCATABLE_DIR)/$(INSTSONAME) $(INSTALL_LDLIBRARY); \ + fi touch $@ .PHONY: bolt-opt diff --git a/Misc/NEWS.d/next/Build/2026-10-22-22-11-00.gh-issue-119696.RlocBt.rst b/Misc/NEWS.d/next/Build/2026-10-22-22-11-00.gh-issue-119696.RlocBt.rst new file mode 100644 index 00000000000000..9e372e21d30850 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-22-22-11-00.gh-issue-119696.RlocBt.rst @@ -0,0 +1,3 @@ +Support :option:`--enable-bolt` with :option:`--enable-relocatable` +by applying the build-tree profiles to the separately linked installation +interpreter and, when applicable, shared library. diff --git a/configure b/configure index 72ea026f5c591c..391bae97f28031 100755 --- a/configure +++ b/configure @@ -9481,13 +9481,6 @@ esac fi -if test "$enable_relocatable" = yes && test "$Py_BOLT" = true -then : - - as_fn_error $? "--enable-relocatable does not support --enable-bolt yet" "$LINENO" 5 - -fi - if test "$Py_BOLT" = 'true' ; then PREBOLT_RULE="${DEF_MAKE_ALL_RULE}" diff --git a/configure.ac b/configure.ac index b30fcd00252111..5a7fc0017a5563 100644 --- a/configure.ac +++ b/configure.ac @@ -2215,10 +2215,6 @@ else fi], [AC_MSG_RESULT([no])]) -AS_IF([test "$enable_relocatable" = yes && test "$Py_BOLT" = true], [ - AC_MSG_ERROR([--enable-relocatable does not support --enable-bolt yet]) -]) - AC_SUBST([PREBOLT_RULE]) if test "$Py_BOLT" = 'true' ; then PREBOLT_RULE="${DEF_MAKE_ALL_RULE}"