]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111225: Link extension modules against libpython on Android (#115780)
authorMalcolm Smith <smith@chaquo.com>
Wed, 21 Feb 2024 23:18:57 +0000 (23:18 +0000)
committerGitHub <noreply@github.com>
Wed, 21 Feb 2024 23:18:57 +0000 (23:18 +0000)
Part of the work on PEP 738: Adding Android as a supported platform.

* Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately
  reflect its purpose.
* Edit makesetup to use MODULE_LDFLAGS when linking extension modules.
* Edit the Makefile so that extension modules depend on libpython on
  Android and Cygwin.
* Restore `-fPIC` on Android. It was removed several years ago with a
  note that the toolchain used it automatically, but this is no longer
  the case. Omitting it causes all linker commands to fail with an error
  like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against
  symbol '_Py_FalseStruct'; recompile with -fPIC`.

Makefile.pre.in
Misc/NEWS.d/next/Build/2024-02-21-18-22-49.gh-issue-111225.Z8C3av.rst [new file with mode: 0644]
Modules/makesetup
configure
configure.ac

index 8130921b633e530c214701769dd10a5a1dfad3ef..11d22d9a419ba7851c80cff6be5a1da2d80456f2 100644 (file)
@@ -41,7 +41,7 @@ AR=           @AR@
 READELF=       @READELF@
 SOABI=         @SOABI@
 LDVERSION=     @LDVERSION@
-LIBPYTHON=     @LIBPYTHON@
+MODULE_LDFLAGS=@MODULE_LDFLAGS@
 GITVERSION=    @GITVERSION@
 GITTAG=                @GITTAG@
 GITBRANCH=     @GITBRANCH@
@@ -2917,7 +2917,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
 
 # force rebuild when header file or module build flavor (static/shared) is changed
 MODULE_DEPS_STATIC=Modules/config.c
-MODULE_DEPS_SHARED=$(MODULE_DEPS_STATIC) $(EXPORTSYMS)
+MODULE_DEPS_SHARED=@MODULE_DEPS_SHARED@
 
 MODULE__CURSES_DEPS=$(srcdir)/Include/py_curses.h
 MODULE__CURSES_PANEL_DEPS=$(srcdir)/Include/py_curses.h
diff --git a/Misc/NEWS.d/next/Build/2024-02-21-18-22-49.gh-issue-111225.Z8C3av.rst b/Misc/NEWS.d/next/Build/2024-02-21-18-22-49.gh-issue-111225.Z8C3av.rst
new file mode 100644 (file)
index 0000000..8cdeba4
--- /dev/null
@@ -0,0 +1 @@
+Link extension modules against libpython on Android.
index f000c9cd67310e3d3a10fc35cd20598263314825..d41b6640bb5186fa2894c647c42928473b2e9494 100755 (executable)
@@ -87,18 +87,6 @@ esac
 NL='\
 '
 
-# Setup to link with extra libraries when making shared extensions.
-# Currently, only Cygwin needs this baggage.
-case `uname -s` in
-CYGWIN*) if test $libdir = .
-        then
-               ExtraLibDir=.
-        else
-               ExtraLibDir='$(LIBPL)'
-        fi
-        ExtraLibs="-L$ExtraLibDir -lpython\$(LDVERSION)";;
-esac
-
 # Main loop
 for i in ${*-Setup}
 do
@@ -286,7 +274,7 @@ sed -e 's/[         ]*#.*//' -e '/^[        ]*$/d' |
                                ;;
                        esac
                        rule="$file: $objs"
-                       rule="$rule; \$(BLDSHARED) $objs $libs $ExtraLibs -o $file"
+                       rule="$rule; \$(BLDSHARED) $objs $libs \$(MODULE_LDFLAGS) -o $file"
                        echo "$rule" >>$rulesf
                done
        done
index ba2d49df7c65fee8afbdcd84fecf3af13b8468d2..a08fc1ca12e895d7053eb3358c6aded342c4aa5b 100755 (executable)
--- a/configure
+++ b/configure
@@ -834,7 +834,8 @@ LIBPL
 PY_ENABLE_SHARED
 PLATLIBDIR
 BINLIBDEST
-LIBPYTHON
+MODULE_LDFLAGS
+MODULE_DEPS_SHARED
 EXT_SUFFIX
 ALT_SOABI
 SOABI
@@ -7330,6 +7331,7 @@ printf "%s\n" "#define Py_ENABLE_SHARED 1" >>confdefs.h
   case $ac_sys_system in
     CYGWIN*)
       LDLIBRARY='libpython$(LDVERSION).dll.a'
+      BLDLIBRARY='-L. -lpython$(LDVERSION)'
       DLLLIBRARY='libpython$(LDVERSION).dll'
       ;;
     SunOS*)
@@ -12789,7 +12791,6 @@ then
                 then CCSHARED="-fPIC";
                 else CCSHARED="+z";
                 fi;;
-       Linux-android*) ;;
        Linux*|GNU*) CCSHARED="-fPIC";;
        Emscripten*|WASI*)
                if test "x$enable_wasm_dynamic_linking" = xyes
@@ -23959,10 +23960,12 @@ printf "%s\n" "$LDVERSION" >&6; }
 
 # On Android and Cygwin the shared libraries must be linked with libpython.
 
+
+MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)'
+MODULE_LDFLAGS=''
 if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then
-  LIBPYTHON="-lpython${VERSION}${ABIFLAGS}"
-else
-  LIBPYTHON=''
+  MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)"
+  MODULE_LDFLAGS="\$(BLDLIBRARY)"
 fi
 
 
index b39af7422c4c7ca71f11a4c1eaf4979276ff1dda..ac26486144515be44c93f23745866ffe00714343 100644 (file)
@@ -1360,6 +1360,7 @@ if test $enable_shared = "yes"; then
   case $ac_sys_system in
     CYGWIN*)
       LDLIBRARY='libpython$(LDVERSION).dll.a'
+      BLDLIBRARY='-L. -lpython$(LDVERSION)'
       DLLLIBRARY='libpython$(LDVERSION).dll'
       ;;
     SunOS*)
@@ -3333,7 +3334,6 @@ then
                 then CCSHARED="-fPIC";
                 else CCSHARED="+z";
                 fi;;
-       Linux-android*) ;;
        Linux*|GNU*) CCSHARED="-fPIC";;
        Emscripten*|WASI*)
                AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
@@ -5888,11 +5888,13 @@ LDVERSION='$(VERSION)$(ABIFLAGS)'
 AC_MSG_RESULT([$LDVERSION])
 
 # On Android and Cygwin the shared libraries must be linked with libpython.
-AC_SUBST([LIBPYTHON])
+AC_SUBST([MODULE_DEPS_SHARED])
+AC_SUBST([MODULE_LDFLAGS])
+MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)'
+MODULE_LDFLAGS=''
 if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then
-  LIBPYTHON="-lpython${VERSION}${ABIFLAGS}"
-else
-  LIBPYTHON=''
+  MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)"
+  MODULE_LDFLAGS="\$(BLDLIBRARY)"
 fi