From patchwork Fri Jun 10 09:31:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 633596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rQxlp0LKDz9sD3 for ; Fri, 10 Jun 2016 19:32:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=YTXUX5ws; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= cNOhYarEVY/LhuHz59OPNhV1lo8aVuTn8aTCM2Tp3jMPN/nVFx4YbR5cZiKYpB8D F3cE3ieLsOYSVpkbCzRDtjNMjCdN8upa02fFLCM3HkwjshyUHRBf1q89J4J1VyNA 5COv4P2Sa8S89rNEORQOOHa2NMoas487jZz7sFk3iZk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=EbBUOn aO9OMZMKGFYmqJMCMpyZA=; b=YTXUX5wsgLvy3hn0mjfCNkSN4mM1vjbRymsVrv iQnCQktFDWynrhAb76fOkVEEGvsafJL7oqHrIH77cS1Sh1QyPj7vnVRFBv0CmSW8 YBD2GFmIQ00MnT/5sVtcEPz195GLpiDwBOkLcOg8zmdTY+75wmXnILdNYiP6Ij6a NplxQ= Received: (qmail 102220 invoked by alias); 10 Jun 2016 09:31:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 102082 invoked by uid 89); 10 Jun 2016 09:31:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=*free, ms X-HELO: mx1.redhat.com Date: Fri, 10 Jun 2016 11:31:37 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Remove malloc_get_state, malloc_set_state User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20160610093137.7306E400F0E5F@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) After the removal of __malloc_initialize_hook, newly compiled Emacs binaries are no longer able to use these interfaces. malloc_get_state is only used during the Emacs build process, so we provide a stub implementation only. Existing Emacs binaries will not call this stub function, but still reference the symbol. 2016-06-10 Florian Weimer * malloc/malloc.h (malloc_get_state, malloc_set_state): Remove. * malloc/malloc.c (malloc_get_state, malloc_set_state): Remove weak aliases. * malloc/hooks.c (malloc_get_state): New stub implementation as compatibility symbo. (__malloc_get_state): Remove. (malloc_set_state): Rename from __malloc_set_state. Turn into compat symbol. * malloc/Makefile (tests): Remove tst-mallocstate. * malloc/tst-mallocstate.c: Remove file. diff --git a/NEWS b/NEWS index 9d6ac56..de2af85 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,13 @@ Version 2.24 * The deprecated __malloc_initialize_hook variable has been removed from the API. +* The __malloc_get_state and __malloc_set_state functions have been removed + from the API. __malloc_get_state has been replaced with a stub + implementation. Existing undumped Emacs binaries will have to be + recompiled so that they do not use glibc malloc (or malloc heap dumping). + Existing installed Emacs binaries (after dumping) are not affected by this + change. + Security related changes: * An unnecessary stack copy in _nss_dns_getnetbyname_r was removed. It diff --git a/malloc/Makefile b/malloc/Makefile index 91eb17d..8473f74 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -25,7 +25,7 @@ include ../Makeconfig dist-headers := malloc.h headers := $(dist-headers) obstack.h mcheck.h tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \ - tst-mallocstate tst-mcheck tst-mallocfork tst-trim1 \ + tst-mcheck tst-mallocfork tst-trim1 \ tst-malloc-usable tst-realloc tst-posix_memalign \ tst-pvalloc tst-memalign tst-mallopt tst-scratch_buffer \ tst-malloc-backtrace tst-malloc-thread-exit \ diff --git a/malloc/hooks.c b/malloc/hooks.c index caa1e70..8ef2eba 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -447,6 +447,7 @@ memalign_check (size_t alignment, size_t bytes, const void *caller) return mem2mem_check (mem, bytes); } +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_24) /* Get/set state: malloc_get_state() records the current state of all malloc variables (_except_ for the actual heap contents and `hook' @@ -492,60 +493,20 @@ struct malloc_save_state unsigned long narenas; }; +/* Dummy implementation which always fails. We need to provide this + symbol so that existing Emacs binaries continue to work with + BIND_NOW. */ void * -__malloc_get_state (void) +attribute_compat_text_section +malloc_get_state (void) { - struct malloc_save_state *ms; - int i; - mbinptr b; - - ms = (struct malloc_save_state *) __libc_malloc (sizeof (*ms)); - if (!ms) - return 0; - - (void) mutex_lock (&main_arena.mutex); - malloc_consolidate (&main_arena); - ms->magic = MALLOC_STATE_MAGIC; - ms->version = MALLOC_STATE_VERSION; - ms->av[0] = 0; - ms->av[1] = 0; /* used to be binblocks, now no longer used */ - ms->av[2] = top (&main_arena); - ms->av[3] = 0; /* used to be undefined */ - for (i = 1; i < NBINS; i++) - { - b = bin_at (&main_arena, i); - if (first (b) == b) - ms->av[2 * i + 2] = ms->av[2 * i + 3] = 0; /* empty bin */ - else - { - ms->av[2 * i + 2] = first (b); - ms->av[2 * i + 3] = last (b); - } - } - ms->sbrk_base = mp_.sbrk_base; - ms->sbrked_mem_bytes = main_arena.system_mem; - ms->trim_threshold = mp_.trim_threshold; - ms->top_pad = mp_.top_pad; - ms->n_mmaps_max = mp_.n_mmaps_max; - ms->mmap_threshold = mp_.mmap_threshold; - ms->check_action = check_action; - ms->max_sbrked_mem = main_arena.max_system_mem; - ms->max_total_mem = 0; - ms->n_mmaps = mp_.n_mmaps; - ms->max_n_mmaps = mp_.max_n_mmaps; - ms->mmapped_mem = mp_.mmapped_mem; - ms->max_mmapped_mem = mp_.max_mmapped_mem; - ms->using_malloc_checking = using_malloc_checking; - ms->max_fast = get_max_fast (); - ms->arena_test = mp_.arena_test; - ms->arena_max = mp_.arena_max; - ms->narenas = narenas; - (void) mutex_unlock (&main_arena.mutex); - return (void *) ms; + return NULL; } +compat_symbol (libc, malloc_get_state, malloc_get_state, GLIBC_2_0); int -__malloc_set_state (void *msptr) +attribute_compat_text_section +malloc_set_state (void *msptr) { struct malloc_save_state *ms = (struct malloc_save_state *) msptr; @@ -612,6 +573,9 @@ __malloc_set_state (void *msptr) return 0; } +compat_symbol (libc, malloc_set_state, malloc_set_state, GLIBC_2_0); + +#endif /* SHLIB_COMPAT */ /* * Local variables: diff --git a/malloc/malloc.c b/malloc/malloc.c index ac0f751..b054fe6 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5266,8 +5266,6 @@ strong_alias (__libc_mallopt, __mallopt) weak_alias (__libc_mallopt, mallopt) weak_alias (__malloc_stats, malloc_stats) weak_alias (__malloc_usable_size, malloc_usable_size) weak_alias (__malloc_trim, malloc_trim) -weak_alias (__malloc_get_state, malloc_get_state) -weak_alias (__malloc_set_state, malloc_set_state) /* ------------------------------------------------------------ diff --git a/malloc/malloc.h b/malloc/malloc.h index 54b1862..e0c2788 100644 --- a/malloc/malloc.h +++ b/malloc/malloc.h @@ -134,13 +134,6 @@ extern void malloc_stats (void) __THROW; /* Output information about state of allocator to stream FP. */ extern int malloc_info (int __options, FILE *__fp) __THROW; -/* Record the state of all malloc variables in an opaque data structure. */ -extern void *malloc_get_state (void) __THROW; - -/* Restore the state of all malloc variables from data obtained with - malloc_get_state(). */ -extern int malloc_set_state (void *__ptr) __THROW; - /* Hooks for debugging and user-defined versions. */ extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr, const void *) diff --git a/malloc/tst-mallocstate.c b/malloc/tst-mallocstate.c deleted file mode 100644 index a00d045..0000000 --- a/malloc/tst-mallocstate.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Wolfram Gloger , 2001. - - 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 -#include -#include "malloc.h" - -static int errors = 0; - -static void -merror (const char *msg) -{ - ++errors; - printf ("Error: %s\n", msg); -} - -static int -do_test (void) -{ - void *p1, *p2; - void *save_state; - long i; - - errno = 0; - - p1 = malloc (10); - if (p1 == NULL) - merror ("malloc (10) failed."); - - p2 = malloc (20); - if (p2 == NULL) - merror ("malloc (20) failed."); - - free (malloc (10)); - - for (i = 0; i < 100; ++i) - { - save_state = malloc_get_state (); - if (save_state == NULL) - { - merror ("malloc_get_state () failed."); - break; - } - /*free (malloc (10)); This could change the top chunk! */ - malloc_set_state (save_state); - p1 = realloc (p1, i * 4 + 4); - if (p1 == NULL) - merror ("realloc (i*4) failed."); - free (save_state); - } - - p1 = realloc (p1, 40); - free (p2); - p2 = malloc (10); - if (p2 == NULL) - merror ("malloc (10) failed."); - free (p1); - - return errors != 0; -} - -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c"