Bug 101071

Summary: compiling glsl fails with undefined reference to `pthread_create'
Product: Mesa Reporter: warpme
Component: OtherAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium CC: virtuousfox
Version: 17.1   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: configure.ac: add -pthread to PTHREAD_LIBS

Description warpme 2017-05-17 09:52:05 UTC
I’m trying cross-compile mesa 17.1 on system with llvm3.8.1, gcc5.3.0 and glibc2.17

I’m receiving following error:

libtool: link: x86_64-minimyth-linux-gnu-ranlib glsl/.libs/libstandalone.a
libtool: link: rm -fr glsl/.libs/libstandalone.lax glsl/.libs/libstandalone.lax
libtool: link: ( cd "glsl/.libs" && rm -f "libstandalone.la" && ln -s "../libstandalone.la" "libstandalone.la" )
//home/piotro/minimyth-dev/images/build/bin/bash ../../libtool  --tag=CXX   --mode=link x86_64-minimyth-linux-gnu-g++ -fvisibility=hidden -Werror=pointer-arith -Werror=vla -ffat-lto-objects -lpthread -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -Wall -fno-math-errno -fno-trapping-math   -Wl,--as-needed -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -o glsl_compiler glsl/main.o glsl/libstandalone.la
libtool: link: x86_64-minimyth-linux-gnu-g++ -fvisibility=hidden -Werror=pointer-arith -Werror=vla -ffat-lto-objects -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -Wall -fno-math-errno -fno-trapping-math -Wl,--as-needed -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -o glsl_compiler glsl/main.o glsl/.libs/libstandalone.a -lz -lpthread
/home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/5.3.0/libstdc++.so: undefined reference to `pthread_create'
/home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/5.3.0/libstdc++.so: undefined reference to `pthread_once'
/home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/5.3.0/libstdc++.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[5]: *** [glsl_compiler] Error 1

exactly the same cross-compile environment and settings cross-compile 17.0.6 no problem.
Comment 1 Emil Velikov 2017-05-17 12:24:08 UTC
Seems like the cross-compiled libstdc++.so is missing the pthread symbol. Something like the following will help you check if that's the case.

1) setup your platforms so the custom DSO's are detected. For example
$export LD_LIBRARY_PATH=/home/piotro/minimyth-dev/images/build/usr/lib/...
2) using the correct ldd issue:
$ldd -r /home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/5.3.0/libstdc++.so

If you see "undefined symbol: ..." then something's funny in your setup.

Can you check with the libstdc++.so authors that they use "-no-undefined -Wl,--no-undefined" to the LDFLAGS. It will flag issues as the binary is linked.
Comment 2 warpme 2017-05-17 13:41:01 UTC
Emil,
For custom DSO:
 
[piotro@minimyth-dev ~]$ export LD_LIBRARY_PATH=/home/piotro/minimyth-dev/images/build/usr/lib/
[piotro@minimyth-dev ~]$ env
XDG_SESSION_ID=c7
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=192.168.1.254 41500 22
SSH_TTY=/dev/pts/0
USER=piotro
LD_LIBRARY_PATH=/home/piotro/minimyth-dev/images/build/usr/lib/
MAIL=/var/spool/mail/piotro
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
HG=/usr/bin/hg
PWD=/home/piotro
LANG=en_US.UTF8
SHLVL=1
HOME=/home/piotro
LOGNAME=piotro
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus
SSH_CONNECTION=192.168.1.254 41500 192.168.1.190 22
XDG_RUNTIME_DIR=/run/user/1001
_=/usr/bin/env
[piotro@minimyth-dev ~]$ ldd -r /home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/5.3.0/libstdc++.so
        linux-vdso.so.1 (0x00007ffee99fd000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007faef68e6000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007faef6542000)
        /usr/lib64/ld-linux-x86-64.so.2 (0x000055db774d7000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007faef632b000)
[piotro@minimyth-dev ~]$

for libstdc++ I need to look as it...
Comment 3 warpme 2017-05-18 12:26:52 UTC
Emil,

BTW, You wrote:

Can you check with the libstdc++.so authors that they use "-no-undefined -Wl,--no-undefined" to the LDFLAGS. It will flag issues as the binary is linked.


why then I hasn't any issues like this with last 10.0 ... 17.0 mesa versions?
Comment 4 Emil Velikov 2017-05-18 13:19:36 UTC
> [piotro@minimyth-dev ~]$ ldd -r
> /home/piotro/minimyth-dev/images/build/usr/lib/gcc/x86_64-minimyth-linux-gnu/
> 5.3.0/libstdc++.so
>         linux-vdso.so.1 (0x00007ffee99fd000)
>         libm.so.6 => /usr/lib/libm.so.6 (0x00007faef68e6000)
>         libc.so.6 => /usr/lib/libc.so.6 (0x00007faef6542000)
>         /usr/lib64/ld-linux-x86-64.so.2 (0x000055db774d7000)
>         libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007faef632b000)

Right, so the libstdc++.so is fine and the link error is misleading.

> why then I hasn't any issues like this with last 10.0 ... 17.0 mesa versions?

Your guess is as good as mine. As you can see in the command line we explicitly request linkage against libpthread.so (the -lpthread bit), yet GCC fails to do so.

Couple of things to check:
 - does the minimyth environment have a libpthread.so library?
 - can you trace that correct one is attempted/used in the process?
Comment 5 warpme 2017-05-18 17:23:51 UTC
Emil,
One thing:

in configure I see:

checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... no

why then build process asking for libpthread functions?

there is definitely something different in 17.1 as 17.0.6 builds OK in exactly this environment.

If there is unmet, new requirement for 17.1 which is not needed for 17.0.6 - then issue is that 17.1 configure process is not catching this missing dependency.
Comment 6 Emil Velikov 2017-05-19 14:37:07 UTC
(In reply to warpme from comment #5)
> Emil,
> One thing:
> 
> in configure I see:
> 
> checking for the pthreads library -lpthreads... no
> checking whether pthreads work without any flags... yes
> checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
> checking if more special flags are required for pthreads... no
> checking for PTHREAD_PRIO_INHERIT... no
> 
> why then build process asking for libpthread functions?
> 
There's a comment in configure.ac about it (grep for -lpthread). The gist is that we need it (or an equivalent really) in the .pc files.

> there is definitely something different in 17.1 as 17.0.6 builds OK in
> exactly this environment.
> 
> If there is unmet, new requirement for 17.1 which is not needed for 17.0.6 -
> then issue is that 17.1 configure process is not catching this missing
> dependency.

It's quite possible - not arguing against that. Although I would suspect something rather unique to your setup.

Only two ideas come to mind - a) ones mentioned in comment 4 anb b) bisecting (we have ~3000 commits so that's ~13 steps).
Comment 7 warpme 2017-05-23 13:33:06 UTC
Emil,

Pls find output from bisecting:

[piotro@minimyth-dev Mesa]$
[piotro@minimyth-dev git-src]$ git bisect good
Bisecting: 1498 revisions left to test after this (roughly 11 steps)
[920ab07566da8bbc95e12ed36da0c76f342066d9] i965: Delete unused last_ring local.
[piotro@minimyth-dev git-src]$ git bisect good
Bisecting: 749 revisions left to test after this (roughly 10 steps)
[bb2e05885d476702f1fade95ec32eb5eb6079374] vdpau: fix a maybe-uninitialized warning
[piotro@minimyth-dev git-src]$ git bisect good
Bisecting: 374 revisions left to test after this (roughly 9 steps)
[51d6641700146fc22c66b96ad5841268b1c28468] radeonsi: re-use 'desc' in si_set_shader_image()
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 187 revisions left to test after this (roughly 8 steps)
[c6f69eea6ac549fc2ffa46944de4dd82c9b53329] anv/pipeline: Properly handle unset gl_Layer and gl_ViewportIndex
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 93 revisions left to test after this (roughly 7 steps)
[f2a4d881fe94512f7600ec33622af58b8ca06fff] nvc0/ir: also do ConstantFolding for FMA
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 46 revisions left to test after this (roughly 6 steps)
[2936f5c37eba10d68ac27cd7b77a633a127a1688] glsl: use -O1 optimization for builtin_functions.cpp with MinGW
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 22 revisions left to test after this (roughly 5 steps)
[2e70de7d2f703cf81cbe114a99f6328045143c26] mesa/vbo: remove redundant _mesa_is_bufferobj() calls
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 11 revisions left to test after this (roughly 4 steps)
[e5c6c421c4a6a3f7dc3aaefb617428affffdf008] vc4: Fix indenting in vc4_screen_get_param()
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 5 revisions left to test after this (roughly 3 steps)
[3df993e1a22decc4732faf08a4d358cd90548e52] intel: automake: move INTEL_CFLAGS as applicable
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 2 revisions left to test after this (roughly 1 step)
[681adbc18ca934566a42e952fe20e26c39a2d0d1] ddebug: implement clear_texture
[piotro@minimyth-dev git-src]$ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[83d3e6fbff61f817f35820bfd4066a92ff104115] radeonsi: fix an unused-variable warning in a release build
[piotro@minimyth-dev git-src]$ git bisect bad
83d3e6fbff61f817f35820bfd4066a92ff104115 is the first bad commit
commit 83d3e6fbff61f817f35820bfd4066a92ff104115
Author: Marek Olšák <marek.olsak@amd.com>
Date:   Thu Mar 30 17:21:47 2017 +0200

    radeonsi: fix an unused-variable warning in a release build

:040000 040000 c65281e3d79aac6a144315eb4570b5e243192cf2 f29883989f567f01a17189f9367531385525cc02 M      src
[piotro@minimyth-dev git-src]$
Comment 8 warpme 2017-05-23 13:45:42 UTC
hmm,

I just revert this commit on current 17.1 and it....fails with OP problem.
how it that?
Comment 9 Emil Velikov 2017-05-30 13:45:12 UTC
(In reply to warpme from comment #8)
> hmm,
> 
> I just revert this commit on current 17.1 and it....fails with OP problem.
> how it that?

Sounds like something has gone wrong during bisect. Be that a typo good <> bad or some files were not generated.

You can tweaking the configure line (roughly like below) to build only the required parts and confirm the bisection results.

$ ./configure --without-vulkan-drivers --without-gallium-drivers --with-dri-drivers=swrast --disable-egl --disable-gbm --disable-gles1 --disable-gles2
Comment 10 warpme 2017-06-01 16:30:30 UTC
Emil,
Unfortunately minimizing build options doesn't help me with successful bisecting.
I'm always failing in the middle with following erorr:

//home/piotro/minimyth-dev/images/build/bin/bash ../../libtool  --tag=CC   --mode=link x86_64-minimyth-linux-gnu-gcc -pthread -Werror=pointer-arith -Werror=vla -fvisibility=hidden -ffat-lto-objects -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -Wall -std=c99 -Werror=implicit-function-declaration -Werror=missing-prototypes -fno-math-errno -fno-trapping-math  -no-undefined -Wl,--gc-sections -Wl,--no-undefined -Wl,--as-needed -pipe -flto -pipe -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -o shared-glapi/libglapi.la -rpath /usr/lib shared_glapi_libglapi_la-entry.lo shared_glapi_libglapi_la-mapi_glapi.lo shared_glapi_libglapi_la-stub.lo shared_glapi_libglapi_la-table.lo shared_glapi_libglapi_la-u_current.lo shared_glapi_libglapi_la-u_execmem.lo -lpthread
libtool: link: x86_64-minimyth-linux-gnu-gcc -shared  -fPIC -DPIC  .libs/shared_glapi_libglapi_la-entry.o .libs/shared_glapi_libglapi_la-mapi_glapi.o .libs/shared_glapi_libglapi_la-stub.o .libs/shared_glapi_libglapi_la-table.o .libs/shared_glapi_libglapi_la-u_current.o .libs/shared_glapi_libglapi_la-u_execmem.o   -lpthread  -pthread -flto -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64 -Wl,--gc-sections -Wl,--no-undefined -Wl,--as-needed -flto -march=x86-64 -mtune=generic -O3 -mfpmath=sse -flto -m64   -pthread -Wl,-soname -Wl,libglapi.so.0 -o shared-glapi/.libs/libglapi.so.0.0.0
libtool: link: (cd "shared-glapi/.libs" && rm -f "libglapi.so.0" && ln -s "libglapi.so.0.0.0" "libglapi.so.0")
libtool: link: (cd "shared-glapi/.libs" && rm -f "libglapi.so" && ln -s "libglapi.so.0.0.0" "libglapi.so")
libtool: link: ( cd "shared-glapi/.libs" && rm -f "libglapi.la" && ln -s "../libglapi.la" "libglapi.la" )
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p ../../lib;	\
for f in shared-glapi/.libs/libglapi.so*; do \
	if test -h .libs/$f; then			\
		cp -d $f ../../lib;	\
	else						\
		ln -f $f ../../lib;	\
	fi;						\
done && touch .install-mesa-links
make[6]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/mapi'
make[5]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/mapi'
make[4]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/mapi'
Making all in compiler
make[4]: Entering directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/compiler'
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl/glcpp
bison  -o glsl/glsl_parser.cpp -p "_mesa_glsl_" --defines=./glsl/glsl_parser.h ./glsl/glsl_parser.yy
flex  -o glsl/glsl_lexer.cpp ./glsl/glsl_lexer.ll
python  ./glsl/ir_expression_operation.py strings > glsl/ir_expression_operation_strings.h || (rm -f glsl/ir_expression_operation_strings.h; false)
python  ./glsl/ir_expression_operation.py enum > glsl/ir_expression_operation.h || (rm -f glsl/ir_expression_operation.h; false)
python  ./glsl/ir_expression_operation.py constant > glsl/ir_expression_operation_constant.h || (rm -f glsl/ir_expression_operation_constant.h; false)
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p glsl/glcpp
bison  -o glsl/glcpp/glcpp-parse.c -p "glcpp_parser_" --defines=./glsl/glcpp/glcpp-parse.h ./glsl/glcpp/glcpp-parse.y
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p nir
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p nir
flex  -o glsl/glcpp/glcpp-lex.c ./glsl/glcpp/glcpp-lex.l
//home/piotro/minimyth-dev/images/build/usr/bin/mkdir -p nir
python  ./nir/nir_builder_opcodes_h.py > nir/nir_builder_opcodes.h || (rm -f nir/nir_builder_opcodes.h; false)
python  ./nir/nir_constant_expressions.py > nir/nir_constant_expressions.c || (rm -f nir/nir_constant_expressions.c; false)
python  ./nir/nir_opcodes_c.py > nir/nir_opcodes.c || (rm -f nir/nir_opcodes.c; false)
Traceback (most recent call last):
  File "./nir/nir_builder_opcodes_h.py", line 46, in <module>
    from nir_opcodes import opcodes
  File "/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/compiler/nir/nir_opcodes.py", line 178, in <module>
    unop_convert("{}2{}{}".format(src_t[0], dst_t[0], bit_size),
ValueError: zero length field name in format
Traceback (most recent call last):
  File "./nir/nir_constant_expressions.py", line 405, in <module>
    from nir_opcodes import opcodes
  File "/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/compiler/nir/nir_opcodes.py", line 178, in <module>
    unop_convert("{}2{}{}".format(src_t[0], dst_t[0], bit_size),
ValueError: zero length field name in format
make[4]: *** [nir/nir_builder_opcodes.h] Error 1
make[4]: *** Waiting for unfinished jobs....
make[4]: *** [nir/nir_constant_expressions.c] Error 1
Traceback (most recent call last):
  File "./nir/nir_opcodes_c.py", line 26, in <module>
    from nir_opcodes import opcodes
  File "/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/compiler/nir/nir_opcodes.py", line 178, in <module>
    unop_convert("{}2{}{}".format(src_t[0], dst_t[0], bit_size),
ValueError: zero length field name in format
make[4]: *** [nir/nir_opcodes.c] Error 1
make[4]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src/compiler'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/piotro/minimyth-dev/script/xorg/Mesa/work/main.d/mesa-17.1.1'
../../gar.lib.mk:316: recipe for target 'build-work/main.d/mesa-17.1.1/Makefile' failed
make: *** [build-work/main.d/mesa-17.1.1/Makefile] Error 2
==>Done...
Comment 11 Emil Velikov 2017-06-01 18:35:47 UTC
(In reply to warpme from comment #10)
> Emil,
> Unfortunately minimizing build options doesn't help me with successful
> bisecting.
Minimising the build options was aimed to a) reduce the surface area and b) speed up the build, hence the bisection.

> I'm always failing in the middle with following erorr:

> python  ./nir/nir_opcodes_c.py > nir/nir_opcodes.c || (rm -f
> nir/nir_opcodes.c; false)
> Traceback (most recent call last):
>   File "./nir/nir_builder_opcodes_h.py", line 46, in <module>
>     from nir_opcodes import opcodes
These python errors seem new and unrelated. I would simply "git bisect skip" them.

To isolate any other bugs you could do:
$ git bisect start .....
$ build & test
$ git bisect good/bad
$ git clean -fxd // warning: it purge _all_ files that are not checked in git
$ rm -rf $builddir // if building out of tree
$ build & test
...
Comment 12 warpme 2017-06-02 16:03:44 UTC
Emil,
Due 762a6333f21fd8606f69db6060027c4522d46678 I can't use git auto bisect and need to do it manually with this commit reverted.

Here are results:

2e98db6... util/vk: Add helpers for finding an extension struct - good
ed28ae7... radv: Increase api version to 1.0.42 - good
407fa77... radv: Set driver version to mesa version - good
3ece76f... radv/ac: gather4 cube workaround integer - good
7372e3c... radv/ac: workaround regression in llvm 4.0 release - good
e2c4435... util/disk_cache: add thread queue to disk cache - bad

It looks like https://cgit.freedesktop.org/mesa/mesa/commit/?id=e2c4435b078a1471b044219552873a54b1817bac is root cause.

If You need - I'm ready to test patches to solve OP issue :-)

br
Comment 13 Emil Velikov 2017-06-02 17:14:54 UTC
Created attachment 131682 [details] [review]
configure.ac: add -pthread to PTHREAD_LIBS

Right, so util_queue_init() pulls util_queue_init/pthread_create.
Still not sure why things behave on your end -> -lpthread is in the link chain, so GCC should be smart enough to pick it.

Regardless, the attached patch is a step in the right direction and should address things on your end.
Comment 14 warpme 2017-06-03 18:10:01 UTC
Emil,
Now compiles OK.
I'm not sure why as I tested compilation with -lptrhead and -pthread...but with this patch compiles OK :-)
thx for Your work with this!
Comment 15 Emil Velikov 2017-06-15 23:00:09 UTC
Merged in master and should find it's way in 17.1.3 or 17.1.4.
Thanks for the help and testing. I would not have figured it out on my own.
Comment 16 John 2017-08-10 08:06:36 UTC
Hello,

I've been having the same issue for a while, even with Emil's patch on master:

libtool: link: ( cd "glsl/.libs" && rm -f "libstandalone.la" && ln -s "../libstandalone.la" "libstandalone.la" )
/bin/sh ../../libtool  --tag=CXX   --mode=link g++ -fvisibility=hidden -Werror=pointer-arith -Werror=vla -march=native -O2 -pipe -fstack-protector-strong -fno-plt -fstack-check -flto=8 -g -fvar-tracking-assignments -g -fvar-tracking-assignments -Wall -fno-math-errno -fno-trapping-math   -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,-flto -o glsl_compiler glsl/main.o glsl/libstandalone.la  
libtool: link: g++ -fvisibility=hidden -Werror=pointer-arith -Werror=vla -march=native -O2 -pipe -fstack-protector-strong -fno-plt -fstack-check -flto=8 -g -fvar-tracking-assignments -g -fvar-tracking-assignments -Wall -fno-math-errno -fno-trapping-math -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-flto -o glsl_compiler glsl/main.o  glsl/.libs/libstandalone.a -lz -lpthread -pthread
/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../lib/libstdc++.so: undefined reference to `pthread_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../lib/libstdc++.so: undefined reference to `pthread_once'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../lib/libstdc++.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status


If I remove "--as-needed" from my LDFLAGS it compiles with no problem.

I'm on GCC 7.1.1, glibc 2.25, not cross-compiling, but compiling for my system.

What am I doing wrong?

Thanks!
Comment 17 Sergey Kondakov 2017-12-20 22:31:14 UTC
On my LTO build of 17.3.0 in openSUSE OBS I've also got "undefined reference to `pthread_create'" in glsl_compiler but somehow managed to go past it (I think it was this patch: https://lists.freedesktop.org/archives/mesa-dev/2016-May/118772.html) and stuck with:

