https://github.com/python/cpython/commit/4e45c9c309abb12c622334c7a419503d169af380
commit: 4e45c9c309abb12c622334c7a419503d169af380
branch: main
author: rueteh <[email protected]>
committer: FFY00 <[email protected]>
date: 2026-02-24T22:52:02Z
summary:

gh-136677: Introduce executable specific linker flags to configure (#137296)

* introduce executable specific linker flags

Add PY_CORE_EXE_LDFLAGS and EXE_LDFLAGS which stores executable specific
LDFLAGS, replacing PY_CORE_LDFLAGS for building
executable targets.

If PY_CORE_EXE_LDFLAGS / EXE_LDFLAGS is not provided, then it defaults
to the value of PY_CORE_LDFLAGS which is the existing behaviour.

If both flags are supplied, and there is a need
to distinguish between executable and shared specific LDFLAGS,
in particular, PY_CORE_LDFLAGS should contain the shared specific LDFLAGS.

* documentation for new linker flags

* update Misc folder documentation

* Update Makefile.pre.in

Co-authored-by: Victor Stinner <[email protected]>

---------

Co-authored-by: Filipe Laíns <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Filipe Laíns <[email protected]>

files:
A Misc/NEWS.d/next/Build/2025-07-21-00-33-38.gh-issue-136677.Y1_3ec.rst
M Doc/using/configure.rst
M Lib/_osx_support.py
M Lib/test/pythoninfo.py
M Lib/test/test__osx_support.py
M Makefile.pre.in
M Misc/ACKS
M configure
M configure.ac

diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index 50812358a690c3..813127663ed8fe 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -1650,6 +1650,9 @@ Linker flags
    value to be able to build extension modules using the
    directories specified in the environment variables.
 
+   Please consider using ``EXE_LDFLAGS`` if the supplied linker flags are
+   executable specific, e.g. GCC's ``-pie`` flag.
+
 .. envvar:: LIBS
 
    Linker flags to pass libraries to the linker when linking the Python
@@ -1685,6 +1688,30 @@ Linker flags
 
    .. versionadded:: 3.8
 
+.. envvar:: EXE_LDFLAGS
+
+   Linker flags used for building executable targets such as the
+   interpreter. If supplied, :envvar:`PY_CORE_EXE_LDFLAGS`
+   will be used in replacement of :envvar:`PY_CORE_LDFLAGS`.
+
+   .. versionadded:: 3.15
+
+.. envvar:: CONFIGURE_EXE_LDFLAGS
+
+   Value of :envvar:`EXE_LDFLAGS` variable passed to the ``./configure``
+   script.
+
+   .. versionadded:: 3.15
+
+.. envvar:: PY_CORE_EXE_LDFLAGS
+
+   Linker flags used for building the interpreter and
+   executable targets.
+
+   Default: ``$(PY_CORE_LDFLAGS)``
+
+   .. versionadded:: 3.15
+
 
 .. rubric:: Footnotes
 
diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py
index 0cb064fcd791be..29b89e311cb1fe 100644
--- a/Lib/_osx_support.py
+++ b/Lib/_osx_support.py
@@ -17,7 +17,8 @@
 _UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
                             'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
                             'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
-                            'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS')
+                            'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS',
+                            'PY_CORE_EXE_LDFLAGS')
 
 # configuration variables that may contain compiler calls
 _COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index 3befc0f2e633ca..fdd8989f9cb3f8 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -528,6 +528,7 @@ def collect_sysconfig(info_add):
         'PY_CFLAGS',
         'PY_CFLAGS_NODIST',
         'PY_CORE_LDFLAGS',
+        'PY_CORE_EXE_LDFLAGS',
         'PY_LDFLAGS',
         'PY_LDFLAGS_NODIST',
         'PY_STDMODULE_CFLAGS',
diff --git a/Lib/test/test__osx_support.py b/Lib/test/test__osx_support.py
index 0813c4804c1cdc..b92ce6796b50fb 100644
--- a/Lib/test/test__osx_support.py
+++ b/Lib/test/test__osx_support.py
@@ -25,7 +25,7 @@ def setUp(self):
             'CFLAGS', 'LDFLAGS', 'CPPFLAGS',
             'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',
             'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
-            'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS'
+            'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS', 'PY_CORE_EXE_LDFLAGS'
         )
 
     def add_expected_saved_initial_values(self, config_vars, expected_vars):
