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

look for pthread_atfork() also in lib c_nonshared #16

Closed
wants to merge 1 commit into from
Closed

look for pthread_atfork() also in lib c_nonshared #16

wants to merge 1 commit into from

Conversation

DerDakon
Copy link

@DerDakon DerDakon commented Nov 8, 2018

Newer versions of glibc do not have pthread_nonshared anymore, instead the symbol is in c_nonshared. This fixes a crash on start on those platforms (namely with syslog-ng).

The fix was inspired by #15 (comment).

Newer versions of glibc do not have pthread_nonshared anymore, instead the
symbol is in c_nonshared. This fixes a crash on start on those platforms
(namely with syslog-ng).

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
@hydrapolic
Copy link

We added this to Gentoo Linux and it fixed the segfault on ppc64 - https://bugs.gentoo.org/675338.

@hbakken
Copy link

hbakken commented Apr 1, 2019

The fix from the pull request seems to fix this, and syslog-ng is (understandably) not very keen on pulling an ivykis fix which isn't upstream. Is there any chance of getting this pulled soon?

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this pull request Apr 10, 2019
syslog-ng may segfault at startup (during library initialization, before
reaching main) in newer toolchains. I have witnessed it on aarch64 (but with
32-bit arm userland) with glibc 2.28.

Problem is described in syslog-ng issue #2263 [1], which in turn leads to a
problem in 'ivykis' which is shipped with syslog-ng, see ivykis issue #15
[2].

Root cause is that 'pthread_atfork' is used by ivykis but searched by its
configure script in libpthread_nonshared only. In newer toolchains, it seems
this symbol is in libc_nonshared.

Apply a patch someone proposed via pullrequest [3] to the ivykis project,
but which is at this moment not yet merged upstream.

[1] syslog-ng/syslog-ng#2263
[2] buytenh/ivykis#15
[3] buytenh/ivykis#16

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this pull request Apr 24, 2019
syslog-ng may segfault at startup (during library initialization, before
reaching main) in newer toolchains. I have witnessed it on aarch64 (but with
32-bit arm userland) with glibc 2.28.

Problem is described in syslog-ng issue #2263 [1], which in turn leads to a
problem in 'ivykis' which is shipped with syslog-ng, see ivykis issue #15
[2].

Root cause is that 'pthread_atfork' is used by ivykis but searched by its
configure script in libpthread_nonshared only. In newer toolchains, it seems
this symbol is in libc_nonshared.

Apply a patch someone proposed via pullrequest [3] to the ivykis project,
but which is at this moment not yet merged upstream.

[1] syslog-ng/syslog-ng#2263
[2] buytenh/ivykis#15
[3] buytenh/ivykis#16

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(cherry picked from commit d1467ea)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
@DerDakon
Copy link
Author

DerDakon commented May 1, 2019

ping?

@buytenh
Copy link
Owner

buytenh commented May 4, 2019

@hydrapolic @hbakken @DerDakon Just for my information, do you also get
this segmentation fault if you build and install ivykis from an ivykis
source tarball and then build syslog-ng with --with-ivykis=system ?

@hbakken
Copy link

hbakken commented May 4, 2019

@hydrapolic @hbakken @DerDakon Just for my information, do you also get
this segmentation fault if you build and install ivykis from an ivykis
source tarball and then build syslog-ng with --with-ivykis=system ?

Yes, unless the above-mentioned patch is applied to ivykis, it still crashes.

@buytenh
Copy link
Owner

buytenh commented May 4, 2019

@hbakken OK, thank you for testing. Could you please upload a build
log for that somewhere?

(My only aarch64 environment is emulated via QEMU and everything
there is painfully slow.)

@hbakken
Copy link

hbakken commented May 4, 2019

Uh, sorry, I haven't tested in a while, and I need to build a new os base for my embedded system to trigger the bug, which takes a bit, so that's going to be a bit of a hassle.
The fix seems rather straight-forward to me, though. We search for a function in the wrong library, fails to find it, thus crashing.

