From patchwork Wed Nov 3 16:27:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 47005 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 A98F93858404 for ; Wed, 3 Nov 2021 16:31:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A98F93858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635957090; bh=ilVLKh0yZw+V0mS/6+pzm+UNEDPDFcjyu4ZVChmoUgY=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uf+cyFO10TmonKTz94q5g72zo09Hh9pfw38lcqB2IR+NO98nTIzAwvTyZCYERAC4/ JY/MFsruIvVypHpxBzAQ/lSmUaWgyQ0QKqYm0lcnBJtZKZavlcefwIV3dFEsb/Gi95 Hg1wtLFw8WLUD7LlHsibD0SYE84qytMUYEg8sF2c= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 20CF13858439 for ; Wed, 3 Nov 2021 16:27:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20CF13858439 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-541-LE8HUvijM9KqpgT-hAW0Xg-1; Wed, 03 Nov 2021 12:27:54 -0400 X-MC-Unique: LE8HUvijM9KqpgT-hAW0Xg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53C481006AA4; Wed, 3 Nov 2021 16:27:53 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F008B60FDD; Wed, 3 Nov 2021 16:27:51 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] elf: Introduce GLRO (dl_libc_freeres), called from __libc_freeres In-Reply-To: References: X-From-Line: 0722a1636d8ad26381b8e7092715d81749037f40 Mon Sep 17 00:00:00 2001 Message-Id: <0722a1636d8ad26381b8e7092715d81749037f40.1635954168.git.fweimer@redhat.com> Date: Wed, 03 Nov 2021 17:27:49 +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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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" --- elf/Makefile | 2 +- elf/dl-libc_freeres.c | 24 ++++++++++++++++++++++++ elf/rtld.c | 1 + malloc/set-freeres.c | 5 +++++ sysdeps/generic/ldsodefs.h | 7 +++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 elf/dl-libc_freeres.c Reviewed-by: Adhemerval Zanella diff --git a/elf/Makefile b/elf/Makefile index cb9bcfb799..1c768bdf47 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -68,7 +68,7 @@ elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \ rtld-routines = rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \ dl-error-minimal dl-conflict dl-hwcaps dl-hwcaps_split dl-hwcaps-subdirs \ dl-usage dl-diagnostics dl-diagnostics-kernel dl-diagnostics-cpu \ - dl-mutex + dl-mutex dl-libc_freeres all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines) CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables diff --git a/elf/dl-libc_freeres.c b/elf/dl-libc_freeres.c new file mode 100644 index 0000000000..68f305a6f9 --- /dev/null +++ b/elf/dl-libc_freeres.c @@ -0,0 +1,24 @@ +/* Deallocating malloc'ed memory from the dynamic loader. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +void +__rtld_libc_freeres (void) +{ +} diff --git a/elf/rtld.c b/elf/rtld.c index be2d5d8e74..847141e21d 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -378,6 +378,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro = ._dl_catch_error = _rtld_catch_error, ._dl_error_free = _dl_error_free, ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft, + ._dl_libc_freeres = __rtld_libc_freeres, #ifdef HAVE_DL_DISCOVER_OSVERSION ._dl_discover_osversion = _dl_discover_osversion #endif diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c index 5c19a2725c..856ff7831f 100644 --- a/malloc/set-freeres.c +++ b/malloc/set-freeres.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "../nss/nsswitch.h" #include "../libio/libioP.h" @@ -67,6 +68,10 @@ __libc_freeres (void) call_function_static_weak (__libc_dlerror_result_free); +#ifdef SHARED + GLRO (dl_libc_freeres) (); +#endif + for (p = symbol_set_first_element (__libc_freeres_ptrs); !symbol_set_end_p (__libc_freeres_ptrs, p); ++p) free (*p); diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 1318c36dce..c26860430c 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -712,6 +712,10 @@ struct rtld_global_ro namespace. */ void (*_dl_error_free) (void *); void *(*_dl_tls_get_addr_soft) (struct link_map *); + + /* Called from __libc_shared to deallocate malloc'ed memory. */ + void (*_dl_libc_freeres) (void); + #ifdef HAVE_DL_DISCOVER_OSVERSION int (*_dl_discover_osversion) (void); #endif @@ -1416,6 +1420,9 @@ __rtld_mutex_init (void) } #endif /* !PTHREAD_IN_LIBC */ +/* Implementation of GL (dl_libc_freeres). */ +void __rtld_libc_freeres (void) attribute_hidden; + void __thread_gscope_wait (void) attribute_hidden; # define THREAD_GSCOPE_WAIT() __thread_gscope_wait ()