From patchwork Wed Nov 3 16:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 47002 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 329833858424 for ; Wed, 3 Nov 2021 16:28:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 329833858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635956925; bh=aQZDiK83dPRF3NRuTcW1HWshfiOZZ7EshWErKfJjAGQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=w2VWp6Jrpq8PgLGiwQVawGwLJ/xHD6KiInvjrdB4MjgrjmPL3SAlKkzj6tg+MESaG +yFoDTfBCzSnAS5m6x/ZmPG/d3fRpKp4DKTAAEe5ebbiwBfPEvc4APWIEqwhk0+1i5 px8oKrGU4WDmq52tu1hhAZhE3MJkqg5Ql3+MEDa0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A0DAB3858D28 for ; Wed, 3 Nov 2021 16:27:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0DAB3858D28 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-285-JfsqcmY0ODGtmlM7hfLnMA-1; Wed, 03 Nov 2021 12:27:26 -0400 X-MC-Unique: JfsqcmY0ODGtmlM7hfLnMA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13BFC1006AA6; Wed, 3 Nov 2021 16:27:25 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81BDB70F5F; Wed, 3 Nov 2021 16:27:20 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 0/3] Add _dl_find_eh_frame function for unwinder optimization X-From-Line: ed580138ca8b4c467f84f1131cfe627729588212 Mon Sep 17 00:00:00 2001 Message-Id: Date: Wed, 03 Nov 2021 17:27:18 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Gcc-patches From: Florian Weimer Reply-To: Florian Weimer Cc: Jakub Jelinek , gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch series implements a new function, _dl_find_eh_frame, for use by in-process unwinders. The new function is lock-free and async-signal-safe, and it scales logarithmically with the number of shared objects in the process. It does not write to global data at all, unlike the current libgcc unwinder, which has a small global cache and relies on the unwinder lock. dlclose is fully supported. The interface itself is modelled on the __gnu_Unwind_Find_exidx function. I'm going to post the GCC patches that enable use of this function separately. We may want to tweak the _dl_find_eh_frame interface somewhat. For example, we could also provide a pointer to the link map, and perhaps the in-memory boundaries of the object. With the link map, we can use it to accelerate _dl_find_dso_for_object. And we should really use it to implement __gnu_Unwind_Find_exidx on arm. Something like this: struct dl_find_object { struct link_map *dl_link_map; void *dl_eh_frame; void *dl_map_start; void *dl_map_end; void *dl_dbase; // optional, i386 & nios2 unsigned long int dl_pcount; // optional, arm }; int _dl_find_object (void *__address, struct dl_find_object *__result) __TRHOW; I wanted to post this version so that the review of the GCC patches can start now and hopefully finish in time for stage 1 close. Tested on i686-linux-gnu, x86_64-linux-gnu with the old and new unwinder. Tested on powerpc-linux-gnu, powerpc64le-linux-gnu, aarch64-linux-gnu with the old unwinder. Thanks, Florian Florian Weimer (3): nptl: Extract from pthread_cond_common.c elf: Introduce GLRO (dl_libc_freeres), called from __libc_freeres elf: Add _dl_find_eh_frame function NEWS | 4 + bits/atomic_wide_counter.h | 35 + bits/dlfcn_eh_frame.h | 33 + dlfcn/Makefile | 2 +- dlfcn/dlfcn.h | 2 + elf/Makefile | 33 +- elf/Versions | 3 + elf/dl-close.c | 4 + elf/dl-find_eh_frame.c | 864 ++++++++++++++++++ elf/dl-find_eh_frame.h | 90 ++ elf/dl-find_eh_frame_slow.h | 55 ++ elf/dl-libc_freeres.c | 26 + elf/dl-open.c | 5 + elf/rtld.c | 8 + elf/tst-dl_find_eh_frame-mod1.c | 10 + elf/tst-dl_find_eh_frame-mod2.c | 10 + elf/tst-dl_find_eh_frame-mod3.c | 10 + elf/tst-dl_find_eh_frame-mod4.c | 10 + elf/tst-dl_find_eh_frame-mod5.c | 11 + elf/tst-dl_find_eh_frame-mod6.c | 11 + elf/tst-dl_find_eh_frame-mod7.c | 10 + elf/tst-dl_find_eh_frame-mod8.c | 10 + elf/tst-dl_find_eh_frame-mod9.c | 10 + elf/tst-dl_find_eh_frame-threads.c | 237 +++++ elf/tst-dl_find_eh_frame.c | 179 ++++ include/atomic_wide_counter.h | 103 +++ include/bits/atomic_wide_counter.h | 1 + include/bits/dlfcn_eh_frame.h | 1 + include/link.h | 3 + malloc/set-freeres.c | 5 + manual/Makefile | 2 +- manual/dynlink.texi | 69 ++ manual/libdl.texi | 10 - manual/probes.texi | 2 +- manual/threads.texi | 2 +- misc/Makefile | 3 +- misc/atomic_wide_counter.c | 127 +++ nptl/Makefile | 13 +- nptl/pthread_cond_common.c | 204 +---- nptl/tst-cond22.c | 14 +- sysdeps/generic/ldsodefs.h | 7 + sysdeps/i386/bits/dlfcn_eh_frame.h | 34 + sysdeps/mach/hurd/i386/ld.abilist | 1 + sysdeps/nios2/bits/dlfcn_eh_frame.h | 34 + sysdeps/nptl/bits/thread-shared-types.h | 22 +- sysdeps/unix/sysv/linux/aarch64/ld.abilist | 1 + sysdeps/unix/sysv/linux/alpha/ld.abilist | 1 + sysdeps/unix/sysv/linux/arc/ld.abilist | 1 + sysdeps/unix/sysv/linux/arm/be/ld.abilist | 1 + sysdeps/unix/sysv/linux/arm/le/ld.abilist | 1 + sysdeps/unix/sysv/linux/csky/ld.abilist | 1 + sysdeps/unix/sysv/linux/hppa/ld.abilist | 1 + sysdeps/unix/sysv/linux/i386/ld.abilist | 1 + sysdeps/unix/sysv/linux/ia64/ld.abilist | 1 + .../unix/sysv/linux/m68k/coldfire/ld.abilist | 1 + .../unix/sysv/linux/m68k/m680x0/ld.abilist | 1 + sysdeps/unix/sysv/linux/microblaze/ld.abilist | 1 + .../unix/sysv/linux/mips/mips32/ld.abilist | 1 + .../sysv/linux/mips/mips64/n32/ld.abilist | 1 + .../sysv/linux/mips/mips64/n64/ld.abilist | 1 + sysdeps/unix/sysv/linux/nios2/ld.abilist | 1 + .../sysv/linux/powerpc/powerpc32/ld.abilist | 1 + .../linux/powerpc/powerpc64/be/ld.abilist | 1 + .../linux/powerpc/powerpc64/le/ld.abilist | 1 + sysdeps/unix/sysv/linux/riscv/rv32/ld.abilist | 1 + sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist | 1 + .../unix/sysv/linux/s390/s390-32/ld.abilist | 1 + .../unix/sysv/linux/s390/s390-64/ld.abilist | 1 + sysdeps/unix/sysv/linux/sh/be/ld.abilist | 1 + sysdeps/unix/sysv/linux/sh/le/ld.abilist | 1 + .../unix/sysv/linux/sparc/sparc32/ld.abilist | 1 + .../unix/sysv/linux/sparc/sparc64/ld.abilist | 1 + sysdeps/unix/sysv/linux/x86_64/64/ld.abilist | 1 + sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist | 1 + 74 files changed, 2143 insertions(+), 215 deletions(-) create mode 100644 bits/atomic_wide_counter.h create mode 100644 bits/dlfcn_eh_frame.h create mode 100644 elf/dl-find_eh_frame.c create mode 100644 elf/dl-find_eh_frame.h create mode 100644 elf/dl-find_eh_frame_slow.h create mode 100644 elf/dl-libc_freeres.c create mode 100644 elf/tst-dl_find_eh_frame-mod1.c create mode 100644 elf/tst-dl_find_eh_frame-mod2.c create mode 100644 elf/tst-dl_find_eh_frame-mod3.c create mode 100644 elf/tst-dl_find_eh_frame-mod4.c create mode 100644 elf/tst-dl_find_eh_frame-mod5.c create mode 100644 elf/tst-dl_find_eh_frame-mod6.c create mode 100644 elf/tst-dl_find_eh_frame-mod7.c create mode 100644 elf/tst-dl_find_eh_frame-mod8.c create mode 100644 elf/tst-dl_find_eh_frame-mod9.c create mode 100644 elf/tst-dl_find_eh_frame-threads.c create mode 100644 elf/tst-dl_find_eh_frame.c create mode 100644 include/atomic_wide_counter.h create mode 100644 include/bits/atomic_wide_counter.h create mode 100644 include/bits/dlfcn_eh_frame.h create mode 100644 manual/dynlink.texi delete mode 100644 manual/libdl.texi create mode 100644 misc/atomic_wide_counter.c create mode 100644 sysdeps/i386/bits/dlfcn_eh_frame.h create mode 100644 sysdeps/nios2/bits/dlfcn_eh_frame.h base-commit: 6720d36b6623c5e48c070d86acf61198b33e144e