Bug 361253

Summary: [s390x] ex_clone.c:42: undefined reference to `pthread_create'
Product: [Developer tools] valgrind Reporter: dann frazier <dannf>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: arnez, borntraeger, dannf
Priority: NOR    
Version: 3.11 SVN   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Move -lpthread to end of linker command line

Description dann frazier 2016-03-31 21:48:13 UTC
'make regtest' on trunk currently fails on Ubuntu 16.04/s390x.

gcc -Winline -Wall -Wshadow -Wno-long-long -g -fno-stack-protector   -m64   -lpthread  -o ex_clone ex_clone.o  
ex_clone.o: In function `main':
/home/ubuntu/valgrind/none/tests/s390x/ex_clone.c:42: undefined reference to `pthread_create'
/home/ubuntu/valgrind/none/tests/s390x/ex_clone.c:57: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Makefile:1324: recipe for target 'ex_clone' failed



Reproducible: Always

Steps to Reproduce:
1. Install Ubuntu 16.04 on an s390x system
2. svn clone svn://svn.valgrind.org/valgrind/trunk valgrind
3. cd valgrind; ./autogen.sh; ./configure; make regtest


Actual Results:  
gcc -Winline -Wall -Wshadow -Wno-long-long -g -fno-stack-protector   -m64   -lpthread  -o ex_clone ex_clone.o  
ex_clone.o: In function `main':
/home/ubuntu/valgrind/none/tests/s390x/ex_clone.c:42: undefined reference to `pthread_create'
/home/ubuntu/valgrind/none/tests/s390x/ex_clone.c:57: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Makefile:1324: recipe for target 'ex_clone' failed

Expected Results:  
Successful build.
Comment 1 dann frazier 2016-03-31 21:51:00 UTC
Created attachment 98183 [details]
Move -lpthread to end of linker command line
Comment 2 Christian Borntraeger 2016-09-20 12:21:59 UTC
I can certaiinly apply this patch, but I am puzzled. 

why does

gcc  -Winline -Wall -Wshadow -Wno-long-long -g -fno-stack-protector   -m64   -o ex_clone none/tests/s390x/ex_clone.o -lpthread 

work
and
gcc  -Winline -Wall -Wshadow -Wno-long-long -g -fno-stack-protector   -m64   -lpthread -o ex_clone none/tests/s390x/ex_clone.o
does not?
Comment 3 Christian Borntraeger 2016-09-20 12:32:19 UTC
OK, seems that library ordering does indeed matter.
applied as r15970