From cfe7cf859511b727c6bf54cb9a9f060e00fc7e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sat, 4 Jan 2025 04:38:46 +0000 Subject: [PATCH] GH-128469: set RPATH on the builddir Python executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns platform @@ -2264,7 +2271,7 @@ sharedinstall: all # Install the interpreter with $(VERSION) affixed # This goes into $(exec_prefix) .PHONY: altbininstall -altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@ +altbininstall: python-bin $(BUILDPYTHON) @FRAMEWORKPYTHONW@ @for i in $(BINDIR) $(LIBDIR); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -2274,7 +2281,7 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@ fi; \ done if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \ - $(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \ + $(INSTALL_PROGRAM) `cat pybuilddir.txt`/$(PYTHON) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \ else \ $(INSTALL_PROGRAM) $(STRIPFLAG) Mac/pythonw $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \ fi diff --git a/config.sub b/config.sub index 1bb6a05dc11026..defe52c0c874ba 100755 --- a/config.sub +++ b/config.sub @@ -1,11 +1,10 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2024 Free Software Foundation, Inc. +# Copyright 1992-2023 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale -# Patched 2024-02-03 to include support for arm64_32 and iOS/tvOS/watchOS simulators -timestamp='2024-01-01' +timestamp='2023-09-19' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -77,7 +76,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright 1992-2024 Free Software Foundation, Inc. +Copyright 1992-2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -1128,7 +1127,7 @@ case $cpu-$vendor in xscale-* | xscalee[bl]-*) cpu=`echo "$cpu" | sed 's/^xscale/arm/'` ;; - arm64-* | aarch64le-* | arm64_32-*) + arm64-* | aarch64le-*) cpu=aarch64 ;; @@ -1223,7 +1222,6 @@ case $cpu-$vendor in | moxie \ | mt \ | msp430 \ - | nanomips* \ | nds32 | nds32le | nds32be \ | nfp \ | nios | nios2 | nios2eb | nios2el \ @@ -1255,7 +1253,6 @@ case $cpu-$vendor in | ubicom32 \ | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ | vax \ - | vc4 \ | visium \ | w65 \ | wasm32 | wasm64 \ @@ -1600,7 +1597,7 @@ case $cpu-$vendor in os= obj=elf ;; - mips*-*|nanomips*-*) + mips*-*) os= obj=elf ;; @@ -1724,7 +1721,7 @@ fi case $os in # Sometimes we do "kernel-libc", so those need to count as OSes. - llvm* | musl* | newlib* | relibc* | uclibc*) + musl* | newlib* | relibc* | uclibc*) ;; # Likewise for "kernel-abi" eabi* | gnueabi*) @@ -1769,19 +1766,12 @@ case $os in | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ - | fiwix* | mlibc* | cos* | mbr* | ironclad* ) + | fiwix* | mlibc* | cos* | mbr* ) ;; # This one is extra strict with allowed versions sco3.2v2 | sco3.2v[4-9]* | sco5v6*) # Don't forget version if it is 3.2v4 or newer. ;; - # This refers to builds using the UEFI calling convention - # (which depends on the architecture) and PE file format. - # Note that this is both a different calling convention and - # different file format than that of GNU-EFI - # (x86_64-w64-mingw32). - uefi) - ;; none) ;; kernel* | msvc* ) @@ -1828,9 +1818,8 @@ esac # As a final step for OS-related things, validate the OS-kernel combination # (given a valid OS), if there is a kernel. case $kernel-$os-$obj in - linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ - | linux-mlibc*- | linux-musl*- | linux-newlib*- \ - | linux-relibc*- | linux-uclibc*- ) + linux-gnu*- | linux-dietlibc*- | linux-android*- | linux-newlib*- \ + | linux-musl*- | linux-relibc*- | linux-uclibc*- | linux-mlibc*- ) ;; uclinux-uclibc*- ) ;; @@ -1838,8 +1827,7 @@ case $kernel-$os-$obj in ;; windows*-msvc*-) ;; - -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ - | -uclibc*- ) + -dietlibc*- | -newlib*- | -musl*- | -relibc*- | -uclibc*- | -mlibc*- ) # These are just libc implementations, not actual OSes, and thus # require a kernel. echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 @@ -1867,8 +1855,6 @@ case $kernel-$os-$obj in ;; *-eabi*- | *-gnueabi*-) ;; - ios*-simulator- | tvos*-simulator- | watchos*-simulator- ) - ;; none--*) # None (no kernel, i.e. freestanding / bare metal), # can be paired with an machine code file format diff --git a/configure b/configure index aa88c74c61156c..101473eb0198fb 100755 --- a/configure +++ b/configure @@ -940,8 +940,8 @@ LINK_PYTHON_DEPS LIBRARY_DEPS HOSTRUNNER NODE +BUILDPYTHON_LDFLAGS STATIC_LIBPYTHON -GNULD EXPORTSFROM EXPORTSYMS LINKCC @@ -1026,6 +1026,7 @@ HAS_GIT GITBRANCH GITTAG GITVERSION +GNULD BASECPPFLAGS target_alias host_alias @@ -3557,6 +3558,47 @@ else BASECPPFLAGS="" fi +# GNULD is set to "yes" if the GNU linker is used. If this goes wrong +# make sure we default having it set to "no": this is used by +# distutils.unixccompiler to know if it should add --enable-new-dtags +# to linker command lines, and failing to detect GNU ld simply results +# in the same behaviour as before. + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +printf %s "checking for GNU ld... " >&6; } +ac_prog=ld +if test "$ac_cv_cc_name" = "gcc"; then + ac_prog=`$CC -print-prog-name=ld` +fi +case `"$ac_prog" -V 2>&1 < /dev/null` in + *GNU*) + GNULD=yes;; + *) + GNULD=no;; +esac +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $GNULD" >&5 +printf "%s\n" "$GNULD" >&6; } + +# RPATH and RUNPATH flags +if test "x$GNULD" = xyes +then : + + rpath_arg="-Wl,--disable-new-dtags,-rpath=" + runpath_arg="-Wl,--enable-new-dtags,-rpath=" + +else case e in #( + e) + if test "$ac_sys_system" = "Darwin" + then + rpath_arg="-Wl,-rpath," + else + rpath_arg="-Wl,-rpath=" + fi + runpath_arg="$rpath_arg" + ;; +esac +fi + @@ -7531,27 +7573,6 @@ esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $EXPORTSYMS" >&5 printf "%s\n" "$EXPORTSYMS" >&6; } -# GNULD is set to "yes" if the GNU linker is used. If this goes wrong -# make sure we default having it set to "no": this is used by -# distutils.unixccompiler to know if it should add --enable-new-dtags -# to linker command lines, and failing to detect GNU ld simply results -# in the same behaviour as before. - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -printf %s "checking for GNU ld... " >&6; } -ac_prog=ld -if test "$ac_cv_cc_name" = "gcc"; then - ac_prog=`$CC -print-prog-name=ld` -fi -case `"$ac_prog" -V 2>&1 < /dev/null` in - *GNU*) - GNULD=yes;; - *) - GNULD=no;; -esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $GNULD" >&5 -printf "%s\n" "$GNULD" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --enable-shared" >&5 printf %s "checking for --enable-shared... " >&6; } # Check whether --enable-shared was given. @@ -7638,6 +7659,12 @@ fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking LDLIBRARY" >&5 printf %s "checking LDLIBRARY... " >&6; } +# If libpython is built as a shared library, set RPATH on the builddir Python executable +if test $enable_shared = "yes"; then + BUILDPYTHON_LDFLAGS="${rpath_arg}'\$\$ORIGIN'" +fi + + # Apple framework builds need more magic. LDLIBRARY is the dynamic # library that we build, but we do not want to link against it (we # will find it with a -framework option). For this reason there is an @@ -29935,24 +29962,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ -# rpath to libssl and libcrypto -if test "x$GNULD" = xyes -then : - - rpath_arg="-Wl,--enable-new-dtags,-rpath=" - -else case e in #( - e) - if test "$ac_sys_system" = "Darwin" - then - rpath_arg="-Wl,-rpath," - else - rpath_arg="-Wl,-rpath=" - fi - ;; -esac -fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-openssl-rpath" >&5 printf %s "checking for --with-openssl-rpath... " >&6; } @@ -29973,7 +29982,7 @@ case $with_openssl_rpath in #( for arg in "$OPENSSL_LDFLAGS"; do case $arg in #( -L*) : - OPENSSL_LDFLAGS_RPATH="$OPENSSL_LDFLAGS_RPATH ${rpath_arg}$(echo $arg | cut -c3-)" + OPENSSL_LDFLAGS_RPATH="$OPENSSL_LDFLAGS_RPATH ${runpath_arg}$(echo $arg | cut -c3-)" ;; #( *) : ;; @@ -29987,7 +29996,7 @@ esac then : OPENSSL_RPATH="$with_openssl_rpath" - OPENSSL_LDFLAGS_RPATH="${rpath_arg}$with_openssl_rpath" + OPENSSL_LDFLAGS_RPATH="${runpath_arg}$with_openssl_rpath" else case e in #( e) as_fn_error $? "--with-openssl-rpath \"$with_openssl_rpath\" is not a directory" "$LINENO" 5 ;; diff --git a/configure.ac b/configure.ac index 9e131ed1a2dc98..c434eb610d888d 100644 --- a/configure.ac +++ b/configure.ac @@ -110,6 +110,39 @@ else BASECPPFLAGS="" fi +# GNULD is set to "yes" if the GNU linker is used. If this goes wrong +# make sure we default having it set to "no": this is used by +# distutils.unixccompiler to know if it should add --enable-new-dtags +# to linker command lines, and failing to detect GNU ld simply results +# in the same behaviour as before. +AC_SUBST([GNULD]) +AC_MSG_CHECKING([for GNU ld]) +ac_prog=ld +if test "$ac_cv_cc_name" = "gcc"; then + ac_prog=`$CC -print-prog-name=ld` +fi +case `"$ac_prog" -V 2>&1 < /dev/null` in + *GNU*) + GNULD=yes;; + *) + GNULD=no;; +esac +AC_MSG_RESULT([$GNULD]) + +# RPATH and RUNPATH flags +AS_VAR_IF([GNULD], [yes], [ + rpath_arg="-Wl,--disable-new-dtags,-rpath=" + runpath_arg="-Wl,--enable-new-dtags,-rpath=" +], [ + if test "$ac_sys_system" = "Darwin" + then + rpath_arg="-Wl,-rpath," + else + rpath_arg="-Wl,-rpath=" + fi + runpath_arg="$rpath_arg" +]) + AC_SUBST([GITVERSION]) AC_SUBST([GITTAG]) AC_SUBST([GITBRANCH]) @@ -1438,25 +1471,6 @@ AIX*) esac AC_MSG_RESULT([$EXPORTSYMS]) -# GNULD is set to "yes" if the GNU linker is used. If this goes wrong -# make sure we default having it set to "no": this is used by -# distutils.unixccompiler to know if it should add --enable-new-dtags -# to linker command lines, and failing to detect GNU ld simply results -# in the same behaviour as before. -AC_SUBST([GNULD]) -AC_MSG_CHECKING([for GNU ld]) -ac_prog=ld -if test "$ac_cv_cc_name" = "gcc"; then - ac_prog=`$CC -print-prog-name=ld` -fi -case `"$ac_prog" -V 2>&1 < /dev/null` in - *GNU*) - GNULD=yes;; - *) - GNULD=no;; -esac -AC_MSG_RESULT([$GNULD]) - AC_MSG_CHECKING([for --enable-shared]) AC_ARG_ENABLE([shared], AS_HELP_STRING([--enable-shared], [enable building a shared Python library (default is no)])) @@ -1511,6 +1525,12 @@ fi AC_MSG_CHECKING([LDLIBRARY]) +# If libpython is built as a shared library, set RPATH on the builddir Python executable +if test $enable_shared = "yes"; then + BUILDPYTHON_LDFLAGS="${rpath_arg}'\$\$ORIGIN'" +fi +AC_SUBST([BUILDPYTHON_LDFLAGS]) + # Apple framework builds need more magic. LDLIBRARY is the dynamic # library that we build, but we do not want to link against it (we # will find it with a -framework option). For this reason there is an @@ -7232,18 +7252,6 @@ WITH_SAVE_ENV([ # Check for usable OpenSSL AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no]) -# rpath to libssl and libcrypto -AS_VAR_IF([GNULD], [yes], [ - rpath_arg="-Wl,--enable-new-dtags,-rpath=" -], [ - if test "$ac_sys_system" = "Darwin" - then - rpath_arg="-Wl,-rpath," - else - rpath_arg="-Wl,-rpath=" - fi -]) - AC_MSG_CHECKING([for --with-openssl-rpath]) AC_ARG_WITH([openssl-rpath], AS_HELP_STRING([--with-openssl-rpath=@<:@DIR|auto|no@:>@], @@ -7261,7 +7269,7 @@ AS_CASE([$with_openssl_rpath], dnl look for linker directories for arg in "$OPENSSL_LDFLAGS"; do AS_CASE([$arg], - [-L*], [OPENSSL_LDFLAGS_RPATH="$OPENSSL_LDFLAGS_RPATH ${rpath_arg}$(echo $arg | cut -c3-)"] + [-L*], [OPENSSL_LDFLAGS_RPATH="$OPENSSL_LDFLAGS_RPATH ${runpath_arg}$(echo $arg | cut -c3-)"] ) done ], @@ -7270,7 +7278,7 @@ AS_CASE([$with_openssl_rpath], [test -d "$with_openssl_rpath"], [ OPENSSL_RPATH="$with_openssl_rpath" - OPENSSL_LDFLAGS_RPATH="${rpath_arg}$with_openssl_rpath" + OPENSSL_LDFLAGS_RPATH="${runpath_arg}$with_openssl_rpath" ], AC_MSG_ERROR([--with-openssl-rpath "$with_openssl_rpath" is not a directory])) ]