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

[TEMP. FIX] undefined reference to `pthread_atfork' #3884

Closed
concatime opened this issue Jul 7, 2017 · 27 comments
Closed

[TEMP. FIX] undefined reference to `pthread_atfork' #3884

concatime opened this issue Jul 7, 2017 · 27 comments
Milestone

Comments

@concatime
Copy link

concatime commented Jul 7, 2017

Hi. I'm trying to build Nginx with this script, but I get this error.

objs/addon/src/ngx_http_brotli_filter_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lpthread -lcrypt -lm ../pcre-8.41/.libs/libpcre.a ../openssl/.openssl/lib/libssl.a ../openssl/.openssl/lib/libcrypto.a -ldl ../libatomic_ops-7.6.0/src/libatomic_ops.a \
-Wl,-E
../openssl/.openssl/lib/libcrypto.a(threads_pthread.o): In function `openssl_init_fork_handlers':
threads_pthread.c:(.text+0x1ba): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:309: objs/nginx] Error 1

I was able to build two weeks ago, so this issue must be new.

[EDIT] See the temporary fix.

@richsalz
Copy link
Contributor

richsalz commented Jul 7, 2017 via email

@concatime
Copy link
Author

Well, I tried on my server, which is Debian 9 from OVH, and on my desktop, OpenSUSE Tumbleweed. Both with the same result. I used gcc-7/g++-7, maybe because of this?

@concatime
Copy link
Author

Well, this error happens also with gcc/g++ 6.

@richsalz
Copy link
Contributor

richsalz commented Jul 8, 2017 via email

@t-j-h
Copy link
Member

t-j-h commented Jul 8, 2017

Note: pthread_atfork can be in libc rather than libpthreads.

@richsalz
Copy link
Contributor

richsalz commented Jul 8, 2017 via email

@levitte
Copy link
Member

levitte commented Jul 8, 2017

It looks to me like this is an order problem:

objs/addon/src/ngx_http_brotli_filter_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lpthread -lcrypt -lm ../pcre-8.41/.libs/libpcre.a ../openssl/.openssl/lib/libssl.a ../openssl/.openssl/lib/libcrypto.a -ldl ../libatomic_ops-7.6.0/src/libatomic_ops.a \
-Wl,-E

Shouldn't -lpthread appear last to make sure the symbol references in libcrypto.a get properly resolved?

@kroeckx
Copy link
Member

kroeckx commented Jul 8, 2017 via email

@paulidale
Copy link
Contributor

I'm with @levitte the -lpthread should be later in the command line. After the .a files.
You shouldn't need it twice. -ldl is there twice too.

That is more like:

objs/addon/src/ngx_http_brotli_filter_module.o \
objs/ngx_modules.o \
 ../pcre-8.41/.libs/libpcre.a ../openssl/.openssl/lib/libssl.a ../openssl/.openssl/lib/libcrypto.a ../libatomic_ops-7.6.0/src/libatomic_ops.a \
-ldl -lpthread -lpthread -lcrypt -lm -Wl,-E

@concatime
Copy link
Author

concatime commented Jul 8, 2017

So finally, It seems that the Nginx configuration file is quite odd. So the the temporary solution for now is a hack. After running the ./configure, in obj/Makefile, you should remove the first -lpthread and move the second to the end of the line, right before \. Since the github repo. of Nginx is just a mirror, I can't submit an issue about this.

Thanks to all of you who supported me through this whole issue.

@concatime concatime changed the title undefined reference to `pthread_atfork' [SOLVED] undefined reference to `pthread_atfork' Jul 8, 2017
@concatime
Copy link
Author

concatime commented Jul 8, 2017

We should leave this post open until Nginx patches this.

Ok, cool.

@concatime concatime changed the title [SOLVED] undefined reference to `pthread_atfork' [TEMP. FIX] undefined reference to `pthread_atfork' Jul 8, 2017
@richsalz
Copy link
Contributor

richsalz commented Jul 8, 2017

We're glad you got it working. You can still open an issue with nginx. OpenSSL's GH repo is just a downstream clone and we take issues :) This will come up for anyone who is building from master and the next release. Their config file was wrong and they just got lucky until now.

@richsalz richsalz closed this as completed Jul 8, 2017
@t0mtaylor
Copy link

t0mtaylor commented Sep 18, 2017

this worked for me:

	-L ../openssl-dev/.openssl/lib/ -ldl -lcrypt -lm ../pcre-8.39/.libs/libpcre.a ../openssl-dev/.openssl/lib/libssl.a ../openssl-dev/.openssl/lib/libcrypto.a -ldl ../zlib-1.2.8/libz.a -lpthread \
	-Wl,-E

@levitte
Copy link
Member

levitte commented Sep 19, 2017

