From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#27416: [PROPOSED] Simplify malloc replacement on glibc Date: Sat, 17 Jun 2017 17:28:18 -0700 Message-ID: <20170618002818.20744-1-eggert@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1497747257 22202 195.159.176.226 (18 Jun 2017 00:54:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Jun 2017 00:54:17 +0000 (UTC) Cc: Paul Eggert To: 27416@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 18 02:54:09 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMOTg-0005Iw-LS for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Jun 2017 02:54:08 +0200 Original-Received: from localhost ([::1]:36678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMOTm-0002HD-06 for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Jun 2017 20:54:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMOTf-0002Gw-J9 for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:54:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMOTa-0005bI-M6 for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:54:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51175) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMOTa-0005bC-IG for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dMOTa-0004ls-Bl for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Jun 2017 00:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27416 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.149774723718328 (code B ref -1); Sun, 18 Jun 2017 00:54:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Jun 2017 00:53:57 +0000 Original-Received: from localhost ([127.0.0.1]:53852 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMOTU-0004lX-PV for submit@debbugs.gnu.org; Sat, 17 Jun 2017 20:53:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42559) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMOTT-0004lK-Ah for submit@debbugs.gnu.org; Sat, 17 Jun 2017 20:53:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMOTN-0005UD-2v for submit@debbugs.gnu.org; Sat, 17 Jun 2017 20:53:50 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:40971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dMOTM-0005U9-Vp for submit@debbugs.gnu.org; Sat, 17 Jun 2017 20:53:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMOTI-0002Gh-Ru for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:53:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMOTD-0005P0-UR for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:53:44 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:51350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dMOTD-0005O2-Ky for bug-gnu-emacs@gnu.org; Sat, 17 Jun 2017 20:53:39 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 92AF51600FF for ; Sat, 17 Jun 2017 17:28:31 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id UF13I-jdlJ64; Sat, 17 Jun 2017 17:28:29 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2D8601600FE; Sat, 17 Jun 2017 17:28:29 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id sM5Yz8S1v8GC; Sat, 17 Jun 2017 17:28:29 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 0AD041600EF; Sat, 17 Jun 2017 17:28:29 -0700 (PDT) X-Mailer: git-send-email 2.9.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133717 Archived-At: This avoids the need to build lib/e-gettime.o etc. on glibc platforms, as plain lib/gettime.o will do. * configure.ac (HAVE___LIBC_MALLOC): New symbol. * lib/Makefile.in (all): Don=E2=80=99t build libegnu.a if HAVE___LIBC_MAL= LOC. * lib/gnulib.mk.in: Regenerate. * src/Makefile.in (HAVE___LIBC_MALLOC): New macro. (LIBEGNU_ARCHIVE): Use it, so that libegnu.a is not needed if HAVE___LIBC_MALLOC. * src/conf_post.h (malloc, realloc, aligned_alloc, calloc, free): Do not define as macros if HAVE___LIBC_MALLOC, since they are now defined as functions in that case. * src/gmalloc.c (hybrid_malloc, hybrid_realloc, hybrid_calloc) (hybrid_aligned_alloc, hybrid_free): Define to plain malloc etc., if HAVE___LIBC_MALLOC, since the hybrid functions replace the standard ones in that case. (malloc, realloc, calloc, free): Define to __libc_malloc etc., if HAVE___LIBC_MALLOC, as that is the way to call the standard ones in that case. (aligned_alloc): No need to declare if HAVE___LIBC_MALLOC, since we don=E2=80=99t replace it. (hybrid_aligned_alloc): Do not call aligned_alloc if HAVE___LIBC_MALLOC, since there is no __libc_aligned_alloc. Use posix_memalign instead. --- configure.ac | 3 +++ lib/Makefile.in | 2 +- lib/gnulib.mk.in | 1 + src/Makefile.in | 4 +++- src/conf_post.h | 9 ++++----- src/gmalloc.c | 16 ++++++++++++++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index ef61107..7dafd49 100644 --- a/configure.ac +++ b/configure.ac @@ -2214,6 +2214,7 @@ AC_DEFUN =20 GMALLOC_OBJ=3D HYBRID_MALLOC=3D +HAVE___LIBC_MALLOC=3D if test "${system_malloc}" =3D "yes"; then AC_DEFINE([SYSTEM_MALLOC], 1, [Define to 1 to use the system memory allocator, even if it is not @@ -2230,6 +2231,7 @@ AC_DEFUN GNU_MALLOC_reason=3D" (only before dumping)" GMALLOC_OBJ=3Dgmalloc.o VMLIMIT_OBJ=3D + AC_CHECK_FUNCS([__libc_malloc], [HAVE___LIBC_MALLOC=3D1]) else test "$doug_lea_malloc" !=3D "yes" && GMALLOC_OBJ=3Dgmalloc.o VMLIMIT_OBJ=3Dvm-limit.o @@ -2249,6 +2251,7 @@ AC_DEFUN fi fi AC_SUBST([HYBRID_MALLOC]) +AC_SUBST([HAVE___LIBC_MALLOC]) AC_SUBST(GMALLOC_OBJ) AC_SUBST(VMLIMIT_OBJ) =20 diff --git a/lib/Makefile.in b/lib/Makefile.in index ee41ea3..cd18da7 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -90,7 +90,7 @@ .c.o: e-%.o: %.c $(AM_V_CC)$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -Demacs -o $@ $< =20 -all: libgnu.a $(if $(HYBRID_MALLOC),libegnu.a) +all: libgnu.a $(if $(HYBRID_MALLOC),$(if $(HAVE___LIBC_MALLOC),,libegnu.= a)) =20 libgnu.a: $(libgnu_a_OBJECTS) $(AM_V_at)rm -f $@ diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 509089e..4afe4b3 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -522,6 +522,7 @@ HAVE_WCHAR_T =3D @HAVE_WCHAR_T@ HAVE_WINSOCK2_H =3D @HAVE_WINSOCK2_H@ HAVE_XSERVER =3D @HAVE_XSERVER@ HAVE__EXIT =3D @HAVE__EXIT@ +HAVE___LIBC_MALLOC =3D @HAVE___LIBC_MALLOC@ HYBRID_MALLOC =3D @HYBRID_MALLOC@ IMAGEMAGICK_CFLAGS =3D @IMAGEMAGICK_CFLAGS@ IMAGEMAGICK_LIBS =3D @IMAGEMAGICK_LIBS@ diff --git a/src/Makefile.in b/src/Makefile.in index 2be24ac..f1b1aeb 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -257,6 +257,7 @@ XDBE_CFLAGS =3D WIDGET_OBJ=3D@WIDGET_OBJ@ =20 HYBRID_MALLOC =3D @HYBRID_MALLOC@ +HAVE___LIBC_MALLOC =3D @HAVE___LIBC_MALLOC@ =20 ## cygw32.o if CYGWIN, otherwise empty. CYGWIN_OBJ=3D@CYGWIN_OBJ@ @@ -584,7 +585,8 @@ globals.h: =20 $(ALLOBJS): globals.h =20 -LIBEGNU_ARCHIVE =3D $(lib)/lib$(if $(HYBRID_MALLOC),e)gnu.a +LIBEGNU_ARCHIVE =3D \ + $(lib)/lib$(if $(HYBRID_MALLOC),$(if $(HAVE___LIBC_MALLOC),,e))gnu.a =20 $(LIBEGNU_ARCHIVE): $(config_h) $(MAKE) -C $(lib) all diff --git a/src/conf_post.h b/src/conf_post.h index e1d6a93..af10397 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -105,17 +105,16 @@ typedef bool bool_bf; =20 /* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use gmalloc before dumping and the system malloc after dumping. - hybrid_malloc and friends, defined in gmalloc.c, are wrappers that - accomplish this. */ -#ifdef HYBRID_MALLOC -#ifdef emacs + This is done via wrappers defined in gmalloc.c, whose names are + 'malloc' etc. if HAVE___LIBC_MALLOC is defined, and 'hybrid_malloc' + etc. otherwise. */ +#if defined HYBRID_MALLOC && !defined HAVE___LIBC_MALLOC && defined emac= s #define malloc hybrid_malloc #define realloc hybrid_realloc #define aligned_alloc hybrid_aligned_alloc #define calloc hybrid_calloc #define free hybrid_free #endif -#endif /* HYBRID_MALLOC */ =20 /* We have to go this route, rather than the old hpux9 approach of renaming the functions via macros. The system's stdlib.h has fully diff --git a/src/gmalloc.c b/src/gmalloc.c index 49f1faf..9de0079 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -1709,13 +1709,25 @@ valloc (size_t size) #undef aligned_alloc #undef free =20 +#ifdef HAVE___LIBC_MALLOC +# define hybrid_malloc malloc +# define hybrid_realloc realloc +# define hybrid_calloc calloc +# define hybrid_aligned_alloc aligned_alloc +# define hybrid_free free +# define malloc __libc_malloc +# define realloc __libc_realloc +# define calloc __libc_calloc +# define free __libc_free +#endif + #ifdef HYBRID_MALLOC /* Declare system malloc and friends. */ extern void *malloc (size_t size); extern void *realloc (void *ptr, size_t size); extern void *calloc (size_t nmemb, size_t size); extern void free (void *ptr); -#ifdef HAVE_ALIGNED_ALLOC +#if defined HAVE_ALIGNED_ALLOC && !defined HAVE___LIBC_MALLOC extern void *aligned_alloc (size_t alignment, size_t size); #elif defined HAVE_POSIX_MEMALIGN extern int posix_memalign (void **memptr, size_t alignment, size_t size)= ; @@ -1759,7 +1771,7 @@ hybrid_aligned_alloc (size_t alignment, size_t size= ) if (!DUMPED) return galigned_alloc (alignment, size); /* The following is copied from alloc.c */ -#ifdef HAVE_ALIGNED_ALLOC +#if defined HAVE_ALIGNED_ALLOC && !defined HAVE___LIBC_MALLOC return aligned_alloc (alignment, size); #else /* HAVE_POSIX_MEMALIGN */ void *p; --=20 2.9.4