-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python-config --ldflags must not contain LINKFORSHARED ("-Xlinker -export-dynamic" on Linux) #80689
Comments
python-config --ldflags must not contain LINKFORSHARED. Attached PR modifies python-config --ldflags to no longer include LINKFORSHARED. This similar change was already made on macOS: see bpo-14197. -- Python build system uses a LINKFORSHARED variable, extract of configure.ac: # LINKFORSHARED are the flags passed to the $(CC) command that links This variable is set to "-Xlinker -export-dynamic" on Linux. Extract of ld manual page for --export-dynamic option: If you do not use either of these options (or use the If you use "dlopen" to load a dynamic object which needs to You can also use the dynamic list to control what symbols Note that this option is specific to ELF targeted ports. PE Both configure.ac and ld manual page mention an "executable", whereas LINKFORSHARED is currently exported in python-config --ldflags. Example on Fedora 29: $ python3-config --ldflags
-L/usr/lib64 -lpython3.7m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic The "-export-dynamic" flag causes non-obvious dynamic linking bug like the following bug in Samba which embeds Python:
-- History of the LINKFORSHARED variable. (*) Python build system uses a LINKFORSHARED variable since this commit: commit 7cc5abd
The value of the variable changed on Linux with: commit b65a48e (HEAD)
Extract of the configure.in change: if test -z "$LINKFORSHARED" The variable was only used to build the "python" executable. Extract of Modules/Makefile.in (at commit 7cc5abd): ../python: config.o $(MYLIBS) Makefile (*) The python-config script was created as a Python script by: commit c90b17e
The following commit modified Misc/python-config.in to add LINKFORSHARED to python-config --ldflags: commit a70f349
Extract: + elif opt in ('--libs', '--ldflags'): The following commit modified Misc/python-config.in to not add LINKFORSHARED into "libs" when built on macOS (if PYTHONFRAMEWORK is defined): commit ecd4e9d
diff --git a/Misc/python-config.in b/Misc/python-config.in
index 1d4a81d850..79f0bb14c1 100644
--- a/Misc/python-config.in
+++ b/Misc/python-config.in
@@ -52,7 +52,8 @@ for opt in opt_flags:
if opt == '--ldflags':
if not getvar('Py_ENABLE_SHARED'):
libs.insert(0, '-L' + getvar('LIBPL'))
- libs.extend(getvar('LINKFORSHARED').split())
+ if not getvar('PYTHONFRAMEWORK'):
+ libs.extend(getvar('LINKFORSHARED').split())
print(' '.join(libs))
(*) A shell version of python-config has been added by: commit 8742119
Extract of Misc/python-config.sh.in at this commit:
|
I'm a little bit scared by the idea of backporting such change in Python 2.7 and 3.7 stable branches, even if I think that it's a correct bugfix. I'm scared by the number of platforms, I don't know all these linker flags and I am not able to test all combinations: AC_MSG_RESULT($CCSHARED)
# LINKFORSHARED are the flags passed to the $(CC) command that links
# the python executable -- this is only needed for a few systems
AC_MSG_CHECKING(LINKFORSHARED)
if test -z "$LINKFORSHARED"
then
case $ac_sys_system/$ac_sys_release in
AIX*) LINKFORSHARED='-Wl,-bE:Modules/python.exp -lld';;
hp*|HP*)
LINKFORSHARED="-Wl,-E -Wl,+s";;
# LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
Linux-android*) LINKFORSHARED="-pie -Xlinker -export-dynamic";;
Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
# -u libsys_s pulls in all symbols in libsys
Darwin/*)
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
fi |
See also bpo-10112: "Use -Wl,--dynamic-list=x.list, not -Xlinker -export-dynamic". |
The bug is fixed in 3.7 and master (future 3.8) branches. I prefer to leave 2.7 unchanged. I close the issue. Python 2.7 is affected as well, but I'm really scared to touch the build system of Python 2.7 which is very stable. Even for Python 3.7, I wasn't fully comfortable to merge my fix. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: