Skip to content

Commit 4e45c9c

Browse files
ruetehFFY00vstinner
authored
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>
1 parent 5e61a16 commit 4e45c9c

File tree

9 files changed

+42
-4
lines changed

9 files changed

+42
-4
lines changed

Doc/using/configure.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,9 @@ Linker flags
16501650
value to be able to build extension modules using the
16511651
directories specified in the environment variables.
16521652

1653+
Please consider using ``EXE_LDFLAGS`` if the supplied linker flags are
1654+
executable specific, e.g. GCC's ``-pie`` flag.
1655+
16531656
.. envvar:: LIBS
16541657

16551658
Linker flags to pass libraries to the linker when linking the Python
@@ -1685,6 +1688,30 @@ Linker flags
16851688

16861689
.. versionadded:: 3.8
16871690

1691+
.. envvar:: EXE_LDFLAGS
1692+
1693+
Linker flags used for building executable targets such as the
1694+
interpreter. If supplied, :envvar:`PY_CORE_EXE_LDFLAGS`
1695+
will be used in replacement of :envvar:`PY_CORE_LDFLAGS`.
1696+
1697+
.. versionadded:: 3.15
1698+
1699+
.. envvar:: CONFIGURE_EXE_LDFLAGS
1700+
1701+
Value of :envvar:`EXE_LDFLAGS` variable passed to the ``./configure``
1702+
script.
1703+
1704+
.. versionadded:: 3.15
1705+
1706+
.. envvar:: PY_CORE_EXE_LDFLAGS
1707+
1708+
Linker flags used for building the interpreter and
1709+
executable targets.
1710+
1711+
Default: ``$(PY_CORE_LDFLAGS)``
1712+
1713+
.. versionadded:: 3.15
1714+
16881715

16891716
.. rubric:: Footnotes
16901717

Lib/_osx_support.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS',
1818
'BLDSHARED', 'LDSHARED', 'CC', 'CXX',
1919
'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
20-
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS')
20+
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS',
21+
'PY_CORE_EXE_LDFLAGS')
2122

2223
# configuration variables that may contain compiler calls
2324
_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX')

Lib/test/pythoninfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ def collect_sysconfig(info_add):
528528
'PY_CFLAGS',
529529
'PY_CFLAGS_NODIST',
530530
'PY_CORE_LDFLAGS',
531+
'PY_CORE_EXE_LDFLAGS',
531532
'PY_LDFLAGS',
532533
'PY_LDFLAGS_NODIST',
533534
'PY_STDMODULE_CFLAGS',

Lib/test/test__osx_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self):
2525
'CFLAGS', 'LDFLAGS', 'CPPFLAGS',
2626
'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',
2727
'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
28-
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS'
28+
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS', 'PY_CORE_EXE_LDFLAGS'
2929
)
3030

3131
def add_expected_saved_initial_values(self, config_vars, expected_vars):

Makefile.pre.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ PY_STDMODULE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFOR
123123
PY_BUILTIN_MODULE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN
124124
PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
125125
# Linker flags used for building the interpreter object files
126+
# In particular, EXE_LDFLAGS is an extra flag to provide fine grain distinction between
127+
# LDFLAGS used to build executables and shared targets.
126128
PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
129+
CONFIGURE_EXE_LDFLAGS=@EXE_LDFLAGS@
130+
PY_CORE_EXE_LDFLAGS:= $(if $(CONFIGURE_EXE_LDFLAGS), $(CONFIGURE_EXE_LDFLAGS) $(PY_LDFLAGS_NODIST), $(PY_CORE_LDFLAGS))
127131
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
128132
CFLAGS_ALIASING=@CFLAGS_ALIASING@
129133

@@ -986,7 +990,7 @@ clinic-tests: check-clean-src $(srcdir)/Lib/test/clinic.test.c
986990

987991
# Build the interpreter
988992
$(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS)
989-
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
993+
$(LINKCC) $(PY_CORE_EXE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
990994

991995
platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
992996
$(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)
16761680
$(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/build/generate_re_casefix.py $(srcdir)/Lib/re/_casefix.py
16771681

16781682
Programs/_testembed: Programs/_testembed.o $(LINK_PYTHON_DEPS)
1679-
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
1683+
$(LINKCC) $(PY_CORE_EXE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
16801684

16811685
############################################################################
16821686
# "Bootstrap Python" used to run Programs/_freeze_module.py

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,7 @@ Guo Ci Teo
19161916
Mikhail Terekhov
19171917
Victor Terrón
19181918
Pablo Galindo
1919+
Rue Ching Teh
19191920
Richard M. Tew
19201921
Srinivas Reddy Thatiparthy
19211922
Tobias Thelen
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Introduce executable specific linker flags to ``./configure``.

configure

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ AS_CASE([$enable_wasm_dynamic_linking],
24222422
AC_SUBST([BASECFLAGS])
24232423
AC_SUBST([CFLAGS_NODIST])
24242424
AC_SUBST([LDFLAGS_NODIST])
2425+
AC_SUBST([EXE_LDFLAGS])
24252426
AC_SUBST([LDFLAGS_NOLTO])
24262427
AC_SUBST([WASM_ASSETS_DIR])
24272428
AC_SUBST([WASM_STDLIB])

0 commit comments

Comments
 (0)