[   93s] + export 'CFLAGS=-fno-strict-aliasing -flto=3 -ffat-lto-objects -flto-odr-type-merging -fuse-linker-plugin'
[   93s] + export 'CXXFLAGS=-fno-strict-aliasing -flto=3 -ffat-lto-objects -flto-odr-type-merging -fuse-linker-plugin'
[   93s] + export 'LDFLAGS=-flto=3 -fuse-linker-plugin'
[   93s] + export FFLAGS=
…
[  109s] + ./configure --host=x86_64-suse-linux-gnu --build=x86_64-suse-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --enable-gles1 --enable-gles2 --enable-dri --with-platforms=x11,drm,wayland --enable-shared-glapi --enable-texture-float --enable-lmsensors --enable-gallium-extra-hud --enable-gallium-osmesa --enable-dri3 --enable-nine --enable-gbm --enable-glx-tls --enable-opencl --enable-opencl-icd --with-dri-searchpath=/usr/lib64/dri --enable-llvm --disable-llvm-shared-libs --enable-vdpau --enable-va --enable-xvmc --enable-omx-bellagio --with-vulkan-drivers=intel,radeon --enable-xa --with-dri-drivers=i915,i965,nouveau,r200,radeon --with-gallium-drivers=r300,r600,radeonsi,nouveau,swrast,swr,svga,virgl
…
[  426s]   CCLD     libgbm.la
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `call_once':
[  426s] <artificial>:(.text+0x11a17): undefined reference to `pthread_once'
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `thrd_create':
[  426s] <artificial>:(.text+0x11c5e): undefined reference to `pthread_create'
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `thrd_join':
[  426s] <artificial>:(.text+0x11c9f): undefined reference to `pthread_join'
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `u_thread_create':
[  426s] <artificial>:(.text+0x11d07): undefined reference to `pthread_sigmask'
[  426s] <artificial>:(.text+0x11d40): undefined reference to `pthread_sigmask'
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `u_thread_setname':
[  426s] <artificial>:(.text+0x11d76): undefined reference to `pthread_setname_np'
[  426s] /tmp/ccW1pRdh.ltrans0.ltrans.o: In function `u_thread_get_time_nano':
[  426s] <artificial>:(.text+0x11d97): undefined reference to `pthread_getcpuclockid'
[  426s] collect2: error: ld returned 1 exit status
[  426s] make[3]: *** [Makefile:846: libgbm.la] Error 1

Same 32 bit build fails with:
[  217s]   CXXLD    vulkan/libvulkan_intel.la
[  217s] /tmp/ccUrgMYa.ltrans0.ltrans.o: In function `_mesa_lroundevenf':
[  217s] <artificial>:(.text+0xca56): undefined reference to `lrintf'
[  217s] collect2: error: ld returned 1 exit status
[  217s] make[4]: *** [Makefile:2708: tools/aubinator_error_decode] Error 1
[  217s] make[4]: *** Waiting for unfinished jobs....

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.