Mailing List Archive

Mozilla, pthread libs, and Gentoo/FreeBSD.
Hello,

A bit of background first:
Currently firefox-2* and seamonkey-1.1.1 doesn't build on
Gentoo/FreeBSD. The main reason is that upstream (I think) has 'fixed'
how the pthread lib has to be linked, and now it needs -lc to link
successfully. This little issue is easily solvable the same way as it's
done by the FreeBSD ports patches [1].

The next issue (having the above one fixed) is that the resulting binary
(firefox or seamonkey's -bin) is linked against libc_r.so.6 *and*
libpthread.so.2 (which are two of the thread implementations available
in FreeBSD). Bah, the two libs linked isn't *exactly* the issue, as they
have all weak symbols this shouldn't be a problem, the exact issue
without mapping libpthread.so.2 to libc_r.so.6 by using libmap.conf[2]
is pretty different [3], and that's why I think upstream started using
libc_r instead of libpthread for FreeBSD (as in, this happens also when
firefox is only linked to libpthread using either -pthread or -lpthread).

While looking for a possible *correct* solution for this, I found that
the reason was that the mozilla (firefox/seamonkey) -bin is linked with
the arguments: "-lc_r -pthread" which causes both libraries (libc_r and
libphtread) to be linked to the resulting binary. Here we (and i bet
upstream wanted this too) only want libc_r.so.6 to be linked to the
final binary.

The origin of the "-pthread" addition to that commandline is NSPR_LIBS
which is filled by dev-libs/nspr "nspr-config --libs" output, which is
generated by nspr using the LDFLAGS make var.

This has an easy (yet incorrect imho) fix actually:
The easiest way to fix this would be to remove NSPR_LIBS from the
linkage of firefox/seamonkey-bin, which isn't even needed actually, as
the OS LDFLAGS (LIBS actually, naming the variables) are already handled
by Makefiles automagic, and this binary doesn't really 'need' the nspr
libraries at all, someone may think about a missing -lpthread or -lnspr4
on Linux, I have tested it without linking against NSPR_LIBS and firefox
starts perfectly fine, those who have --as-needed in their LDFLAGS, may
check which libraries is firefox-bin linked against and I'm sure they'll
see a quite reduced number of libraries than me.

Now the questions:
This makes me wonder if NSPR_LIBS is actually correct in this regard
(and, perhaps, a fix for nspr is needed and not mozilla?), since, afaik
on FreeBSD, the *decision* of which threading implementation has to be
used resides in the final executable, not in their libraries. These
guys [4] learned it the hard way, and they left nice references to good
information.

But this can also be just unintended overhead (or some sort of
preloading stuff?) to the firefox/seamonkey-bin binary? As it works
perfectly fine without having NSPR_LIBS in the commandline during the
linkage (even on Linux, again), being the "easy fix" actually correct also.

Or (I'm going all crazy here) it's something weird in the toolchain that
might be wrong? As far as I can see, and using [5] as a testcase,
vanilla FreeBSD does exactly the same thing (as we currently do) when
compiling a program using both -lc_r and -pthread (or '-lthr
-pthread/-lc_r -lthr'), always both libraries get linked. It also does
follow the order, as in if -lc_r or -lthr is used with -pthread, the
specified library (libc_r or libthr) it's the first in the list of
linked libs in the final binary (and also seems to be the only one used,
running that testcase on gdb shows that it dies on the function called
from the first library linked).

Another possibility: upstream forgot about nspr and that one should be
linked to (or just specify in the --libs output) libc_r.so as well? (I
haven't tested that yet)
Or maybe something else? Overall, how do you feel this problem should be
fixed/approached?

[1]http://www.freebsd.org/cgi/cvsweb.cgi/ports/www/firefox/files/patch-config-rules.mk
[2]http://www.freebsd.org/cgi/man.cgi?query=libmap.conf
[3]http://rafb.net/p/O6xRqU15.html
[4]https://forge.continuent.org/jira/browse/CAROB-117
[5]http://autoconf-archive.cryp.to/acx_pthread.html

--
Javier.
--
gentoo-dev@gentoo.org mailing list
Re: Mozilla, pthread libs, and Gentoo/FreeBSD. [ In reply to ]
Javier Villavicencio wrote:
> Hello,
>
> A bit of background first:
> Currently firefox-2* and seamonkey-1.1.1 doesn't build on
> Gentoo/FreeBSD. The main reason is that upstream (I think) has 'fixed'
> how the pthread lib has to be linked, and now it needs -lc to link
> successfully. This little issue is easily solvable the same way as it's
> done by the FreeBSD ports patches [1].
>
> The next issue (having the above one fixed) is that the resulting binary
> (firefox or seamonkey's -bin) is linked against libc_r.so.6 *and*
> libpthread.so.2 (which are two of the thread implementations available
> in FreeBSD).

No, actual firefox-bin is only linked with libpthread.so.2 (directly
with -lpthread)
# wget
ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/firefox.tbz
# mkdir firefox ; tar xjf firefox.tbz -C firefox
# scanelf -nR . | grep c_r

--
Timothy `Drizzt` Redaelli - http://dev.gentoo.org/~drizzt/
FreeSBIE Developer, Gentoo Developer, GUFI Staff
There are two major products that come out of Berkeley: LSD and UNIX.
We don't believe this to be a coincidence. -- Jeremy S. Anderson
Re: Mozilla, pthread libs, and Gentoo/FreeBSD. [ In reply to ]
Timothy Redaelli wrote:
> Javier Villavicencio wrote:
>> Hello,
>>
>> A bit of background first:
>> Currently firefox-2* and seamonkey-1.1.1 doesn't build on
>> Gentoo/FreeBSD. The main reason is that upstream (I think) has 'fixed'
>> how the pthread lib has to be linked, and now it needs -lc to link
>> successfully. This little issue is easily solvable the same way as it's
>> done by the FreeBSD ports patches [1].
>>
>> The next issue (having the above one fixed) is that the resulting binary
>> (firefox or seamonkey's -bin) is linked against libc_r.so.6 *and*
>> libpthread.so.2 (which are two of the thread implementations available
>> in FreeBSD).
>
> No, actual firefox-bin is only linked with libpthread.so.2 (directly
> with -lpthread)
> # wget
> ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/firefox.tbz
> # mkdir firefox ; tar xjf firefox.tbz -C firefox
> # scanelf -nR . | grep c_r
>
Nice to know, by the way i was talking about g/fbsd there not vanilla
freebsd. (I don't have an install yet, i was using a friend's server to
try some gcc tests).

BUT!!, why 'our' mozilla tries to link against libc_r.so.6 then? afaics
we do not touch the 'selection' of the threading library, and i haven't
seen anything besides the GECKO_PTHREADS_LIBS, and even if I pass that
variable (with -lpthread) to make our build still uses libc_r.so.6.
And why the only way to make it work is by remapping libpthread.so.2 to
libc_r.so.6, or (as I have experimented) by removing libpthread.so.2
from the linkage? Or is this also being done in some wrapper on vanilla
fbsd?

Besides this, what's your suggestion? make all mozilla ebuilds patch
accordingly to avoid libc_r and use libpthread alone?
--
gentoo-dev@gentoo.org mailing list
Re: Mozilla, pthread libs, and Gentoo/FreeBSD. [ In reply to ]
Javier Villavicencio wrote:
> Timothy Redaelli wrote:
>> Javier Villavicencio wrote:
>>> Hello,
>>>
>>> A bit of background first:
>>> Currently firefox-2* and seamonkey-1.1.1 doesn't build on
>>> Gentoo/FreeBSD. The main reason is that upstream (I think) has 'fixed'
>>> how the pthread lib has to be linked, and now it needs -lc to link
>>> successfully. This little issue is easily solvable the same way as it's
>>> done by the FreeBSD ports patches [1].
>>>
>>> The next issue (having the above one fixed) is that the resulting binary
>>> (firefox or seamonkey's -bin) is linked against libc_r.so.6 *and*
>>> libpthread.so.2 (which are two of the thread implementations available
>>> in FreeBSD).
>>
>> No, actual firefox-bin is only linked with libpthread.so.2 (directly
>> with -lpthread)
>> # wget
>> ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/firefox.tbz
>>
>> # mkdir firefox ; tar xjf firefox.tbz -C firefox
>> # scanelf -nR . | grep c_r
>>
> Nice to know, by the way i was talking about g/fbsd there not vanilla
> freebsd. (I don't have an install yet, i was using a friend's server to
> try some gcc tests).
>
> BUT!!, why 'our' mozilla tries to link against libc_r.so.6 then? afaics
> we do not touch the 'selection' of the threading library, and i haven't
> seen anything besides the GECKO_PTHREADS_LIBS, and even if I pass that
> variable (with -lpthread) to make our build still uses libc_r.so.6.
> And why the only way to make it work is by remapping libpthread.so.2 to
> libc_r.so.6, or (as I have experimented) by removing libpthread.so.2
> from the linkage? Or is this also being done in some wrapper on vanilla
> fbsd?
>
> Besides this, what's your suggestion? make all mozilla ebuilds patch
> accordingly to avoid libc_r and use libpthread alone?

Yeah, we should do such as FreeBSD
<snip>
@${REINPLACE_CMD} -e 's|-lc_r|${PTHREAD_LIBS}|g ; \
</snip>
http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/ports/www/mozilla/Makefile.common

--
Timothy `Drizzt` Redaelli - http://dev.gentoo.org/~drizzt/
FreeSBIE Developer, Gentoo Developer, GUFI Staff
There are two major products that come out of Berkeley: LSD and UNIX.
We don't believe this to be a coincidence. -- Jeremy S. Anderson
Re: Mozilla, pthread libs, and Gentoo/FreeBSD. [ In reply to ]
Timothy Redaelli wrote:
> Javier Villavicencio wrote:
>> Timothy Redaelli wrote:
>>> Javier Villavicencio wrote:
>>>> Hello,
>>>>
>>>> A bit of background first:
>>>> Currently firefox-2* and seamonkey-1.1.1 doesn't build on
>>>> Gentoo/FreeBSD. The main reason is that upstream (I think) has 'fixed'
>>>> how the pthread lib has to be linked, and now it needs -lc to link
>>>> successfully. This little issue is easily solvable the same way as it's
>>>> done by the FreeBSD ports patches [1].
>>>>
>>>> The next issue (having the above one fixed) is that the resulting binary
>>>> (firefox or seamonkey's -bin) is linked against libc_r.so.6 *and*
>>>> libpthread.so.2 (which are two of the thread implementations available
>>>> in FreeBSD).
>>> No, actual firefox-bin is only linked with libpthread.so.2 (directly
>>> with -lpthread)
>>> # wget
>>> ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/firefox.tbz
>>>
>>> # mkdir firefox ; tar xjf firefox.tbz -C firefox
>>> # scanelf -nR . | grep c_r
>>>
>> Nice to know, by the way i was talking about g/fbsd there not vanilla
>> freebsd. (I don't have an install yet, i was using a friend's server to
>> try some gcc tests).
>>
>> BUT!!, why 'our' mozilla tries to link against libc_r.so.6 then? afaics
>> we do not touch the 'selection' of the threading library, and i haven't
>> seen anything besides the GECKO_PTHREADS_LIBS, and even if I pass that
>> variable (with -lpthread) to make our build still uses libc_r.so.6.
>> And why the only way to make it work is by remapping libpthread.so.2 to
>> libc_r.so.6, or (as I have experimented) by removing libpthread.so.2
>> from the linkage? Or is this also being done in some wrapper on vanilla
>> fbsd?
>>
>> Besides this, what's your suggestion? make all mozilla ebuilds patch
>> accordingly to avoid libc_r and use libpthread alone?
>
> Yeah, we should do such as FreeBSD
> <snip>
> @${REINPLACE_CMD} -e 's|-lc_r|${PTHREAD_LIBS}|g ; \
> </snip>
> http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/ports/www/mozilla/Makefile.common
>

Nice finding. I was just looking where -lc_r was added and it's a check
for gethostbyname_r in the configure script, it uses:
AC_CHECK_LIB(c_r, gethostbyname_r)
instead of the more correct
AC_SEARCH_LIBS([gethostbyname_r], [c_r])
since gethostbyname_r is already in the libc, it will always add -lc_r
even if it's not needed for gethostbyname_r.

Now that libc_r.so.6 is away, all that is left is to make it use
PTHREAD_LIBS or default to -lpthread. /me wonders why there isn't a
normal pthread check here.

Thanks!.

Javier.
--
gentoo-dev@gentoo.org mailing list