Skip to contentSkip to conversation

libbsd: remove usage of __register_atfork

PATCH New Fabrice Fontaine 3 participants 4 messages Oct 3, 2018 – Nov 28, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbsd: remove usage of __register_atfork

The following error is raised by minizip:

[100%] Linking C executable minizip /home/peko/autobuild/instance-0/output/host/m68k-buildroot-uclinux-uclibc/sysroot/usr/lib/libbsd.a(arc4random.o): In function `_rs_init.part.1':
arc4random.c:(.text+0xaa): undefined reference to `__register_atfork'
collect2: error: ld returned 1 exit status

As specified in openssl/Config.in, uClibc on noMMU doesn't provide __register_atfork() so, as suggested by Arnout during review of minizip patch (https://patchwork.ozlabs.org/patch/978000), remove usage of this function from libbsd to always use pthread_atfork

Fixes:
- http://autobuild.buildroot.org/results/df2dcbdceaa01a2ae37bf09140e4dbef0a5b9489

---
 ...02-Remove-usage-of-__register_atfork.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 package/libbsd/0002-Remove-usage-of-__register_atfork.patch
package/libbsd/0002-Remove-usage-of-__register_atfork.patch new file +39 -0
new file mode 100644
index 0000000000..366594bbe8
@@ -0,0 +1,39 @@
+From 1220b3b758030f1717558980d60ade9a33628383 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <[email protected]>
+Date: Wed, 3 Oct 2018 19:14:34 +0200
+Subject: [PATCH] Remove usage of __register_atfork
+
+Calling an internal function of glibc is never a good idea.
+This is especially true for __register_atfork which is not defined on
+uClibc with noMMU.
+So remove call to __register_atfork and so always use pthread_atfork
+
+Signed-off-by: Fabrice Fontaine <[email protected]>
+[Upstream status:
+https://gitlab.freedesktop.org/libbsd/libbsd/merge_requests/2]
+---
+ src/arc4random_linux.h | 7 -------
+ 1 file changed, 7 deletions(-)
+
+diff --git a/src/arc4random_linux.h b/src/arc4random_linux.h
+index 7a2ca1e..7287b07 100644
+--- a/src/arc4random_linux.h
++++ b/src/arc4random_linux.h
+@@ -31,14 +31,7 @@
+ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
+ #define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
+ #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
+-
+-#ifdef __GLIBC__
+-extern void *__dso_handle;
+-extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+-#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
+-#else
+ #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+-#endif
+ 
+ static inline void
+ _getentropy_fail(void)
+-- 
+2.17.1
+
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 libbsd: remove usage of __register_atfork

Hello,

+Arnout in Cc.

Quoted 12 lines · Fabrice Fontaine

The following error is raised by minizip:

[100%] Linking C executable minizip /home/peko/autobuild/instance-0/output/host/m68k-buildroot-uclinux-uclibc/sysroot/usr/lib/libbsd.a(arc4random.o): In function `_rs_init.part.1':
arc4random.c:(.text+0xaa): undefined reference to `__register_atfork'
collect2: error: ld returned 1 exit status

As specified in openssl/Config.in, uClibc on noMMU doesn't provide __register_atfork() so, as suggested by Arnout during review of minizip patch (https://patchwork.ozlabs.org/patch/978000), remove usage of this function from libbsd to always use pthread_atfork

Quoted 8 lines

Fixes:
- http://autobuild.buildroot.org/results/df2dcbdceaa01a2ae37bf09140e4dbef0a5b9489

---
 ...02-Remove-usage-of-__register_atfork.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 package/libbsd/0002-Remove-usage-of-__register_atfork.patch

With this change, the build fails in the CI of libbsd:
https://gitlab.freedesktop.org/ffontaine/libbsd/-/jobs/26984:

../src/.libs/libbsd.so: undefined reference to `pthread_atfork'

I guess that's because pthread_atfork() requires linking against libpthread ?

Also, pthread_atfork() does not have the dso_handle argument that __register_atfork() has. Is this important in the context of libbsd ? See
https://gitlab.com/gnutls/gnutls/commit/84b1a7ac383bf1db4c73b8f044170446deca8b2e
for example. I would assume no, because there was already a fallback on pthread_atfork() in libbsd.

Also, Arnout said __register_atfork() is an internal function, but it is documented in LSB:
http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/baselib--register-atfork.html.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 libbsd: remove usage of __register_atfork

Dear all,
Le dim. 14 oct. 2018 ? 10:58, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 42 lines

Hello,

+Arnout in Cc.

Quoted 12 lines · Fabrice Fontaine

The following error is raised by minizip:

[100%] Linking C executable minizip /home/peko/autobuild/instance-0/output/host/m68k-buildroot-uclinux-uclibc/sysroot/usr/lib/libbsd.a(arc4random.o): In function `_rs_init.part.1':
arc4random.c:(.text+0xaa): undefined reference to `__register_atfork'
collect2: error: ld returned 1 exit status

As specified in openssl/Config.in, uClibc on noMMU doesn't provide __register_atfork() so, as suggested by Arnout during review of minizip patch (https://patchwork.ozlabs.org/patch/978000), remove usage of this function from libbsd to always use pthread_atfork

Quoted 8 lines

Fixes:
- http://autobuild.buildroot.org/results/df2dcbdceaa01a2ae37bf09140e4dbef0a5b9489

---
 ...02-Remove-usage-of-__register_atfork.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 package/libbsd/0002-Remove-usage-of-__register_atfork.patch

With this change, the build fails in the CI of libbsd:
https://gitlab.freedesktop.org/ffontaine/libbsd/-/jobs/26984:

../src/.libs/libbsd.so: undefined reference to `pthread_atfork'

I guess that's because pthread_atfork() requires linking against libpthread ?

Also, pthread_atfork() does not have the dso_handle argument that __register_atfork() has. Is this important in the context of libbsd ? See
https://gitlab.com/gnutls/gnutls/commit/84b1a7ac383bf1db4c73b8f044170446deca8b2e
for example. I would assume no, because there was already a fallback on pthread_atfork() in libbsd.

Quoted 3 lines

Also, Arnout said __register_atfork() is an internal function, but it is documented in LSB:
http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/baselib--register-atfork.html.

OK, so I'll send a new patch to remove this change and add the following dependency on libbsd and minizip:
# uClibc on noMMU doesn't provide __register_atfork() depends on !(BR2_TOOLCHAIN_USES_UCLIBC && !BR2_USE_MMU)

Quoted 8 lines

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Best Regards,

Fabrice

#3 lore raw

PATCH 1/1 libbsd: remove usage of __register_atfork

On 2018-11-28 18:04 +0100, Fabrice Fontaine spake thusly:

Quoted 32 lines

Dear all,
Le dim. 14 oct. 2018 ? 10:58, Thomas Petazzoni
<[email protected]> a ?crit :

Quoted 29 lines

Hello,

+Arnout in Cc.

Quoted 12 lines · Fabrice Fontaine

The following error is raised by minizip:

[100%] Linking C executable minizip /home/peko/autobuild/instance-0/output/host/m68k-buildroot-uclinux-uclibc/sysroot/usr/lib/libbsd.a(arc4random.o): In function `_rs_init.part.1':
arc4random.c:(.text+0xaa): undefined reference to `__register_atfork'
collect2: error: ld returned 1 exit status

As specified in openssl/Config.in, uClibc on noMMU doesn't provide __register_atfork() so, as suggested by Arnout during review of minizip patch (https://patchwork.ozlabs.org/patch/978000), remove usage of this function from libbsd to always use pthread_atfork

Quoted 8 lines

Fixes:
- http://autobuild.buildroot.org/results/df2dcbdceaa01a2ae37bf09140e4dbef0a5b9489

---
 ...02-Remove-usage-of-__register_atfork.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 package/libbsd/0002-Remove-usage-of-__register_atfork.patch

With this change, the build fails in the CI of libbsd:
https://gitlab.freedesktop.org/ffontaine/libbsd/-/jobs/26984:

That's because the test should link with -pthread, maybe something not too far fromm:

overlay_LDADD = -pthread

(totally untested)

Quoted 5 lines
Quoted 1 line

http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/baselib--register-atfork.html.

OK, so I'll send a new patch to remove this change and add the following dependency on libbsd and minizip:
# uClibc on noMMU doesn't provide __register_atfork() depends on !(BR2_TOOLCHAIN_USES_UCLIBC && !BR2_USE_MMU)

Works for me too, I guess, until upstream fixes their mess.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'