Skip to content
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 gives broken output when statically linking Python with --as-needed #61969

Open
MaxCantor mannequin opened this issue Apr 16, 2013 · 2 comments
Open
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error

Comments

@MaxCantor
Copy link
Mannequin

MaxCantor mannequin commented Apr 16, 2013

BPO 17769
Nosy @zware

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:

assignee = None
closed_at = None
created_at = <Date 2013-04-16.20:22:14.834>
labels = ['type-bug', 'build']
title = 'python-config --ldflags gives broken output when statically linking Python with --as-needed'
updated_at = <Date 2019-03-15.22:09:56.167>
user = 'https://bugs.python.org/MaxCantor'

bugs.python.org fields:

activity = <Date 2019-03-15.22:09:56.167>
actor = 'BreamoreBoy'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Build', 'Cross-Build']
creation = <Date 2013-04-16.20:22:14.834>
creator = 'Max.Cantor'
dependencies = []
files = []
hgrepos = []
issue_num = 17769
keywords = []
message_count = 2.0
messages = ['187121', '224655']
nosy_count = 2.0
nosy_names = ['zach.ware', 'Max.Cantor']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue17769'
versions = ['Python 2.7']

@MaxCantor
Copy link
Mannequin Author

MaxCantor mannequin commented Apr 16, 2013

On certain Linux distributions such as Ubuntu, the linker is invoked by default with --as-needed, which has an undesireable side effect when linking static libraries: it is bad at detecting required symbols, and the order of libraries on the command line become significant.

Right now, on my Ubuntu 12.10 system with a custom 32-bit version of Python, I get the following command output:

mcantor@hpmongo:~$ /opt/pym32/bin/python-config --ldflags
-L/opt/pym32/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

When linking a project with those flags, I get the following error:

/usr/bin/ld: /opt/pym32/lib/python2.7/config/libpython2.7.a(dynload_shlib.o): undefined reference to symbol 'dlopen@@GLIBC_2.1'
/usr/bin/ld: note: 'dlopen@@GLIBC_2.1' is defined in DSO /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../i386-linux-gnu/libdl.so so try adding it to the linker command line
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../i386-linux-gnu/libdl.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

To resolve the error, I moved -ldl and -lutil *AFTER* -lpython2.7, so the relevant chunk of my gcc command line looked like this:

-L/opt/pym32/lib/python2.7/config -lpthread -lm -lpython2.7 -ldl -lutil -Xlinker -export-dynamic

I have no idea why --as-needed has such an unpleasant side effect when static libraries are being used, and it's arguable from my perspective that this behavior is the real bug. However it's equally likely that there's a good reason for that behavior, like it causes a slowdown during leap-years on Apple IIs or something. So here I am. python-config ought to respect the quirks of --as-needed when outputting its ldflags.

@MaxCantor MaxCantor mannequin added build The build process and cross-build type-bug An unexpected behavior, bug, or error labels Apr 16, 2013
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Aug 3, 2014

@max sorry about the delay in giving you a response. Can somebody please pick this up, I can't find on the experts list who to put on the nosy list for build issues.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants