Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f5e3f0

Browse filesBrowse files
authored
gh-111225: Link extension modules against libpython on Android (#115780)
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`.
1 parent 113687a commit 7f5e3f0
Copy full SHA for 7f5e3f0

File tree

Expand file treeCollapse file tree

5 files changed

+19
-25
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+19
-25
lines changed

‎Makefile.pre.in

Copy file name to clipboardExpand all lines: Makefile.pre.in
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ AR= @AR@
4141
READELF= @READELF@
4242
SOABI= @SOABI@
4343
LDVERSION= @LDVERSION@
44-
LIBPYTHON= @LIBPYTHON@
44+
MODULE_LDFLAGS=@MODULE_LDFLAGS@
4545
GITVERSION= @GITVERSION@
4646
GITTAG= @GITTAG@
4747
GITBRANCH= @GITBRANCH@
@@ -2917,7 +2917,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
29172917

29182918
# force rebuild when header file or module build flavor (static/shared) is changed
29192919
MODULE_DEPS_STATIC=Modules/config.c
2920-
MODULE_DEPS_SHARED=$(MODULE_DEPS_STATIC) $(EXPORTSYMS)
2920+
MODULE_DEPS_SHARED=@MODULE_DEPS_SHARED@
29212921

29222922
MODULE__CURSES_DEPS=$(srcdir)/Include/py_curses.h
29232923
MODULE__CURSES_PANEL_DEPS=$(srcdir)/Include/py_curses.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Link extension modules against libpython on Android.

‎Modules/makesetup

Copy file name to clipboardExpand all lines: Modules/makesetup
+1-13Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ esac
8787
NL='\
8888
'
8989

90-
# Setup to link with extra libraries when making shared extensions.
91-
# Currently, only Cygwin needs this baggage.
92-
case `uname -s` in
93-
CYGWIN*) if test $libdir = .
94-
then
95-
ExtraLibDir=.
96-
else
97-
ExtraLibDir='$(LIBPL)'
98-
fi
99-
ExtraLibs="-L$ExtraLibDir -lpython\$(LDVERSION)";;
100-
esac
101-
10290
# Main loop
10391
for i in ${*-Setup}
10492
do
@@ -286,7 +274,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
286274
;;
287275
esac
288276
rule="$file: $objs"
289-
rule="$rule; \$(BLDSHARED) $objs $libs $ExtraLibs -o $file"
277+
rule="$rule; \$(BLDSHARED) $objs $libs \$(MODULE_LDFLAGS) -o $file"
290278
echo "$rule" >>$rulesf
291279
done
292280
done

‎configure

Copy file name to clipboardExpand all lines: configure
+8-5Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac

Copy file name to clipboardExpand all lines: configure.ac
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ if test $enable_shared = "yes"; then
13601360
case $ac_sys_system in
13611361
CYGWIN*)
13621362
LDLIBRARY='libpython$(LDVERSION).dll.a'
1363+
BLDLIBRARY='-L. -lpython$(LDVERSION)'
13631364
DLLLIBRARY='libpython$(LDVERSION).dll'
13641365
;;
13651366
SunOS*)
@@ -3333,7 +3334,6 @@ then
33333334
then CCSHARED="-fPIC";
33343335
else CCSHARED="+z";
33353336
fi;;
3336-
Linux-android*) ;;
33373337
Linux*|GNU*) CCSHARED="-fPIC";;
33383338
Emscripten*|WASI*)
33393339
AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [
@@ -5888,11 +5888,13 @@ LDVERSION='$(VERSION)$(ABIFLAGS)'
58885888
AC_MSG_RESULT([$LDVERSION])
58895889

58905890
# On Android and Cygwin the shared libraries must be linked with libpython.
5891-
AC_SUBST([LIBPYTHON])
5891+
AC_SUBST([MODULE_DEPS_SHARED])
5892+
AC_SUBST([MODULE_LDFLAGS])
5893+
MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)'
5894+
MODULE_LDFLAGS=''
58925895
if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then
5893-
LIBPYTHON="-lpython${VERSION}${ABIFLAGS}"
5894-
else
5895-
LIBPYTHON=''
5896+
MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)"
5897+
MODULE_LDFLAGS="\$(BLDLIBRARY)"
58965898
fi
58975899

58985900

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.