http://bugs.gentoo.org/221281 temacs segfaults in dump-emacs under Linux 2.6.25 Patch backported from Emacs 22 and upstream bug 900. It comprises parts of the following changes: 2008-10-21 Jan Djärv * emacs.c (main): Unconditionally set PER_LINUX32 and exec temacs when dumping if HAVE_PERSONALITY_LINUX32 is defined 2005-07-01 Masatake YAMATO * emacs.c (main): Passing ADD_NO_RANDOMIZE to `personality'. 2004-10-20 Jan Djärv * configure.in (HAVE_PERSONALITY_LINUX32): New test if PER_LINUX32 can be set. --- emacs-21.4-orig/configure.in 2008-05-11 00:02:58.000000000 +0200 +++ emacs-21.4/configure.in 2008-05-11 00:29:23.000000000 +0200 @@ -1358,6 +1358,18 @@ AC_CHECK_HEADERS(sys/select.h sys/timeb.h sys/time.h unistd.h utime.h \ linux/version.h sys/systeminfo.h termios.h limits.h string.h stdlib.h \ termcap.h stdio_ext.h fcntl.h term.h strings.h) + +AC_MSG_CHECKING(if personality LINUX32 can be set) +AC_TRY_COMPILE([#include ], [personality (PER_LINUX32)], + emacs_cv_personality_linux32=yes, + emacs_cv_personality_linux32=no) +AC_MSG_RESULT($emacs_cv_personality_linux32) + +if test $emacs_cv_personality_linux32 = yes; then + AC_DEFINE(HAVE_PERSONALITY_LINUX32, 1, + [Define to 1 if personality LINUX32 can be set.]) +fi + AC_HEADER_STDC AC_HEADER_TIME AC_DECL_SYS_SIGLIST --- emacs-21.4-orig/src/config.in 2002-07-09 00:23:31.000000000 +0200 +++ emacs-21.4/src/config.in 2008-05-11 00:13:38.000000000 +0200 @@ -183,6 +183,7 @@ #undef HAVE_UALARM #undef HAVE_SYS_WAIT_H #undef HAVE_STRINGS_H +#undef HAVE_PERSONALITY_LINUX32 #undef HAVE_LIBDNET #undef HAVE_LIBPTHREADS --- emacs-21.4-orig/src/emacs.c 2002-08-29 21:27:07.000000000 +0200 +++ emacs-21.4/src/emacs.c 2008-05-11 00:26:38.000000000 +0200 @@ -61,6 +61,13 @@ #include #endif +#ifdef HAVE_PERSONALITY_LINUX32 +#include +#ifndef ADDR_NO_RANDOMIZE +#define ADDR_NO_RANDOMIZE 0x0040000 +#endif +#endif + #ifndef O_RDWR #define O_RDWR 2 #endif @@ -763,6 +770,28 @@ } } +#ifdef HAVE_PERSONALITY_LINUX32 + /* See if there is a gap between the end of BSS and the heap. + In that case, set personality and exec ourself again. */ + if (!initialized + && (strcmp (argv[argc-1], "dump") == 0 + || strcmp (argv[argc-1], "bootstrap") == 0) + && !getenv ("EMACS_HEAP_EXEC")) + { + /* Set this so we only do this once. */ + putenv ("EMACS_HEAP_EXEC=true"); + + /* A flag to turn off address randomization which is introduced + in linux kernel shipped with fedora core 4 */ + personality (PER_LINUX32 | ADDR_NO_RANDOMIZE); + + execvp (argv[0], argv); + + /* If the exec fails, try to dump anyway. */ + perror ("execvp"); + } +#endif /* HAVE_PERSONALITY_LINUX32 */ + /* Map in shared memory, if we are using that. */ #ifdef HAVE_SHM if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args))