From patchwork Thu May 30 21:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32953 Received: (qmail 95857 invoked by alias); 30 May 2019 21:30:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95804 invoked by uid 89); 30 May 2019 21:30:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=obs, 1977 X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.163) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 May 2019 21:30:53 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway21.websitewelcome.com (Postfix) with ESMTP id EBB9340109BA0 for ; Thu, 30 May 2019 16:30:51 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id WSdPhqn2cdnCeWSdPhVJel; Thu, 30 May 2019 16:30:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jN+gqRvAjvDHlAfFjOV8kL/sZqdZnUlG8l0Vk5ic9eU=; b=PnWYDaQnVOr/q2a1DRDC0qJITo gZMgK4WRL4cIozW5eUN2ZRQrre/SPo7+9pzUqfcd3vH0t8d2j3yAs9lmexnJLbwHjbF7XlLgktV/k fXyIcK0ns0UKjALbGb1EED/68; Received: from 174-29-48-168.hlrn.qwest.net ([174.29.48.168]:43126 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hWSdP-000zWh-NJ; Thu, 30 May 2019 16:30:51 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 2/2] Move gdb's xmalloc and friends to new file Date: Thu, 30 May 2019 15:30:46 -0600 Message-Id: <20190530213046.20542-3-tom@tromey.com> In-Reply-To: <20190530213046.20542-1-tom@tromey.com> References: <20190530213046.20542-1-tom@tromey.com> When "common" becomes a library, linking will cause a symbol clash, because "xmalloc" and some related symbols are defined in that library, libiberty, and readline. To work around this problem, this patch moves the clashing symbols to a new file, which is then compiled separately for both gdb and gdbserver. gdb/ChangeLog 2019-05-30 Tom Tromey * common/common-utils.c (xmalloc, xrealloc, xcalloc) (xmalloc_failed): Move to alloc.c. * alloc.c: New file. * Makefile.in (COMMON_SFILES): Add alloc.c. gdb/gdbserver/ChangeLog 2019-05-30 Tom Tromey * Makefile.in (SFILES): Add alloc.c. (OBS): Add alloc.o. (IPA_OBJS): Add alloc-ipa.o. (alloc-ipa.o): New target. (%.o: ../%.c): New pattern rule. --- gdb/ChangeLog | 7 +++ gdb/Makefile.in | 1 + gdb/alloc.c | 95 +++++++++++++++++++++++++++++++++++++++ gdb/common/common-utils.c | 72 ----------------------------- gdb/gdbserver/ChangeLog | 8 ++++ gdb/gdbserver/Makefile.in | 11 +++++ 6 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 gdb/alloc.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 0f495783600..15ec7a61b1c 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -924,6 +924,7 @@ COMMON_SFILES = \ ada-varobj.c \ addrmap.c \ agent.c \ + alloc.c \ annotate.c \ arch-utils.c \ auto-load.c \ diff --git a/gdb/alloc.c b/gdb/alloc.c new file mode 100644 index 00000000000..e6c9c215435 --- /dev/null +++ b/gdb/alloc.c @@ -0,0 +1,95 @@ +/* Shared allocation functions for GDB, the GNU debugger. + + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "common/common-defs.h" +#include "libiberty.h" +#include +#include "common/errors.h" + +/* The xmalloc() (libiberty.h) family of memory management routines. + + These are like the ISO-C malloc() family except that they implement + consistent semantics and guard against typical memory management + problems. */ + +/* NOTE: These are declared using PTR to ensure consistency with + "libiberty.h". xfree() is GDB local. */ + +PTR /* ARI: PTR */ +xmalloc (size_t size) +{ + void *val; + + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ + if (size == 0) + size = 1; + + val = malloc (size); /* ARI: malloc */ + if (val == NULL) + malloc_failure (size); + + return val; +} + +PTR /* ARI: PTR */ +xrealloc (PTR ptr, size_t size) /* ARI: PTR */ +{ + void *val; + + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ + if (size == 0) + size = 1; + + if (ptr != NULL) + val = realloc (ptr, size); /* ARI: realloc */ + else + val = malloc (size); /* ARI: malloc */ + if (val == NULL) + malloc_failure (size); + + return val; +} + +PTR /* ARI: PTR */ +xcalloc (size_t number, size_t size) +{ + void *mem; + + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ + if (number == 0 || size == 0) + { + number = 1; + size = 1; + } + + mem = calloc (number, size); /* ARI: xcalloc */ + if (mem == NULL) + malloc_failure (number * size); + + return mem; +} + +void +xmalloc_failed (size_t size) +{ + malloc_failure (size); +} diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index 74ca93810c7..dd839a0d4d1 100644 --- a/gdb/common/common-utils.c +++ b/gdb/common/common-utils.c @@ -22,84 +22,12 @@ #include "host-defs.h" #include -/* The xmalloc() (libiberty.h) family of memory management routines. - - These are like the ISO-C malloc() family except that they implement - consistent semantics and guard against typical memory management - problems. */ - -/* NOTE: These are declared using PTR to ensure consistency with - "libiberty.h". xfree() is GDB local. */ - -PTR /* ARI: PTR */ -xmalloc (size_t size) -{ - void *val; - - /* See libiberty/xmalloc.c. This function need's to match that's - semantics. It never returns NULL. */ - if (size == 0) - size = 1; - - val = malloc (size); /* ARI: malloc */ - if (val == NULL) - malloc_failure (size); - - return val; -} - -PTR /* ARI: PTR */ -xrealloc (PTR ptr, size_t size) /* ARI: PTR */ -{ - void *val; - - /* See libiberty/xmalloc.c. This function need's to match that's - semantics. It never returns NULL. */ - if (size == 0) - size = 1; - - if (ptr != NULL) - val = realloc (ptr, size); /* ARI: realloc */ - else - val = malloc (size); /* ARI: malloc */ - if (val == NULL) - malloc_failure (size); - - return val; -} - -PTR /* ARI: PTR */ -xcalloc (size_t number, size_t size) -{ - void *mem; - - /* See libiberty/xmalloc.c. This function need's to match that's - semantics. It never returns NULL. */ - if (number == 0 || size == 0) - { - number = 1; - size = 1; - } - - mem = calloc (number, size); /* ARI: xcalloc */ - if (mem == NULL) - malloc_failure (number * size); - - return mem; -} - void * xzalloc (size_t size) { return xcalloc (1, size); } -void -xmalloc_failed (size_t size) -{ - malloc_failure (size); -} - /* Like asprintf/vasprintf but get an internal_error if the call fails. */ diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index f5fc55034ee..a0793e657c5 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -197,6 +197,7 @@ SFILES = \ $(srcdir)/arch/arm-get-next-pcs.c \ $(srcdir)/arch/arm-linux.c \ $(srcdir)/arch/ppc-linux-common.c \ + $(srcdir)/../alloc.c \ $(srcdir)/common/btrace-common.c \ $(srcdir)/common/buffer.c \ $(srcdir)/common/cleanups.c \ @@ -238,6 +239,7 @@ SOURCES = $(SFILES) TAGFILES = $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS} OBS = \ + alloc.o \ ax.o \ common/agent.o \ common/btrace-common.o \ @@ -413,6 +415,7 @@ gdbreplay$(EXEEXT): $(sort $(GDBREPLAY_OBS)) $(LIBGNU) $(LIBIBERTY) $(LIBIBERTY) IPA_OBJS = \ + alloc-ipa.o \ ax-ipa.o \ common/common-utils-ipa.o \ common/errors-ipa.o \ @@ -568,6 +571,10 @@ ax.o: ax.c $(COMPILE) $(WARN_CFLAGS_NO_FORMAT) $< $(POSTCOMPILE) +alloc-ipa.o: ../alloc.c + $(IPAGENT_COMPILE) $(WARN_CFLAGS_NO_FORMAT) $< + $(POSTCOMPILE) + # Rules for objects that go in the in-process agent. arch/%-ipa.o: ../arch/%.c @@ -623,6 +630,10 @@ common/%.o: ../common/%.c $(COMPILE) $< $(POSTCOMPILE) +%.o: ../%.c + $(COMPILE) $< + $(POSTCOMPILE) + # Rules for register format descriptions. Suffix destination files with # -generated to identify and clean them easily.