Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
git and -(l)pthread error
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Christian99
Veteran
Veteran


Joined: 28 May 2009
Posts: 1668

PostPosted: Fri Jun 06, 2014 6:58 pm    Post subject: git and -(l)pthread error Reply with quote

Since a while (I think beginning of this year and different versions some 1.9s and also 2.0), portage can't build git anymore without my help. The relevant error is this, I think:
Code:
x86_64-pc-linux-gnu-gcc  -O2 -pipe -march=native -fomit-frame-pointer -flto -Wl,-O1 -Wl,--as-needed -Wall -I. -DUSE_LIBPCRE  -DHAVE_PATHS_H -DHAVE_DEV_TTY -DXDL_FAST_HASH -DSHA1_HEADER='"block-sha1/sha1.h"'  -DNO_STRLCPY -DNO_MKSTEMPS -DSHELL_PATH='"/bin/sh"' -o git-imap-send -Wl,-O1 -Wl,--as-needed  imap-send.o \
        libgit.a xdiff/lib.a  -lpcre -lz -lpthread  -lssl  -lcrypto
utf8.o (symbol from plugin): warning: memset used with constant zero length parameter; this could be due to transposed parameters
utf8.o (symbol from plugin): warning: memset used with constant zero length parameter; this could be due to transposed parameters
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/libgcc_s.so: undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/libgcc_s.so: undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/libgcc_s.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status


it is easily fixed by changing the git main Makefile: there is a line
Code:
PTHREAD_LIBS = -lpthread
, when changed to
Code:
PTHREAD_LIBS = -pthread
the build runs flawless.

So, what's the problem there? why isn't the prober linker flag specified? In /usr/lib64/pkgconfig files, there is a mixture betwenn -lpthread and -pthread. might this be a possible cause? and if yes, how should i correct the .pc files best? or any other ideas?[/code]
Back to top
View user's profile Send private message
Christian99
Veteran
Veteran


Joined: 28 May 2009
Posts: 1668

PostPosted: Tue Jun 10, 2014 4:37 pm    Post subject: Reply with quote

*push*
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21602

PostPosted: Wed Jun 11, 2014 1:54 am    Post subject: Reply with quote

Does the problem go away if you do not use -flto? Using that flag defers to link time some operations that are otherwise done at compile time. If those operations are influenced by the presence of the -pthread flag, then deferring them to a run which does not specify it would change behavior.

Disclaimer: I have used LTO only briefly and have no specific knowledge that this is your problem or that removing LTO will fix it. On the other hand, you have not received any other advice and your post is no longer considered "unanswered" due to your bump.
Back to top
View user's profile Send private message
Christian99
Veteran
Veteran


Joined: 28 May 2009
Posts: 1668

PostPosted: Wed Jun 11, 2014 8:54 pm    Post subject: Reply with quote

yes, indeed, that helped. Well, I have seen quite a few errors related to lto, but never imagined this one was caused by that, too.

Well, Does anybody know what the difference is between -pthread and -lptread?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21602

PostPosted: Wed Jun 11, 2014 10:07 pm    Post subject: Reply with quote

Yes. The first enables various options required to support threading. The second only links to the threading library. For a regular link, this is enough. If you defer code generation to link time, it is not enough. Generally, when using lto, you should pass to the linker all the options that would be passed in a regular compilation phase. Passing -pthread may be sufficient to resolve this particular issue, but it would be better to pass all of CFLAGS or CXXFLAGS, as appropriate.
Back to top
View user's profile Send private message
Christian99
Veteran
Veteran


Joined: 28 May 2009
Posts: 1668

PostPosted: Wed Jun 11, 2014 10:18 pm    Post subject: Reply with quote

ok, thx for the help!
Back to top
View user's profile Send private message
IdRatherBeCompiling
n00b
n00b


Joined: 07 Jan 2015
Posts: 2

PostPosted: Wed Jan 07, 2015 10:22 pm    Post subject: Reply with quote

Hey guys, I just ran into this same problem.

The issue is that in the directory:

Code:
/var/tmp/portage/sys-apps/busybox-1.21.0/work/busybox-1.21.0/scripts/


you might need to alter the path a little depending on your busybox version. There is a script called trylink. And this is broken. Run:

Code:
emerge busybox


Control C it after it's started compiling (otherwise the directory wont exist). And copy the trylink script.

I changed the lines:

Code:
l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`


To:
Code:

l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`
l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`
l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`


Then I ran the one liner to copy my hacked trylink script to the busybox directory (necessary because emerge will nuke your file changes):

Code:
while [ 1 ]; do cp trylink /var/tmp/portage/sys-apps/busybox-1.21.0/work/busybox-1.21.0/scripts/; sleep 1; done


In one terminal and i reran:

Quote:
emerge system


In another. Because emerge system kept restarting from the beginning. And this solved my issue.

It's a filthy hack, but it got me past the problem.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21602

PostPosted: Thu Jan 08, 2015 12:37 am    Post subject: Reply with quote

That is a disgusting way to modify an existing build, in addition to being racy. If you absolutely must patch a file, do it from an overlay or via the Portage environment overrides, which will both solve the race and ensure that the same change is applied every time you rebuild the affected package.
Back to top
View user's profile Send private message
IdRatherBeCompiling
n00b
n00b


Joined: 07 Jan 2015
Posts: 2

PostPosted: Thu Jan 08, 2015 8:36 am    Post subject: Reply with quote

Yuuuuuuuup, I told you it wasn't pretty.

Ahh I googled for hours and I got nowhere, but i wasn't sure what I was looking for :)

I'll look into that.

Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum