Bug 951781

Summary: guile-1.8 linked with pthreads but no -lpthread in pkg-config --libs
Product: [Fedora] Fedora Reporter: Sebastian Freundt <devel>
Component: guileAssignee: Miroslav Lichvar <mlichvar>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 18CC: jsynacek, mlichvar
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-04-19 09:22:02 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Sebastian Freundt 2013-04-13 05:42:02 UTC
User-Agent:       Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0
Build Identifier: 

libguile.so is evidently linked with libpthread.so.0 (as can be verified with ldd)

However,

  pkg-config --libs guile-1.8

fails to provide the -lpthread in linker flags.  (the -pthread CFLAG is there however).

Any code relying on the information provided by pkg-config will fail, e.g.

With any trivial test file test.c try:
gcc -std=c11 -O3 -g -c -Wall test.c -o test.o $(pkg-config --cflags guile-1.8) 
gcc -std=c11 -O3 -g -Wall test.o -o test $(pkg-config --libs guile-1.8)
/bin/ld: test.o: undefined reference to symbol 'pthread_getspecific@@GLIBC_2.2.5'
/bin/ld: note: 'pthread_getspecific@@GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status


Reproducible: Always

Comment 1 Jan Synacek 2013-04-16 06:42:05 UTC
Fedora's linker does not use indirect linking (https://fedoraproject.org/wiki/UnderstandingDSOLinkChange), so you have to provide -lpthread yourself. 

However, I'm not sure if this should be 'fixed' or not, I'm currently discussing it with upstream.

Comment 2 Jan Synacek 2013-04-19 09:22:02 UTC
As stated before, you should provide the correct flags yourself, as indirect linking is not supported. Closing this bug.

Comment 3 Sebastian Freundt 2013-04-19 09:26:19 UTC
Yep.  I guess I just won't support Fedora then.  This is inherently broken.  If pkg-config can't tell me what to link with, who else can?

Thanks for the effort though.

Comment 4 Jan Synacek 2013-04-19 12:43:56 UTC
> If pkg-config can't tell me what to link with, who else can?

pkg-config is telling you what you asked for - the guile linker flags. It won't tell you what you need to link from what you use in your source code.

However, you can tell gcc to indirectly include NEEDED symbols from the Dynamic section, just add -Wl,--copy-dt-needed-entries.

Comment 5 Sebastian Freundt 2013-04-19 13:40:23 UTC
That's wrong, pkg-config is supposed to tell me what *I* need to add to *my* linker line when I want to link to libguile.  And it just doesn't do that.

The upstream guile doesn't have that problem as it won't be linked with pthread support by default.  That's just another Fedora patch.  However, upstream makes the mistake of not mentioning -lpthread in their .pc when it was configured with pthread support and hence does need to be linked with -lpthread.

I will take this to upstream directly.  Adding more and more kludges to my linker lines is definitely not the way to go.  I want to write lean and portable code.

Comment 6 Jan Synacek 2013-04-22 06:05:23 UTC
I already started the discussion: http://lists.gnu.org/archive/html/guile-devel/2013-04/msg00165.html