From d1ac334eb7c6a6d8a1d5d8525001bbd981fc51d9 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 22 Oct 2026 18:00:05 +0000 Subject: [PATCH] gh-119696: Add an experimental relocatable configure flag --- Doc/using/configure.rst | 11 ++++++ Makefile.pre.in | 1 + ...-10-22-18-00-00.gh-issue-119696.r3Flag.rst | 2 ++ configure | 34 +++++++++++++++++++ configure.ac | 15 ++++++++ pyconfig.h.in | 3 ++ 6 files changed, 66 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2026-10-22-18-00-00.gh-issue-119696.r3Flag.rst diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 0d420d80f8e261..2cc8e94ebf075c 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -1073,6 +1073,17 @@ Linker options Enable building a shared Python library: ``libpython`` (default is no). +.. option:: --enable-relocatable + + Enable experimental support for relocatable builds (default is no). + This option currently has no effect on the build. + + .. warning:: + + This feature is under active development. Do not use it in production. + + .. versionadded:: 3.16 + .. option:: --without-static-libpython Do not build ``libpythonMAJOR.MINOR.a`` and do not install ``python.o`` diff --git a/Makefile.pre.in b/Makefile.pre.in index 36515dbd146a1e..7dcfc455797696 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -60,6 +60,7 @@ DSYMUTIL= @DSYMUTIL@ DSYMUTIL_PATH= @DSYMUTIL_PATH@ GNULD= @GNULD@ +RELOCATABLE= @RELOCATABLE@ # Shell used by make (some versions default to the login shell, which is bad) SHELL= /bin/sh -e diff --git a/Misc/NEWS.d/next/Build/2026-10-22-18-00-00.gh-issue-119696.r3Flag.rst b/Misc/NEWS.d/next/Build/2026-10-22-18-00-00.gh-issue-119696.r3Flag.rst new file mode 100644 index 00000000000000..328d94c1094e4c --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-22-18-00-00.gh-issue-119696.r3Flag.rst @@ -0,0 +1,2 @@ +Add the experimental :option:`--enable-relocatable` configure option. +The option currently has no effect on the build. diff --git a/configure b/configure index c777d8117c66c4..9ab251a0fe22ee 100755 --- a/configure +++ b/configure @@ -960,6 +960,7 @@ LINK_PYTHON_DEPS LIBRARY_DEPS HOSTRUNNER NODE +RELOCATABLE STATIC_LIBPYTHON GNULD EXPORTSFROM @@ -1107,6 +1108,7 @@ enable_shared with_static_libpython enable_static_libpython_for_interpreter enable_profiling +enable_relocatable enable_gil with_pydebug with_trace_refs @@ -1859,6 +1861,8 @@ Optional Features: library) --enable-profiling enable C-level code profiling with gprof (default is no) + --enable-relocatable enable experimental relocatable build support + (default is no) --disable-gil enable support for running without the GIL (default is no) --enable-pystats enable internal statistics gathering (default is no) @@ -7937,6 +7941,36 @@ if test "x$enable_profiling" = xyes; then LDFLAGS="-pg $LDFLAGS" fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --enable-relocatable" >&5 +printf %s "checking for --enable-relocatable... " >&6; } +# Check whether --enable-relocatable was given. +if test ${enable_relocatable+y} +then : + enableval=$enable_relocatable; +else case e in #( + e) enable_relocatable=no ;; +esac +fi + +case $enable_relocatable in #( + yes|no) : + ;; #( + *) : + as_fn_error $? "--enable-relocatable must be yes or no" "$LINENO" 5 ;; +esac +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_relocatable" >&5 +printf "%s\n" "$enable_relocatable" >&6; } +if test "x$enable_relocatable" = xyes +then : + + +printf "%s\n" "#define Py_ENABLE_RELOCATABLE 1" >>confdefs.h + + +fi +RELOCATABLE=$enable_relocatable + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking LDLIBRARY" >&5 printf %s "checking LDLIBRARY... " >&6; } diff --git a/configure.ac b/configure.ac index a8760c94ac151a..1afbeba002bbbf 100644 --- a/configure.ac +++ b/configure.ac @@ -1594,6 +1594,21 @@ if test "x$enable_profiling" = xyes; then LDFLAGS="-pg $LDFLAGS" fi +AC_MSG_CHECKING([for --enable-relocatable]) +AC_ARG_ENABLE([relocatable], + AS_HELP_STRING([--enable-relocatable], + [enable experimental relocatable build support (default is no)]), + [], [enable_relocatable=no]) +AS_CASE([$enable_relocatable], + [yes|no], [], + [AC_MSG_ERROR([--enable-relocatable must be yes or no])]) +AC_MSG_RESULT([$enable_relocatable]) +AS_VAR_IF([enable_relocatable], [yes], [ + AC_DEFINE([Py_ENABLE_RELOCATABLE], [1], + [Define if --enable-relocatable is used.]) +]) +AC_SUBST([RELOCATABLE], [$enable_relocatable]) + AC_MSG_CHECKING([LDLIBRARY]) # Apple framework builds need more magic. LDLIBRARY is the dynamic diff --git a/pyconfig.h.in b/pyconfig.h.in index 08306a1dc8ba13..4fb029a6756e3c 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1880,6 +1880,9 @@ /* Define if you want to build an interpreter with many run-time checks. */ #undef Py_DEBUG +/* Define if --enable-relocatable is used. */ +#undef Py_ENABLE_RELOCATABLE + /* Defined if Python is built as a shared library. */ #undef Py_ENABLE_SHARED