Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `pthread_atfork' #9

Closed
twoerner opened this issue Oct 25, 2019 · 2 comments
Closed

undefined reference to `pthread_atfork' #9

twoerner opened this issue Oct 25, 2019 · 2 comments

Comments

@twoerner
Copy link
Contributor

Building on some distros (openSUSE 15.1) requires the addition of -lpthread in order to build successfully:

make[2]: Entering directory '/home/trevor/devel/extern/libcap-ng/_build/utils'
/bin/sh ../libtool  --tag=CC   --mode=link gcc -W -Wall -Wshadow -Wformat -Wundef -D_GNU_SOURCE -g -O2   -o pscap pscap.o  -L../src -lcap-ng
libtool: link: gcc -W -Wall -Wshadow -Wformat -Wundef -D_GNU_SOURCE -g -O2 -o .libs/pscap pscap.o  -L../src /home/trevor/devel/extern/libcap-ng/_build/src/.libs/libcap-ng.so
/usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /home/trevor/devel/extern/libcap-ng/_build/src/.libs/libcap-ng.so: undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:488: pscap] Error 1
make[2]: Leaving directory '/home/trevor/devel/extern/libcap-ng/_build/utils'
make[1]: *** [Makefile:448: all-recursive] Error 1
make[1]: Leaving directory '/home/trevor/devel/extern/libcap-ng/_build'
make: *** [Makefile:380: all] Error 2

I noticed this with 0.7.10, but the issue also exists on master.

I can build successfully if I do:

$ make LDFLAGS="-lpthread"
@stevegrubb
Copy link
Owner

The following is copied from a pull request. It probably belongs here for posterity.

I suppose there should be more work on this. Before using pthread_atfork() indiscriminately, I was assured by glibc developers that pthread_atfork has been moved to normal libc. Exactly how they do it I do not directly see. But objdump --syms /usr/lib64/libc-2.30.so | grep atfork shows: __register_atfork and digging into nptl/pthread_atfork.c shows that there is a weak alias that uses __register_atfork.

I have no idea which version of glibc started making pthread_atfork "work" for plain libc linking. Perhaps some work needs to be done to find that and create a proper test for configure that does the right thing for both old and new glibc.

@stevegrubb
Copy link
Owner

Closing this based on merging pull request #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants