From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#24033: Porting emacs-25 to GNU/Linux ppc64 with draft glibc 2.24 Date: Wed, 20 Jul 2016 10:02:32 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------43EA9CCB94F389846EC5B491" X-Trace: ger.gmane.org 1469001810 6553 80.91.229.3 (20 Jul 2016 08:03:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Jul 2016 08:03:30 +0000 (UTC) To: 24033@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 20 10:03:19 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bPmTO-0000Fn-Fg for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Jul 2016 10:03:18 +0200 Original-Received: from localhost ([::1]:32931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmTK-0004u3-El for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Jul 2016 04:03:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmTC-0004tn-LI for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:03:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPmT8-0005qL-AW for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:03:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmT8-0005qC-74 for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bPmT7-0007H2-Tx for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 20 Jul 2016 08:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24033 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.146900177927949 (code B ref -1); Wed, 20 Jul 2016 08:03:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Jul 2016 08:02:59 +0000 Original-Received: from localhost ([127.0.0.1]:57895 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPmT4-0007Gj-Ir for submit@debbugs.gnu.org; Wed, 20 Jul 2016 04:02:58 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPmT2-0007GT-2y for submit@debbugs.gnu.org; Wed, 20 Jul 2016 04:02:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPmSv-0005ok-Gt for submit@debbugs.gnu.org; Wed, 20 Jul 2016 04:02:51 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:56701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmSv-0005oa-Db for submit@debbugs.gnu.org; Wed, 20 Jul 2016 04:02:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmSs-0004Z7-M2 for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:02:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPmSo-0005nS-Bg for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:02:45 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:46988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPmSo-0005mu-3N for bug-gnu-emacs@gnu.org; Wed, 20 Jul 2016 04:02:42 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6B237161146 for ; Wed, 20 Jul 2016 01:02:38 -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 y3Ey7OO8DW1l for ; Wed, 20 Jul 2016 01:02:36 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1633C16114A for ; Wed, 20 Jul 2016 01:02:36 -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 nHXKyYqaeUsN for ; Wed, 20 Jul 2016 01:02:35 -0700 (PDT) Original-Received: from [192.168.1.52] (AMontpellier-656-1-464-192.w92-145.abo.wanadoo.fr [92.145.248.192]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5B8AF161146 for ; Wed, 20 Jul 2016 01:02:35 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:121291 Archived-At: This is a multi-part message in MIME format. --------------43EA9CCB94F389846EC5B491 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Tags: patch I'd like to backport the attached patch from master to emacs-25. The idea is that Emacs 25 should work with glibc 2.24 (which is still in draft form). glibc is withdrawing support for some deprecated symbols like malloc_set_state and __malloc_initialize_hook. Emacs is intended to be portable to systems lacking these symbols, but this apparently does not work on ppc64 and ppc64le platforms. As noted in , the attached patch has been tested on emacs-25 and works on the affected platforms. I've also tested it on unaffected platforms such as x86 and x86-64. This issue may be a release blocker for glibc 2.24 (this still hasn't been decided). I'd rather that Emacs didn't get in the way of the malloc performance improvements intended for glibc 2.24, and installing this patch into emacs-25 should help with that. --------------43EA9CCB94F389846EC5B491 Content-Type: text/x-patch; name="0001-Port-to-glibc-2.24-pre-release-ppc64.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Port-to-glibc-2.24-pre-release-ppc64.patch" >From 418fa48309e1886fe5e611fa07acf193f5e3f7f9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Jul 2016 15:23:14 +0200 Subject: [PATCH] Port to glibc 2.24 (pre-release) + ppc64 Backport from master. Inspired by a suggestion by Florian Weimer in: https://sourceware.org/ml/libc-alpha/2016-07/msg00425.html * configure.ac (HAVE_PERSONALITY_ADDR_NO_RANDOMIZE): Rename from HAVE_PERSONALITY_LINUX32, and check for ADDR_NO_RANDOMIZE (the crucial thing) instead of for LINUX32. All uses changed. * src/emacs.c (main) [HAVE_PERSONALITY_ADDR_NO_RANDOMIZE]: Use ADDR_NO_RANDOMIZE from personality.h rather than inventing the flag ourselves. Just set that flag, rather than also setting the persona. Do all this earlier, so as to avoid problems with calls to brk in the interim. When doing it, avoid functions like putenv that may allocate memory. Special case for __PPC64__, which needs ASLR disabled in dumped Emacs too. --- admin/CPP-DEFINES | 2 +- configure.ac | 20 +++++++++++--------- src/emacs.c | 53 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES index 796b57d..d404dee 100644 --- a/admin/CPP-DEFINES +++ b/admin/CPP-DEFINES @@ -237,7 +237,7 @@ HAVE_NET_IF_DL_H HAVE_NET_IF_H HAVE_NLIST_H HAVE_OTF_GET_VARIATION_GLYPHS -HAVE_PERSONALITY_LINUX32 +HAVE_PERSONALITY_ADDR_NO_RANDOMIZE HAVE_PNG HAVE_PNG_H HAVE_POSIX_MEMALIGN diff --git a/configure.ac b/configure.ac index 678e98e..9da23d1 100644 --- a/configure.ac +++ b/configure.ac @@ -1615,15 +1615,17 @@ AC_CHECK_HEADERS_ONCE( sys/resource.h sys/utsname.h pwd.h utmp.h util.h) -AC_MSG_CHECKING(if personality LINUX32 can be set) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#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.]) +AC_CACHE_CHECK([if personality ADDR_NO_RANDOMIZE flag exists], + [emacs_cv_personality_addr_no_randomize], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[personality (personality (0xffffffff) + | ADDR_NO_RANDOMIZE)]])], + [emacs_cv_personality_addr_no_randomize=yes], + [emacs_cv_personality_addr_no_randomize=no])]) +if test $emacs_cv_personality_addr_no_randomize = yes; then + AC_DEFINE([HAVE_PERSONALITY_ADDR_NO_RANDOMIZE], [1], + [Define to 1 if personality flag ADDR_NO_RANDOMIZE exists.]) fi # Note that Solaris has sys/sysinfo.h which defines struct diff --git a/src/emacs.c b/src/emacs.c index 5c187e7..b0e5a05 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -106,7 +106,7 @@ extern void moncontrol (int mode); #include #endif -#ifdef HAVE_PERSONALITY_LINUX32 +#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE #include #endif @@ -674,6 +674,35 @@ main (int argc, char **argv) stack_base = &dummy; + dumping = !initialized && (strcmp (argv[argc - 1], "dump") == 0 + || strcmp (argv[argc - 1], "bootstrap") == 0); + +#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE + + /* True if address randomization interferes with memory allocaiton. */ +# ifdef __PPC64__ + bool disable_aslr = true; +# else + bool disable_aslr = dumping; +# endif + + if (disable_aslr) + { + int pers = personality (0xffffffff); + if (! (pers & ADDR_NO_RANDOMIZE) + && 0 <= personality (pers | ADDR_NO_RANDOMIZE)) + { + /* Address randomization was enabled, but is now disabled. + Re-execute Emacs to get a clean slate. */ + execvp (argv[0], argv); + + /* If the exec fails, warn the user and then try without a + clean slate. */ + fprintf (stderr, "%s: %s\n", argv[0], strerror (errno)); + } + } +#endif + #ifndef CANNOT_DUMP might_dump = !initialized; #endif @@ -781,28 +810,6 @@ main (int argc, char **argv) } } - dumping = !initialized && (strcmp (argv[argc - 1], "dump") == 0 - || strcmp (argv[argc - 1], "bootstrap") == 0); - -#ifdef HAVE_PERSONALITY_LINUX32 - if (dumping && ! getenv ("EMACS_HEAP_EXEC")) - { - /* Set this so we only do this once. */ - xputenv ("EMACS_HEAP_EXEC=true"); - - /* A flag to turn off address randomization which is introduced - in linux kernel shipped with fedora core 4 */ -#define ADD_NO_RANDOMIZE 0x0040000 - personality (PER_LINUX32 | ADD_NO_RANDOMIZE); -#undef ADD_NO_RANDOMIZE - - execvp (argv[0], argv); - - /* If the exec fails, try to dump anyway. */ - emacs_perror (argv[0]); - } -#endif /* HAVE_PERSONALITY_LINUX32 */ - #if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK) && !defined (CYGWIN) /* Extend the stack space available. Don't do that if dumping, since some systems (e.g. DJGPP) might define a smaller stack -- 2.5.5 --------------43EA9CCB94F389846EC5B491--