From patchwork Tue Jul 6 18:09:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1501453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=PG04hw3a; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GK9hp31x3z9sWX for ; Wed, 7 Jul 2021 04:15:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18F3D3893C57 for ; Tue, 6 Jul 2021 18:15:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18F3D3893C57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625595336; bh=vYoZUll0C4rVlDdiob2vBuULBxH56A+p3cZ92mOCIrk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PG04hw3ajidx5QtnpgrjyBQwsuyTVnoz4RzbtNn9xf9FvBX75sGGA9NTnOJsQH7At Lk5iMM84q8NUGBgVyeHxqdbej6Pwy/QcHet6B5nnmWo73M78FPpf9D0NOd+dMMx62w 77mLIRxQOKl//ZR3gaN6ERllV/ZzwNlqKmfhzCYg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from butterfly.birch.relay.mailchannels.net (butterfly.birch.relay.mailchannels.net [23.83.209.27]) by sourceware.org (Postfix) with ESMTPS id 387E53892463 for ; Tue, 6 Jul 2021 18:10:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 387E53892463 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 43F11781E38; Tue, 6 Jul 2021 18:10:15 +0000 (UTC) Received: from pdx1-sub0-mail-a29.g.dreamhost.com (100-96-16-83.trex.outbound.svc.cluster.local [100.96.16.83]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 735AF781C50; Tue, 6 Jul 2021 18:10:14 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a29.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.16.83 (trex/6.3.3); Tue, 06 Jul 2021 18:10:15 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Wipe-Thread: 774728612a6ac60c_1625595015079_1926059868 X-MC-Loop-Signature: 1625595015079:1063832569 X-MC-Ingress-Time: 1625595015078 Received: from pdx1-sub0-mail-a29.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a29.g.dreamhost.com (Postfix) with ESMTP id 281BD7EC6B; Tue, 6 Jul 2021 11:10:14 -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-a29.g.dreamhost.com (Postfix) with ESMTPSA id C42DD7F039; Tue, 6 Jul 2021 11:10:10 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a29 To: libc-alpha@sourceware.org Subject: [PATCH v6 8/8] Remove __morecore and __default_morecore Date: Tue, 6 Jul 2021 23:39:24 +0530 Message-Id: <20210706180924.95047-9-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210706180924.95047-1-siddhesh@sourceware.org> References: <20210706180924.95047-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Make the __morecore and __default_morecore symbols compat-only and remove their declarations from the API. --- NEWS | 5 +++++ include/stdlib.h | 3 --- malloc/arena.c | 12 ++---------- malloc/hooks.c | 2 ++ malloc/malloc-internal.h | 5 +++++ malloc/malloc.c | 4 +--- malloc/malloc.h | 8 -------- malloc/morecore.c | 15 +++++++++++++-- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index 4fd4ff0e90..038420a621 100644 --- a/NEWS +++ b/NEWS @@ -113,6 +113,11 @@ Deprecated and removed features, and other changes affecting compatibility: future release of the GNU C Library. Users may port away from these hooks by writing and preloading their own malloc interposition library. +* The __morecore and __after_morecore_hook malloc hooks and the default + implementation __default_morecore have been removed from the API. Existing + applications will continue to link against these symbols but the interfaces + no longer have any effect on malloc. + Changes to build and runtime requirements: * 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 -extern void *__default_morecore (ptrdiff_t) __THROW; -libc_hidden_proto (__default_morecore) - struct abort_msg_s { unsigned int size; diff --git a/malloc/arena.c b/malloc/arena.c index 1ae57f43d5..0650b05c79 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -266,14 +266,6 @@ next_env_entry (char ***position) #endif -#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); @@ -294,7 +286,7 @@ ptmalloc_init (void) and that morecore does not support tagged regions, then disable it. */ if (__MTAG_SBRK_UNTAGGED) - __morecore = __failing_morecore; + __always_fail_morecore = true; mtag_enabled = true; mtag_mmap_flags = __MTAG_MMAP_FLAGS; @@ -307,7 +299,7 @@ ptmalloc_init (void) generic sbrk implementation also enforces this, but it is not used on Hurd. */ if (!__libc_initial) - __morecore = __failing_morecore; + __always_fail_morecore = true; #endif thread_arena = &main_arena; diff --git a/malloc/hooks.c b/malloc/hooks.c index 166160bc98..bba80c536a 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -46,6 +46,8 @@ compat_symbol (libc, __memalign_hook, __memalign_hook, GLIBC_2_0); void weak_variable (*__after_morecore_hook) (void) = 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); /* This is interposed by libc_malloc_debug.so to match with a compatible libc. We don't use dlsym or equivalent because the dlsym symbol version got bumped diff --git a/malloc/malloc-internal.h b/malloc/malloc-internal.h index 258f29584e..611aa97762 100644 --- a/malloc/malloc-internal.h +++ b/malloc/malloc-internal.h @@ -21,6 +21,7 @@ #include #include +#include /* INTERNAL_SIZE_T is the word-size used for internal bookkeeping of chunk sizes. @@ -62,6 +63,8 @@ #define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1) +extern bool __always_fail_morecore attribute_hidden; + /* Called in the parent process before a fork. */ void __malloc_fork_lock_parent (void) attribute_hidden; @@ -77,4 +80,6 @@ void __malloc_arena_thread_freeres (void) attribute_hidden; /* Activate a standard set of debugging hooks. */ void __malloc_check_init (void) attribute_hidden; +extern void *__glibc_morecore (ptrdiff_t) attribute_hidden; + #endif /* _MALLOC_INTERNAL_H */ diff --git a/malloc/malloc.c b/malloc/malloc.c index 00fcc676a0..0b8c6d9086 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -382,10 +382,8 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line, /* Definition for getting more memory from the OS. */ -#define MORECORE (*__morecore) +#define MORECORE (*__glibc_morecore) #define MORECORE_FAILURE 0 -void * __default_morecore (ptrdiff_t); -void *(*__morecore)(ptrdiff_t) = __default_morecore; /* Memory tagging. */ diff --git a/malloc/malloc.h b/malloc/malloc.h index d066a05d82..2df0b38050 100644 --- a/malloc/malloc.h +++ b/malloc/malloc.h @@ -76,14 +76,6 @@ extern void *valloc (size_t __size) __THROW __attribute_malloc__ extern void *pvalloc (size_t __size) __THROW __attribute_malloc__ __wur __attr_dealloc_free; -/* 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 */ struct mallinfo diff --git a/malloc/morecore.c b/malloc/morecore.c index 047228779b..c85a85c0eb 100644 --- a/malloc/morecore.c +++ b/malloc/morecore.c @@ -38,16 +38,27 @@ libc_hidden_proto (__sbrk) # define NULL 0 #endif +#if defined(SHARED) || defined(USE_MTAG) +bool __always_fail_morecore = false; +#endif + /* 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 = (void *) __sbrk (increment); if (result == (void *) -1) return NULL; 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