python-config --ldflags must not contain LINKFORSHARED ("-Xlinker -export-dynamic" on Linux) #80689
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
assignee = None closed_at = <Date 2019-04-16.13:04:17.579> created_at = <Date 2019-04-02.15:00:19.982> labels = ['3.8', 'build', '3.7'] title = 'python-config --ldflags must not contain LINKFORSHARED ("-Xlinker -export-dynamic" on Linux)' updated_at = <Date 2019-04-16.13:04:17.574> user = 'https://github.com/vstinner'
activity = <Date 2019-04-16.13:04:17.574> actor = 'vstinner' assignee = 'none' closed = True closed_date = <Date 2019-04-16.13:04:17.579> closer = 'vstinner' components = ['Build'] creation = <Date 2019-04-02.15:00:19.982> creator = 'vstinner' dependencies =  files =  hgrepos =  issue_num = 36508 keywords = ['patch'] message_count = 6.0 messages = ['339341', '339344', '339345', '339771', '340339', '340340'] nosy_count = 4.0 nosy_names = ['doko', 'pitrou', 'vstinner', 'ned.deily'] pr_nums = ['12661', '12748'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue36508' versions = ['Python 3.7', 'Python 3.8']
The text was updated successfully, but these errors were encountered:
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:
The value of the variable changed on Linux with:
Extract of the configure.in change:
if test -z "$LINKFORSHARED"
../python: config.o $(MYLIBS) Makefile
(*) The python-config script was created as a Python script by:
The following commit modified Misc/python-config.in to add LINKFORSHARED to python-config --ldflags:
+ 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):
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:
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"
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.