NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/57628: multithread programs may deadlock in ld.elf_so (sparc on sparc64)
The following reply was made to PR lib/57628; it has been noted by GNATS.
From: Martin Husemann <martin%duskware.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: lib/57628: multithread programs may deadlock in ld.elf_so (sparc
on sparc64)
Date: Wed, 27 Sep 2023 20:05:11 +0200
The attached patch seems to fix the issue for me, w/o any obivous bad
side effects (ld.elf_so size ~the same, initial tests work fine).
The same gdb test run from the previous rump example now shows both copies
of __libc_atomic_init() being called - the ld.elf_so internal one very
early (before any userland threads could have been created) and the second
one when libc constructors are run.
All our ld.elf_so seem to have the hidden function, but it is a no-op on most
architectures (when hardware supported atomic ops are good enough), so no
ifdef magic or whatever seems needed.
Is it this simple? Am I overlooking something?
Will run complete tests now...
Martin
Index: rtld.c
===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.215
diff -u -p -r1.215 rtld.c
--- rtld.c 30 Jul 2023 09:20:14 -0000 1.215
+++ rtld.c 27 Sep 2023 17:52:04 -0000
@@ -70,6 +70,13 @@ __RCSID("$NetBSD: rtld.c,v 1.215 2023/07
#endif
/*
+ * Hidden function from common/lib/libc/atomic - nop on machines
+ * with enough atomic ops. Need to explicitly call it early.
+ * libc has the same symbol and will initialize itself, but not our copy.
+ */
+void __libc_atomic_init(void);
+
+/*
* Function declarations.
*/
static void _rtld_init(caddr_t, caddr_t, const char *);
@@ -404,6 +411,8 @@ _rtld_init(caddr_t mapbase, caddr_t relo
ehdr = (Elf_Ehdr *)mapbase;
_rtld_objself.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);
_rtld_objself.phsize = ehdr->e_phnum * sizeof(_rtld_objself.phdr[0]);
+
+ __libc_atomic_init();
}
/*
Home |
Main Index |
Thread Index |
Old Index