From 08f10e02be1bb218d6edcde87b9f59dd11b40a78 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 29 May 2019 15:49:10 -0600 Subject: Move gdb's xmalloc and friends to new file 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-06-11 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-06-11 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/common/common-utils.c | 72 ----------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'gdb/common/common-utils.c') diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index 74ca938..dd839a0 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. */ -- cgit v1.1