Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 132473

Summary: djvu-3.5.17: fix unresolved symbols in (--as-needed)
Product: Gentoo Linux Reporter: TGL <>
Component: Current packagesAssignee: Text-Markup Team (OBSOLETE) <text-markup+disabled>
Severity: normal CC: cems, dberkholz, flameeyes, genstef, ikelos
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 129413    
Attachments: djvu-3.5.17-libpthread.patch

Description TGL 2006-05-06 09:59:23 UTC
This library should be linked to libpthread (when USE has "qt" or "threads"):

% ldd -r /usr/lib/ =>  (0xffffe000) => /usr/lib/ (0xb7dea000) => /usr/lib/gcc/i686-pc-linux-gnu/4.1.0/ (0xb7d09000) => /lib/ (0xb7ce1000) => /lib/ (0xb7ba2000) => /usr/lib/gcc/i686-pc-linux-gnu/4.1.0/ (0xb7b96000)
        /lib/ (0x80000000)
undefined symbol: pthread_create        (/usr/lib/
undefined symbol: pthread_cancel        (/usr/lib/

Because of this, app-text/djvu won't compile with -Wl,--as-needed (fails while linking some example programs, because unresolved symbols are forbidden with this linker flag). But even without --as-needed, i think it can be an issue at runtime too (in the case a program linked to libdjvulibre but not to libpthread).

The cause of this problem is a bad interaction beetween an autoconf macro, libtool (1.5.22 here), and gcc (4.1 here). In short:
 - AC_PATH_PTHREAD (see config/acinclude.m4) detects that adding "-pthread" to CFLAGS is enough to compile with threads support.
 - when linking, libtool passes this flag to gcc. But it triggers "-nostdlib".
 - despite the "-pthread" option, gcc doesn't add "-lpthread" to the linker args when the "-nostdlib" option is in use. Thus libthread is never linked.

For a better explanation, see:

An (imho) acceptable workaround would be to force usage of "-lpthread". I will attach a patch for the ebuild which does that by setting some variables which overrides the behavior of the autoconf macros.
I don't know what could be an acceptable fix for upstream though.
Comment 1 TGL 2006-05-06 10:00:46 UTC
Created attachment 86292 [details, diff]
Comment 2 Diego Elio Pettenò (RETIRED) gentoo-dev 2006-05-07 20:46:31 UTC
Hmm no that won't work as that will break on *BSD where -lpthread is different by -pthread.

The autodetection has to be fixed instead.
Comment 3 TGL 2006-05-08 06:28:16 UTC
Note that my explanation of the workaround is not accurate: setting this variables doesn't really "force" anything, but just gives some values to try first. If "AC_TRY_LINK_FUNC(pthread_join)" fails with this values, then the macro will continue with the normal autodetection. I don't know whether it would have been the case or not on *BSD, but if it was, then this workaround would not have break things.

(In reply to comment #2)
> The autodetection has to be fixed instead.

But this macro works just fine. It comes from the autoconf library [1] (not the latest version, but that's minor differences), and has a well documented semantics which is well implemented. When it detects that CFLAGS=-pthread is enough on my system to link a threaded program, it is right, there's no bug.


The real problem here is libtool breaking semantics of -pthread: it is the one which forces -nostdlib for linking, while only doing half the job of readding the libs this flag will remove.

Now, i understand there's not much to do about it here, so i'm okay to try to find other better workarounds...

I will attach a first attempt patch, which makes possible to test combinations of flags/libs in the autodetection macro, and adds the "-pthread -lpthread" combination in the case of Linux/GCC. Sure, it should probably be completed with  other combinations for the other systems where libtool breaks things.
Comment 4 TGL 2006-05-08 06:30:34 UTC
Created attachment 86422 [details, diff]

A first attempt at patching the pthread macro. Should be applied in src_unpack, before running of aclocal and autoconf.
Comment 5 Carlos Eduardo Santos 2006-08-22 09:42:45 UTC
LD_PRELOAD=/usr/lib/ /usr/bin/firefox
Comment 6 Stefan Schweizer (RETIRED) gentoo-dev 2006-10-22 13:21:09 UTC
thanks, I committed this patch to Gentoo - can you please post this upstream also?