diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6853c04143512c..9b9e166e88896c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -578,6 +578,12 @@ Build Changes ``libdb`` 3.x and 4.x are no longer supported. (Contributed by Christian Heimes in :issue:`45747`.) +* The Python binary now builds the libpython static library using + ``-Wl,--whole-archive`` or ``-Wl,-all_load`` linker option to + export all symbols exported by object files. + Previously, the ``Py_FrozenMain`` symbol was not exported. + (Contributed by Hai Shi and Victor Stinner in :issue:`44133`.) + C API Changes ============= diff --git a/Misc/NEWS.d/next/Build/2021-12-01-16-46-13.bpo-44133.TOgTVh.rst b/Misc/NEWS.d/next/Build/2021-12-01-16-46-13.bpo-44133.TOgTVh.rst new file mode 100644 index 00000000000000..6d93f125790689 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-12-01-16-46-13.bpo-44133.TOgTVh.rst @@ -0,0 +1,5 @@ +The Python binary now builds the libpython static library using +``-Wl,--whole-archive`` or ``-Wl,-all_load`` linker option to +export all symbols exported by object files. +Previously, the ``Py_FrozenMain`` symbol was not exported. +Patch by Hai Shi and Victor Stinner. diff --git a/configure b/configure index 382e0309747279..f2c07f026cd878 100755 --- a/configure +++ b/configure @@ -6479,12 +6479,17 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h esac else # shared is disabled PY_ENABLE_SHARED=0 - case $ac_sys_system in - CYGWIN*) - BLDLIBRARY='$(LIBRARY)' - LDLIBRARY='libpython$(LDVERSION).dll.a' - ;; - esac + case $ac_sys_system in #( + CYGWIN*) : + BLDLIBRARY='$(LIBRARY)' + LDLIBRARY='libpython$(LDVERSION).dll.a' ;; #( + Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*|VxWorks*) : + BLDLIBRARY='-Wl,--whole-archive $(LDLIBRARY) -Wl,--no-whole-archive' ;; #( + Darwin*) : + BLDLIBRARY='-Wl,-all_load $(LDLIBRARY)' ;; #( + *) : + ;; +esac fi if test "$cross_compiling" = yes; then diff --git a/configure.ac b/configure.ac index 1e5fef337ca5d1..bdd7ed9b04853f 100644 --- a/configure.ac +++ b/configure.ac @@ -1295,12 +1295,14 @@ if test $enable_shared = "yes"; then esac else # shared is disabled PY_ENABLE_SHARED=0 - case $ac_sys_system in - CYGWIN*) - BLDLIBRARY='$(LIBRARY)' - LDLIBRARY='libpython$(LDVERSION).dll.a' - ;; - esac + AS_CASE([$ac_sys_system], + [CYGWIN*], + [BLDLIBRARY='$(LIBRARY)' + LDLIBRARY='libpython$(LDVERSION).dll.a'], + [Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*|VxWorks*], + [BLDLIBRARY='-Wl,--whole-archive $(LDLIBRARY) -Wl,--no-whole-archive'], + [Darwin*], + [BLDLIBRARY='-Wl,-all_load $(LDLIBRARY)']) fi if test "$cross_compiling" = yes; then