From f65fff5bb5f2f2eee3b258538f1abb70eeb911c6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 22 Feb 2015 04:25:03 +0100 Subject: [PATCH 4/5] Add musl patch to support HYBRID_MALLOC on elf systems. * src/unexelf.c (unexec): Define bss_sbrk_did_unexec. * src/gmalloc.c: Adjust for HYBRID_MALLOC in the non CYGWIN case. (__default_morecore): Here, in particular. * configure.ac: Define HYBRID_MALLOC when unexelf.o is used. New variable SHEAP_OBJ. * src/Makefile.in: Use it. Except for build system fixes this is essentially the same as http://git.alpinelinux.org/cgit/aports/tree/testing/emacs/musl.patch?id=d6f211ec868df4657c745b8ba2bae77b2a7fb7f6 The original patch contains one unrelated hunk, which will be committed separately. --- configure.ac | 12 ++++++++++-- src/Makefile.in | 6 +++++- src/gmalloc.c | 4 ++-- src/unexelf.c | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 63e354e..56e2f12 100644 --- a/configure.ac +++ b/configure.ac @@ -2117,7 +2117,13 @@ case "$opsys" in cygwin) hybrid_malloc=yes;; esac +if test "${system_malloc}" != yes && test "${doug_lea_malloc}" != yes \ + && test "${UNEXEC_OBJ}" = unexelf.o && test "${hybrid_malloc}" != no; then + hybrid_malloc=yes +fi + GMALLOC_OBJ= +SHEAP_OBJ= if test "${system_malloc}" = "yes"; then AC_DEFINE([SYSTEM_MALLOC], 1, [Define to 1 to use the system memory allocator, even if it is not @@ -2132,6 +2138,7 @@ elif test "$hybrid_malloc" = yes; then GNU_MALLOC= GNU_MALLOC_reason="only before dumping" GMALLOC_OBJ=gmalloc.o + SHEAP_OBJ=sheap.o VMLIMIT_OBJ= else test "$doug_lea_malloc" != "yes" && GMALLOC_OBJ=gmalloc.o @@ -2152,9 +2159,10 @@ else fi fi AC_SUBST(GMALLOC_OBJ) +AC_SUBST(SHEAP_OBJ) AC_SUBST(VMLIMIT_OBJ) -if test "$doug_lea_malloc" = "yes" ; then +if test "$doug_lea_malloc" = "yes" && test "$hybrid_malloc" != yes; then if test "$GNU_MALLOC" = yes ; then GNU_MALLOC_reason=" (Using Doug Lea's new malloc from the GNU C Library.)" @@ -4970,7 +4978,7 @@ fi AC_SUBST(RALLOC_OBJ) if test "$opsys" = "cygwin"; then - CYGWIN_OBJ="sheap.o cygw32.o" + CYGWIN_OBJ="cygw32.o" ## Cygwin differs because of its unexec(). PRE_ALLOC_OBJ= POST_ALLOC_OBJ=lastfile.o diff --git a/src/Makefile.in b/src/Makefile.in index f1d780f..ece8858 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -243,7 +243,10 @@ XFIXES_CFLAGS = @XFIXES_CFLAGS@ ## widget.o if USE_X_TOOLKIT, otherwise empty. WIDGET_OBJ=@WIDGET_OBJ@ -## sheap.o if CYGWIN, otherwise empty. +## sheap.o if HYBRID_MALLOC, otherwise empty. +SHEAP_OBJ=@SHEAP_OBJ@ + +## cygw32.o if CYGWIN, otherwise empty. CYGWIN_OBJ=@CYGWIN_OBJ@ ## fontset.o fringe.o image.o if we have any window system @@ -384,6 +387,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \ region-cache.o sound.o atimer.o \ doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \ profiler.o decompress.o \ + $(SHEAP_OBJ) \ $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) obj = $(base_obj) $(NS_OBJC_OBJ) diff --git a/src/gmalloc.c b/src/gmalloc.c index 240408e..530b3b2 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -70,7 +70,7 @@ extern void emacs_abort (void); #define aligned_alloc galigned_alloc #define free gfree -#ifdef CYGWIN +#ifdef HYBRID_MALLOC extern void *bss_sbrk (ptrdiff_t size); extern int bss_sbrk_did_unexec; extern char bss_sbrk_buffer[]; @@ -1542,7 +1542,7 @@ void * __default_morecore (ptrdiff_t increment) { void *result; -#if defined (CYGWIN) +#ifdef HYBRID_MALLOC if (!DUMPED) { return bss_sbrk (increment); diff --git a/src/unexelf.c b/src/unexelf.c index c10c7f2..3d10aa0 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -227,6 +227,11 @@ unexec (const char *new_name, const char *old_name) off_t new_file_size; void *new_break; +#ifdef HYBRID_MALLOC + extern int bss_sbrk_did_unexec; + bss_sbrk_did_unexec = 1; +#endif + /* Pointers to the base of the image of the two files. */ caddr_t old_base, new_base; -- 2.6.3