diff --git a/Makefile.pre.in b/Makefile.pre.in
index f4119abf324fca..122957dec29b6f 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -123,7 +123,11 @@ PY_STDMODULE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) 
$(PY_CPPFLAGS) $(CFLAGSFOR
 PY_BUILTIN_MODULE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN
 PY_CORE_CFLAGS=        $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
 # Linker flags used for building the interpreter object files
+# In particular, EXE_LDFLAGS is an extra flag to provide fine grain 
distinction between
+# LDFLAGS used to build executables and shared targets.
 PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
+CONFIGURE_EXE_LDFLAGS=@EXE_LDFLAGS@
+PY_CORE_EXE_LDFLAGS:= $(if $(CONFIGURE_EXE_LDFLAGS), $(CONFIGURE_EXE_LDFLAGS) 
$(PY_LDFLAGS_NODIST), $(PY_CORE_LDFLAGS))
 # Strict or non-strict aliasing flags used to compile dtoa.c, see above
 CFLAGS_ALIASING=@CFLAGS_ALIASING@
 
@@ -986,7 +990,7 @@ clinic-tests: check-clean-src 
$(srcdir)/Lib/test/clinic.test.c
 
 # Build the interpreter
 $(BUILDPYTHON):        Programs/python.o $(LINK_PYTHON_DEPS)
-       $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o 
$(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
+       $(LINKCC) $(PY_CORE_EXE_LDFLAGS) $(LINKFORSHARED) -o $@ 
Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
 
 platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
        $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import 
get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' 
>platform
@@ -1676,7 +1680,7 @@ regen-re: $(BUILDPYTHON)
        $(RUNSHARED) ./$(BUILDPYTHON) 
$(srcdir)/Tools/build/generate_re_casefix.py $(srcdir)/Lib/re/_casefix.py
 
 Programs/_testembed: Programs/_testembed.o $(LINK_PYTHON_DEPS)
-       $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ 
Programs/_testembed.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
+       $(LINKCC) $(PY_CORE_EXE_LDFLAGS) $(LINKFORSHARED) -o $@ 
Programs/_testembed.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
 
 ############################################################################
 # "Bootstrap Python" used to run Programs/_freeze_module.py
diff --git a/Misc/ACKS b/Misc/ACKS
index 3464bd95bac791..e38bda37bfa92d 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1916,6 +1916,7 @@ Guo Ci Teo
 Mikhail Terekhov
 Victor Terrón
 Pablo Galindo
+Rue Ching Teh
 Richard M. Tew
 Srinivas Reddy Thatiparthy
 Tobias Thelen
diff --git 
a/Misc/NEWS.d/next/Build/2025-07-21-00-33-38.gh-issue-136677.Y1_3ec.rst 
b/Misc/NEWS.d/next/Build/2025-07-21-00-33-38.gh-issue-136677.Y1_3ec.rst
new file mode 100644
index 00000000000000..30addc4bf64d4b
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2025-07-21-00-33-38.gh-issue-136677.Y1_3ec.rst
@@ -0,0 +1 @@
+Introduce executable specific linker flags to ``./configure``.
diff --git a/configure b/configure
index 98b4af86858673..dd62fd90e38ee1 100755
--- a/configure
+++ b/configure
@@ -915,6 +915,7 @@ UNIVERSAL_ARCH_FLAGS
 WASM_STDLIB
 WASM_ASSETS_DIR
 LDFLAGS_NOLTO
+EXE_LDFLAGS
 LDFLAGS_NODIST
 CFLAGS_NODIST
 BASECFLAGS
@@ -9745,6 +9746,7 @@ esac
 
 
 
+
 # The -arch flags for universal builds on macOS
 UNIVERSAL_ARCH_FLAGS=
 
diff --git a/configure.ac b/configure.ac
index 34318769fcc29f..8b90d8ca896f0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2422,6 +2422,7 @@ AS_CASE([$enable_wasm_dynamic_linking],
 AC_SUBST([BASECFLAGS])
 AC_SUBST([CFLAGS_NODIST])
 AC_SUBST([LDFLAGS_NODIST])
+AC_SUBST([EXE_LDFLAGS])
 AC_SUBST([LDFLAGS_NOLTO])
 AC_SUBST([WASM_ASSETS_DIR])
 AC_SUBST([WASM_STDLIB])

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to