@hbakken
Copy link

hbakken commented May 4, 2019

...so it seems I need to clarify my previous comment: That was the case back on April 1st. If any of the commits on ivykis since then has fixed this, I haven't tested it. I did, however, try to build syslog-ng against ivykis as of ~1 Apr, and it failed.

@MrAnno
Copy link

MrAnno commented May 4, 2019

I have a reproduction of this issue on a public arm64 server (without syslog-ng).
@buytenh I've sent you SSH access via email.

Basically, the following example program and glibc 2.28 are needed:

#define _POSIX_C_SOURCE 200809L
#include <iv.h>

int main()
{
  iv_init();
  iv_main();
  iv_deinit();
}
$ gcc -std=c99 -Wall -Wextra -Werror -g -pthread ivykis-reprod.c -o ivykis-reprod -livykis
#0  0x0000000000000000 in ?? ()
#1  0x0000ffffb7fb3654 in pthr_atfork (child=<optimized out>, parent=<optimized out>, prepare=<optimized out>) at pthr.h:76
#2  iv_signal_init () at iv_signal.c:114
$ nm -g /usr/lib/aarch64-linux-gnu/libc_nonshared.a | grep atfork
pthread_atfork.oS:
0000000000000000 T __pthread_atfork
0000000000000000 W pthread_atfork
                 U __register_atfork

@buytenh
Copy link
Owner

buytenh commented May 4, 2019

I think I understand this a bit better now (see the update on issue #15).

It seems that we don't even need to pull in lib*_nonshared.a by
hand (which is what AC_CHECK_LIB() does, it adds the library you're
checking for to LIBS if it is found), as this patch, which only
defines HAVE_* but doesn't pull in any libraries, also seems to do
the trick for me:

diff --git a/configure.ac b/configure.ac
index e9b10c0..4f560fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,7 +87,8 @@ esac
 # libpthread_nonshared.a without pulling in libpthread.so.0, explicitly
 # link in libpthread_nonshared.a if it is available.
 #
-AC_CHECK_LIB([pthread_nonshared], [pthread_atfork])
+AC_CHECK_LIB([c_nonshared], [pthread_atfork], [AC_DEFINE(HAVE_LIBC_NONSHARED, 1, Blah)])
+AC_CHECK_LIB([pthread_nonshared], [pthread_atfork], [AC_DEFINE(HAVE_LIBPTHREAD_NONSHARED, 1, Blah)])

 # Checks for header files.
 AC_CHECK_HEADERS([process.h])
diff --git a/src/pthr.h b/src/pthr.h
index a41eaf3..a1807d3 100644
--- a/src/pthr.h
+++ b/src/pthr.h
@@ -42,7 +42,7 @@ static inline int pthreads_available(void)
  * symbol because that causes it to be undefined even if you link
  * libpthread_nonshared.a in explicitly.
  */
-#ifndef HAVE_LIBPTHREAD_NONSHARED
+#if !defined(HAVE_LIBC_NONSHARED) && !defined(HAVE_LIBPTHREAD_NONSHARED)
 #pragma weak pthread_atfork
 #endif

That is, merely the not marking of pthread_atfork as weak if it is
provided by one of two archive libraries seems to be sufficient to fix
this issue, as per #15 (comment) .

@buytenh
Copy link
Owner

buytenh commented May 5, 2019

@buytenh
Copy link
Owner

buytenh commented May 16, 2019

I've had positive feedback for this fix, so I've merged it as commit
a5e9cad ("Avoid marking pthread_atfork() as weak if provided by
libc_nonshared.a."), and I have released ivykis v0.42.4 with this fix
included.

Thanks again to all involved!

@buytenh buytenh closed this May 16, 2019
@hydrapolic
Copy link

Thank you

@DerDakon DerDakon deleted the glibc-pthr_atfork branch May 17, 2019 08:55
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

Successfully merging this pull request may close these issues.

5 participants