Hmm, there was another issue where someone complained that our libcrypto.pc didn't have the necessary options to have the pthread library be part of the final link. Does nginx us pkgconfig files to figure out compile and link options? Then that might be the issue, and that falls back on us.

@levitte levitte reopened this Sep 19, 2017
@meilihao
Copy link

meilihao commented Sep 19, 2017

Today i get the same problem when use --with-openssl=../openssl-master --with-openssl-opt='enable-tls1_3':

../openssl-master/.openssl/lib/libcrypto.a(threads_pthread.o):In function ‘fork_once_func’:
threads_pthread.c:(.text+0x16):undefined reference to `pthread_atfork'

openssl : d2ef6e4
OS: CentOS Linux release 7.4.1708 (Core)
nginx: nginx-1.13.5
gcc : gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)

@meilihao
Copy link

And i add -pthread to --with-cc-opt to build again, but get a same error:

...
-Wl,-z,relro -Wl,-z,now -pie -ldl -lpthread -lcrypt -lpcre ../openssl-master/.openssl/lib/libssl.a ../openssl-master/.openssl/lib/libcrypto.a -ldl -lz \
-Wl,-E
../openssl-master/.openssl/lib/libcrypto.a(threads_pthread.o):In function ‘fork_once_func’:
threads_pthread.c:(.text+0x16):undefined reference to 'pthread_atfork'

@meilihao
Copy link

@levitte
Copy link
Member

levitte commented Sep 19, 2017

Yeah, it's a solution, but kind of a hack. If we're at fault, I will gladly resolve it, but maybe not this week (out travelling)

@dsamarin
Copy link

dsamarin commented Oct 1, 2017

For those who want a scripted temporary solution:

gawk -i inplace \
  '/pthread/ { sub(/-lpthread /, ""); sub(/-lpthread /, ""); sub(/\\/, "-lpthread \\"); print } ! /pthread/ { print }' \
  "objs/Makefile"

@mattcaswell
Copy link
Member

@levitte - do we need to do something here?

@mattcaswell mattcaswell added this to the 1.1.1 milestone Jan 22, 2018
@levitte
Copy link
Member

levitte commented Jan 22, 2018

Yes, we do, we need to make sure that -pthread is part of ex_libs in config targets where this is present in cflags. That way, it will end up in Libs.private in libcrypto.pc

levitte added a commit to levitte/openssl that referenced this issue Jan 22, 2018
Even -pthread gets treated that way.  The reason to do this is so it
ends up in 'Libs.private' in libcrypto.pc.

Fixes openssl#3884
@levitte levitte mentioned this issue Jan 22, 2018
levitte added a commit to levitte/openssl that referenced this issue Jan 22, 2018
Even -pthread gets treated that way.  The reason to do this is so it
ends up in 'Libs.private' in libcrypto.pc.

Fixes openssl#3884
@levitte
Copy link
Member

levitte commented Jan 22, 2018

Fixes in #5134 (master) and #5135 (1.1.0)

levitte added a commit that referenced this issue Jan 23, 2018
Even -pthread gets treated that way.  The reason to do this is so it
ends up in 'Libs.private' in libcrypto.pc.

Fixes #3884

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from #5135)
@khs1994
Copy link

khs1994 commented Apr 4, 2018

nginx 1.13.11 fix

@r3k2
Copy link

r3k2 commented Oct 21, 2019

Hello Im having this same issue under

Ubuntu 18.04.3 LTS

with:

  8%] Linking CXX executable test_cypher_suites
/usr/lib/x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `fork_once_func':
(.text+0x16): undefined reference to `pthread_atfork'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/build.make:113: recipe for target 'libraries/fc/test/crypto/test_cypher_suites' failed
make[2]: *** [libraries/fc/test/crypto/test_cypher_suites] Error 1
CMakeFiles/Makefile2:789: recipe for target 'libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/all' failed
make[1]: *** [libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

none of the work around did work for me, because I can't downgrade to that version with apt

@levitte
Copy link
Member

levitte commented Oct 21, 2019

You should look into the order in which the linking command line gets the different libraries, which means you need to tell your make to be a bit more verbose

@SergeyJames
Copy link

SergeyJames commented Nov 25, 2020

In my case, building of openssl library with flag no-threads, was the solution:

./config  no-threads

@ccy234
Copy link

ccy234 commented Apr 21, 2021

And i add -pthread to --with-cc-opt to build again, but get a same error:

...
-Wl,-z,relro -Wl,-z,now -pie -ldl -lpthread -lcrypt -lpcre ../openssl-master/.openssl/lib/libssl.a ../openssl-master/.openssl/lib/libcrypto.a -ldl -lz \
-Wl,-E
../openssl-master/.openssl/lib/libcrypto.a(threads_pthread.o):In function ‘fork_once_func’:
threads_pthread.c:(.text+0x16):undefined reference to 'pthread_atfork'

you should use "--with-ld-opt=-pthread"

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