mirror of
https://github.com/python/cpython.git
synced 2026-05-06 04:37:33 -04:00
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 <vstinner@python.org> --------- Co-authored-by: Filipe Laíns <filipe.lains@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Filipe Laíns <lains@riseup.net>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@ __all__ = [
|
||||
_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')
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -25,7 +25,7 @@ class Test_OSXSupport(unittest.TestCase):
|
||||
'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):
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Introduce executable specific linker flags to ``./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=
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user