Alright, here's my second attempt. On Sat, May 8, 2021 at 10:54 PM Samuel Thibault <samuel.thiba...@gnu.org> wrote: > While at it, rather try to reproduce the other archs' behavior: use > gscope_flag from the tcb, and switch THREAD_GSCOPE_IN_TCB to 1. That > will make the implementation much simpler and scalable.
Well, this has been much less traightforward than the patch I sent yesterday (but unlike that patch, it appears to build and work). I am much less familiar with glibc internals than I am with Hurd, and it shows. Please don't throw stones at me :) For one thing, I don't think I understand how the buildsystem works. (For instance, how do I even add a new source file to a library? Or where does it decide which system-specific parts to build, such as whether to build NPTL or HTL? How do I debug the buildsystem when something doesn't work as expected?) It must be that I'm used to either straightforward Makefiles, or higher-level buildsystems (like CMake or Meson) that autogenerate the low-level boilerplate. Next, I was somewhat confused by what the GL macro is. My current understanding is: some data needs to be shared between the dynamic loader and glibc proper, if glibc is being built as a shared library. To support that case, such data is placed into a special struct instance that itself resides in ld.so. Then the GL macros is used to actually access those symbols. It switches, mostly transparently, between accessing said global struct instance in ld.so, and simply declaring global variables for the case of static build. Naming such variable with the dl_ prefix is just a convention. I likely got something wrong there. If I got the general idea wrong, the second patch must be completely bogus. Initially, I tried to get rid of THREAD_GSCOPE_IN_TCB completely, since THREAD_GSCOPE is now in TCB in all ports. But it turned out that the way it was actualy being used was not to check if the thread scope flag is in TCB or not, but simply to distingusish NPTL from HTL. Namely, files like elf/dl-tls.c would directly use NPTL specifics like struct pthread if THREAD_GSCOPE_IN_TCB is 1. The actual implementation of THREAD_GSCOPE_* is similar to the one in NPTL. Each thread uses a flag in its TCB. THREAD_GSCOPE_WAIT() has to iterate over all the threads and wait for each one to leave the global scope. This has to be available from inside ld.so, which is why I had to convert __pthread_threads (and friends) to GL (dl_pthread_threads). NPTL does a similar thing with its global thread lists, too. Now, on to the good parts. It builds, and even appears to work somewhat. And all the gsync_wake () calls are gone! ~/glibc/build$ ./testrun.sh /bin/uname GNU ~/glibc/build$ ./testrun.sh --tool=rpctrace /bin/uname |& grep gsync ~/glibc/build$ Sergey Bugaev (3): XXX: Rename THREAD_GSCOPE_IN_TCB -> THREAD_GSCOPE_LINK_MAP XXX: Move __pthread_threads to ld.so XXX: Reimplement gscope elf/dl-reloc.c | 4 +-- elf/dl-support.c | 6 ++-- elf/dl-tls.c | 6 ++-- elf/rtld.c | 2 +- htl/Versions | 2 +- htl/pt-alloc.c | 46 ++++++++++++------------ htl/pt-create.c | 11 ++---- htl/pt-internal.h | 28 +++++---------- sysdeps/aarch64/nptl/tls.h | 2 +- sysdeps/alpha/nptl/tls.h | 2 +- sysdeps/arc/nptl/tls.h | 2 +- sysdeps/arm/nptl/tls.h | 2 +- sysdeps/csky/nptl/tls.h | 2 +- sysdeps/generic/ldsodefs.h | 18 ++++++---- sysdeps/generic/tls.h | 3 +- sysdeps/hppa/nptl/tls.h | 2 +- sysdeps/htl/dl-thread_gscope_wait.c | 36 +++++++++++++++++++ sysdeps/htl/pt-key-delete.c | 8 ++--- sysdeps/htl/pthreadP.h | 2 +- sysdeps/htl/raise.c | 9 +++-- sysdeps/htl/thrd_current.c | 8 +++-- sysdeps/i386/nptl/tls.h | 2 +- sysdeps/ia64/nptl/tls.h | 2 +- sysdeps/m68k/nptl/tls.h | 2 +- sysdeps/mach/hurd/htl/pt-sigstate-init.c | 2 +- sysdeps/mach/hurd/htl/pt-sysdep.c | 2 +- sysdeps/mach/hurd/htl/pt-sysdep.h | 2 +- sysdeps/mach/hurd/i386/tls.h | 22 ++++++++++++ sysdeps/mach/hurd/tls.h | 20 ----------- sysdeps/microblaze/nptl/tls.h | 2 +- sysdeps/mips/nptl/tls.h | 2 +- sysdeps/nios2/nptl/tls.h | 2 +- sysdeps/powerpc/nptl/tls.h | 2 +- sysdeps/riscv/nptl/tls.h | 2 +- sysdeps/s390/nptl/tls.h | 2 +- sysdeps/sh/nptl/tls.h | 2 +- sysdeps/sparc/nptl/tls.h | 2 +- sysdeps/x86_64/nptl/tls.h | 2 +- 38 files changed, 156 insertions(+), 117 deletions(-) create mode 100644 sysdeps/htl/dl-thread_gscope_wait.c -- 2.31.1