After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761444 - undefined reference to `pthread_sigmask'
undefined reference to `pthread_sigmask'
Status: RESOLVED NOTGNOME
Product: vte
Classification: Core
Component: general
0.43.x
Other Linux
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-02-02 04:21 UTC by darkxst
Modified: 2016-02-13 19:22 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description darkxst 2016-02-02 04:21:45 UTC
Build fails on Ubuntu 16.04, with output below. Maybe related to Ubuntu using --as-need when linking?

libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/5/crtbeginS.o  .libs/libvte_2_91_la-caps.o .libs/libvte_2_91_la-debug.o .libs/libvte_2_91_la-iso2022.o .libs/libvte_2_91_la-keymap.o .libs/libvte_2_91_la-matcher.o .libs/libvte_2_91_la-pty.o .libs/libvte_2_91_la-ring.o .libs/libvte_2_91_la-table.o .libs/libvte_2_91_la-vte.o .libs/libvte_2_91_la-vteaccess.o .libs/libvte_2_91_la-vteconv.o .libs/libvte_2_91_la-vtedraw.o .libs/libvte_2_91_la-vtegtk.o .libs/libvte_2_91_la-vteregex.o .libs/libvte_2_91_la-vterowdata.o .libs/libvte_2_91_la-vteseq.o .libs/libvte_2_91_la-vtestream.o .libs/libvte_2_91_la-vtetree.o .libs/libvte_2_91_la-vtetypes.o .libs/libvte_2_91_la-vteunistr.o .libs/libvte_2_91_la-vteutils.o .libs/libvte_2_91_la-marshal.o .libs/libvte_2_91_la-vteresources.o .libs/libvte_2_91_la-vtetypebuiltins.o   -Wl,--as-needed -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lz -lgnutls -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/5/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crtn.o  -pthread -O2 -O2 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z -Wl,relro -Wl,-z -Wl,defs -Wl,-O1   -pthread -Wl,-soname -Wl,libvte-2.91.so.0 -o .libs/libvte-2.91.so.0.4302.0
.libs/libvte_2_91_la-pty.o: In function `vte_pty_child_setup':
/build/vte2.91-MZPSlE/vte2.91-0.43.2/./src/pty.cc:132: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
Makefile:1276: recipe for target 'libvte-2.91.la' failed
make[1]: *** [libvte-2.91.la] Error 1
make[1]: Leaving directory '/build/vte2.91-MZPSlE/vte2.91-0.43.2/debian/build/main/src'
Makefile:1204: recipe for target 'all' failed
make: *** [all] Error 2
Comment 1 Christian Persch 2016-02-02 16:09:25 UTC
Works for me, and works on build.g.o. I don't see how it could fail, given that the paste above shows that -pthread is part of the link command.
Comment 2 darkxst 2016-02-02 23:52:45 UTC
Seems to be triggered by the "-Wl,-z -Wl defs" link flag, which doesnt seem right, maybe its a toolchain bug
Comment 3 Egmont Koblinger 2016-02-11 19:58:02 UTC
Does it happen only when compiled from git (./autogen.sh run locally) or also from tarball?

How about 0.42.x?
Comment 4 Christian Persch 2016-02-11 20:01:01 UTC
The 0-42 branch doesn't use that function. (The call was introduced during the pty-cleanup work.)
Comment 5 Olav Vitters 2016-02-11 21:17:35 UTC
http://pkgsubmit.mageia.org/uploads/failure/cauldron/core/release/20160129160146.ovitters.valstar.10797/log/vte3-0.43.2-1.mga6/build.0.20160129160205.log

This is likely due to --as-needed usage. See above for Mageia build failure using 0.43.2 tarball.
Comment 6 darkxst 2016-02-12 07:02:27 UTC
Its caused by linking with "-Wl,-z, defs" not --as-needed.

However I tried with a very simple pthread C program and that linked fine with both "-Wl,-z, defs" and --as-needed enabled so long as -pthread is supplied.

my testing was with the 0.43.2 tarball, I can't build git master at the moment due to unrelated vala error about new api needing 0.44
Comment 7 Andreas Henriksson 2016-02-12 10:23:21 UTC
Adding "-lpthread" to the linker command will solve this, but given pthread being "special" this is not something you want to do unconditionally for portability reasons or so....

There seems to be a plethora of ways of how to handle this in different projects.

I've tested borrowing the following from netatalk and verified it fixes the build here:

AC_SEARCH_LIBS(pthread_sigmask, pthread,,
               [AC_MSG_ERROR([cannot find pthread_sigmask in libc or libpthread])])
if test x"$ac_cv_search_pthread_sigmask" != x"none required" ; then
   PTHREAD_LIBS=$ac_cv_search_pthread_sigmask
fi
AC_SUBST(PTHREAD_LIBS)

LIBS="$LIBS $PTHREAD_LIBS"


See http://sources.debian.net/src/netatalk/2.2.5-1/configure.ac/?hl=88#L88

You might also want to check out AX_PTHREAD, but watch out for pitfalls as mentioned in mesa: 

"AX_PTHREADS leaves PTHREAD_LIBS empty for gcc..."

See http://sources.debian.net/src/mesa/11.1.2-1/configure.ac/?hl=713#L713
Comment 8 Andreas Henriksson 2016-02-12 10:31:16 UTC
http://www.gnu.org/software/autoconf-archive/ax_pthread.html
Comment 9 Christian Persch 2016-02-12 11:43:42 UTC
The link line as shown in comment 0 already contains '-pthread' which according to g++ docs should do the right thing: "Adds support for multithreading with the "pthreads" library.  This option sets flags for both the preprocessor and linker."
Comment 10 Andreas Henriksson 2016-02-12 14:14:47 UTC
(In reply to Christian Persch from comment #9)
> The link line as shown in comment 0 already contains '-pthread' which
> according to g++ docs should do the right thing: "Adds support for
> multithreading with the "pthreads" library.  This option sets flags for both
> the preprocessor and linker."

Yes, it does contain -pthread, but not -lpthread (which both are confusingly similar). "Should" do the right thing, sure maybe but apparently it doesn't and just about every other project in the universe seems to decide to fix this issue in similar ways to what I pointed out. It's up to you ofcourse.... it was just a suggestion. Trying to be helpful pointing out an actual working solution (that lets us still verify there are no unresolved symbols). Dropping "-Wl,-z, defs" is not a solution I consider a good one, but that's my opinion and you're free to ignore it.
Comment 11 Christian Persch 2016-02-12 17:03:07 UTC
You could do a build without extra flags, and one with your zdefs flag, and compare the build log and config.log files to see what exactly changes.
Comment 12 darkxst 2016-02-13 01:28:06 UTC
'-pthread' should cause '-lpthread' to be passed to the linker, however since libtool is calling 'g++ -nostdlib', that actually takes priority and causes the '-lpthread' to be stripped.

This seems to be a long standing issue that has never been dealt with upstream, so I guess explicitly setting '-lpthread' is the correct way to go.

For example there was this patch (but doesnt ever seem to have been accepted)
http://permalink.gmane.org/gmane.comp.gnu.libtool.patches/11704
Comment 13 Christian Persch 2016-02-13 12:49:54 UTC
I see. NOTGNOME since it's a libtool problem, and NOTABUG since it's caused by adding zdefs to the LD flags, so you can just as well add -lpthread too.
Comment 14 Andreas Henriksson 2016-02-13 15:19:41 UTC
(In reply to Christian Persch from comment #13)
> I see. NOTGNOME since it's a libtool problem, and NOTABUG since it's caused
> by adding zdefs to the LD flags, so you can just as well add -lpthread too.

Just have to say (again) since everyone seems to misunderstand what -Wl,-z,defs does: the problem is not *caused* by this flag. That flag only makes it possible to *detect* underlinking issues like this one. Adding this flag is a way to detect, at link-time,  issues instead of experience them at runtime! (Which in this particular case might not be a big practical problem, but anyway if we drop it there might creep in other underlinking issues which is actually practical problems. But ofcourse we can handle all of this downstream if you prefer us not to bother you about this.)

(Also, apparently libtool people seems to disagree with you about this being a libtool issue.)
Comment 15 Christian Persch 2016-02-13 19:02:27 UTC
I've removed libtool use from git master, please check if the problem still occurs.
Comment 16 Christian Persch 2016-02-13 19:22:09 UTC
Actually that didn't work out, so I've reverted that for now.