Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,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
Expand Down Expand Up @@ -1534,6 +1537,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

Expand Down
3 changes: 2 additions & 1 deletion Lib/_osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,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',
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test__osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@

Expand Down Expand Up @@ -994,7 +998,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
Expand Down Expand Up @@ -1685,7 +1689,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
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,7 @@ Guo Ci Teo
Mikhail Terekhov
Victor Terrón
Pablo Galindo
Rue Ching Teh
Richard M. Tew
Srinivas Reddy Thatiparthy
Tobias Thelen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Introduce executable specific linker flags to ``./configure``.
2 changes: 2 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,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])
Expand Down
Loading