From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elephant.ash.relay.mailchannels.net (elephant.ash.relay.mailchannels.net [23.83.222.57]) by sourceware.org (Postfix) with ESMTPS id 8AF5E385482F for ; Mon, 19 Jul 2021 18:47:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AF5E385482F X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9C8E2402D03; Mon, 19 Jul 2021 18:47:13 +0000 (UTC) Received: from pdx1-sub0-mail-a73.g.dreamhost.com (100-96-18-103.trex-nlb.outbound.svc.cluster.local [100.96.18.103]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D2B64402E4D; Mon, 19 Jul 2021 18:47:11 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a73.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.18.103 (trex/6.3.3); Mon, 19 Jul 2021 18:47:13 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Eyes-Vacuous: 51de86f701fe96c7_1626720432927_1263472761 X-MC-Loop-Signature: 1626720432927:1185008233 X-MC-Ingress-Time: 1626720432926 Received: from pdx1-sub0-mail-a73.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a73.g.dreamhost.com (Postfix) with ESMTP id EADF88A6E6; Mon, 19 Jul 2021 11:47:09 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a73.g.dreamhost.com (Postfix) with ESMTPSA id 950CB8A6DE; Mon, 19 Jul 2021 11:47:05 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a73 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: carlos@redhat.com, dj@redhat.com, fweimer@redhat.com Subject: [PATCH v10 03/11] Remove __morecore and __default_morecore Date: Tue, 20 Jul 2021 00:16:29 +0530 Message-Id: <20210719184637.1225275-4-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719184637.1225275-1-siddhesh@sourceware.org> References: <20210719184637.1225275-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3494.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2021 18:47:20 -0000 Make the __morecore and __default_morecore symbols compat-only and remove their declarations from the API. Also, include morecore.c directly into malloc.c; this should ideally get merged into malloc in a future cleanup. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- NEWS | 5 +++++ include/stdlib.h | 3 --- malloc/Makefile | 2 +- malloc/arena.c | 12 ++---------- malloc/hooks.c | 2 ++ malloc/malloc.c | 7 +++---- malloc/malloc.h | 8 -------- malloc/morecore.c | 34 +++++++++++----------------------- 8 files changed, 24 insertions(+), 49 deletions(-) diff --git a/NEWS b/NEWS index 4df348cce5..75ad8a9b95 100644 --- a/NEWS +++ b/NEWS @@ -127,6 +127,11 @@ Deprecated and removed features, and other changes a= ffecting compatibility: mtrace. Similar functionality can be achieved by using conditional breakpoints within mtrace functions from within gdb. =20 +* The __morecore and __after_morecore_hook malloc hooks and the default + implementation __default_morecore have been removed from the API. Exi= sting + applications will continue to link against these symbols but the inter= faces + no longer have any effect on malloc. + Changes to build and runtime requirements: =20 * On Linux, the shm_open, sem_open, and related functions now expect the diff --git a/include/stdlib.h b/include/stdlib.h index 1f6e1508e4..1c6f70b082 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -306,9 +306,6 @@ libc_hidden_proto (__qfcvt_r) # define MB_CUR_MAX (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX)) # endif =20 -extern void *__default_morecore (ptrdiff_t) __THROW; -libc_hidden_proto (__default_morecore) - struct abort_msg_s { unsigned int size; diff --git a/malloc/Makefile b/malloc/Makefile index 6cac2e5d8d..ef5b485ffb 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -104,7 +104,7 @@ tests-exclude-mcheck =3D tst-mallocstate \ tests-mcheck =3D $(filter-out $(tests-exclude-mcheck), $(tests)) endif =20 -routines =3D malloc morecore mcheck mtrace obstack reallocarray \ +routines =3D malloc mcheck mtrace obstack reallocarray \ scratch_buffer_dupfree \ scratch_buffer_grow scratch_buffer_grow_preserve \ scratch_buffer_set_array_size \ diff --git a/malloc/arena.c b/malloc/arena.c index 991fc21a7e..f1693ed48f 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -274,14 +274,6 @@ next_env_entry (char ***position) #endif =20 =20 -#if defined(SHARED) || defined(USE_MTAG) -static void * -__failing_morecore (ptrdiff_t d) -{ - return (void *) MORECORE_FAILURE; -} -#endif - #ifdef SHARED extern struct dl_open_hook *_dl_open_hook; libc_hidden_proto (_dl_open_hook); @@ -310,7 +302,7 @@ ptmalloc_init (void) and that morecore does not support tagged regions, then disable it. */ if (__MTAG_SBRK_UNTAGGED) - __morecore =3D __failing_morecore; + __always_fail_morecore =3D true; =20 mtag_enabled =3D true; mtag_mmap_flags =3D __MTAG_MMAP_FLAGS; @@ -323,7 +315,7 @@ ptmalloc_init (void) generic sbrk implementation also enforces this, but it is not used on Hurd. */ if (!__libc_initial) - __morecore =3D __failing_morecore; + __always_fail_morecore =3D true; #endif =20 thread_arena =3D &main_arena; diff --git a/malloc/hooks.c b/malloc/hooks.c index 45c91d6502..4aa6dadcff 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -20,6 +20,8 @@ #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34) void weak_variable (*__after_morecore_hook) (void) =3D NULL; compat_symbol (libc, __after_morecore_hook, __after_morecore_hook, GLIBC= _2_0); +void *(*__morecore)(ptrdiff_t); +compat_symbol (libc, __morecore, __morecore, GLIBC_2_0); #endif =20 /* Hooks for debugging versions. The initial hooks just call the diff --git a/malloc/malloc.c b/malloc/malloc.c index 24e7854a0e..6e8fa9e424 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -384,12 +384,11 @@ __malloc_assert (const char *assertion, const char = *file, unsigned int line, #define TRIM_FASTBINS 0 #endif =20 - /* Definition for getting more memory from the OS. */ -#define MORECORE (*__morecore) +#include "morecore.c" + +#define MORECORE (*__glibc_morecore) #define MORECORE_FAILURE 0 -void * __default_morecore (ptrdiff_t); -void *(*__morecore)(ptrdiff_t) =3D __default_morecore; =20 /* Memory tagging. */ =20 diff --git a/malloc/malloc.h b/malloc/malloc.h index 634b7db868..17ab9ee345 100644 --- a/malloc/malloc.h +++ b/malloc/malloc.h @@ -76,14 +76,6 @@ extern void *valloc (size_t __size) __THROW __attribut= e_malloc__ extern void *pvalloc (size_t __size) __THROW __attribute_malloc__ __wur __attr_dealloc_free; =20 -/* Underlying allocation function; successive calls should return - contiguous pieces of memory. */ -extern void *(*__morecore) (ptrdiff_t __size) __MALLOC_DEPRECATED; - -/* Default value of `__morecore'. */ -extern void *__default_morecore (ptrdiff_t __size) -__THROW __attribute_malloc__ __MALLOC_DEPRECATED; - /* SVID2/XPG mallinfo structure */ =20 struct mallinfo diff --git a/malloc/morecore.c b/malloc/morecore.c index 047228779b..8168ef158c 100644 --- a/malloc/morecore.c +++ b/malloc/morecore.c @@ -15,39 +15,27 @@ License along with the GNU C Library; if not, see . */ =20 -#ifndef _MALLOC_INTERNAL -# define _MALLOC_INTERNAL -# include -#endif - -#ifndef __GNU_LIBRARY__ -# define __sbrk sbrk -#endif - -#ifdef __GNU_LIBRARY__ -/* It is best not to declare this and cast its result on foreign operati= ng - systems with potentially hostile include files. */ - -# include -# include -extern void *__sbrk (ptrdiff_t increment) __THROW; -libc_hidden_proto (__sbrk) -#endif - -#ifndef NULL -# define NULL 0 +#if defined(SHARED) || defined(USE_MTAG) +static bool __always_fail_morecore =3D false; #endif =20 /* Allocate INCREMENT more bytes of data space, and return the start of data space, or NULL on errors. If INCREMENT is negative, shrink data space. */ void * -__default_morecore (ptrdiff_t increment) +__glibc_morecore (ptrdiff_t increment) { +#if defined(SHARED) || defined(USE_MTAG) + if (__always_fail_morecore) + return NULL; +#endif + void *result =3D (void *) __sbrk (increment); if (result =3D=3D (void *) -1) return NULL; =20 return result; } -libc_hidden_def (__default_morecore) +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libc, __glibc_morecore, __default_morecore, GLIBC_2_0); +#endif --=20 2.31.1