From 6a0bf43d7c5961297aa5024aec534e5bab73c8af Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 10 Nov 2011 00:14:27 -0800 Subject: [PATCH] Standardize on VIRT_ADDR_VARIES behavior; otherwise, valgrind does not work on some platforms. Problem reported by Andreas Schwab in . * puresize.h (pure, PURE_P): Always behave as if VIRT_ADDR_VARIES is set, removing the need for VIRT_ADDRESS_VARIES. (PURE_P): Use a more-efficient implementation that needs just one comparison, not two: on x86-64 with GCC 4.6.2, this cut down the number of instructions from 6 (xorl, cmpq, jge, xorl, cmpq, setge) to 4 (xorl, subq, cmpq, setbe). * alloc.c (pure): Always extern now, since that's the VIRT_ADDR_VARIES behavior. (PURE_POINTER_P): Use a single comparison, not two, for consistency with the new puresize.h. * lisp.h (PNTR_COMPARISON_TYPE): Remove; no longer needed. * m/ibms390.h, m/intel386.h, m/template.h, s/cygwin.h, s/hpux10-20.h: Remove VIRT_ADDR_VARIES no longer needed. --- src/ChangeLog | 19 +++++++++++++++++++ src/alloc.c | 8 +------- src/lisp.h | 3 --- src/m/ibms390.h | 11 +++-------- src/m/intel386.h | 2 -- src/m/template.h | 8 -------- src/puresize.h | 16 +--------------- src/s/cygwin.h | 3 --- src/s/hpux10-20.h | 8 -------- 9 files changed, 24 insertions(+), 54 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b14d6752bb9..4e56e3c8499 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2011-11-10 Paul Eggert + + Standardize on VIRT_ADDR_VARIES behavior; otherwise, valgrind + does not work on some platforms. Problem reported by Andreas Schwab in + . + * puresize.h (pure, PURE_P): Always behave as if VIRT_ADDR_VARIES + is set, removing the need for VIRT_ADDRESS_VARIES. + (PURE_P): Use a more-efficient implementation that needs just one + comparison, not two: on x86-64 with GCC 4.6.2, this cut down the + number of instructions from 6 (xorl, cmpq, jge, xorl, cmpq, setge) + to 4 (xorl, subq, cmpq, setbe). + * alloc.c (pure): Always extern now, since that's the + VIRT_ADDR_VARIES behavior. + (PURE_POINTER_P): Use a single comparison, not two, for + consistency with the new puresize.h. + * lisp.h (PNTR_COMPARISON_TYPE): Remove; no longer needed. + * m/ibms390.h, m/intel386.h, m/template.h, s/cygwin.h, s/hpux10-20.h: + Remove VIRT_ADDR_VARIES no longer needed. + 2011-11-09 Chong Yidong * window.c (Fwindow_inside_edges, Fwindow_inside_pixel_edges) diff --git a/src/alloc.c b/src/alloc.c index 985e4b71426..639a35c3f36 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -203,9 +203,6 @@ static int malloc_hysteresis; remapping on more recent systems because this is less important nowadays than in the days of small memories and timesharing. */ -#ifndef VIRT_ADDR_VARIES -static -#endif EMACS_INT pure[(PURESIZE + sizeof (EMACS_INT) - 1) / sizeof (EMACS_INT)] = {1,}; #define PUREBEG (char *) pure @@ -222,10 +219,7 @@ static ptrdiff_t pure_bytes_used_before_overflow; /* Value is non-zero if P points into pure space. */ #define PURE_POINTER_P(P) \ - (((PNTR_COMPARISON_TYPE) (P) \ - < (PNTR_COMPARISON_TYPE) ((char *) purebeg + pure_size)) \ - && ((PNTR_COMPARISON_TYPE) (P) \ - >= (PNTR_COMPARISON_TYPE) purebeg)) + ((uintptr_t) (P) - (uintptr_t) purebeg <= pure_size) /* Index in pure at which next pure Lisp object will be allocated.. */ diff --git a/src/lisp.h b/src/lisp.h index 46448f7a1fb..880de65bf65 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1877,9 +1877,6 @@ typedef struct { CHECK_NATNUM (tmp); \ XSETCDR ((x), tmp); \ } while (0) - -/* Cast pointers to this type to compare them. */ -#define PNTR_COMPARISON_TYPE uintptr_t /* Define a built-in function for calling from Lisp. `lname' should be the name to give the function in Lisp, diff --git a/src/m/ibms390.h b/src/m/ibms390.h index c309035dc5c..7269d416a48 100644 --- a/src/m/ibms390.h +++ b/src/m/ibms390.h @@ -17,11 +17,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ - -/* Define VIRT_ADDR_VARIES if the virtual addresses of - pure and impure space as loaded can vary, and even their - relative order cannot be relied on. - - Otherwise Emacs assumes that text space precedes data space, - numerically. */ -#define VIRT_ADDR_VARIES +/* This file is a placeholder -- it does not contain any definitions. + At some point we should probably fix this by removing the file + and removing all uses of it. */ diff --git a/src/m/intel386.h b/src/m/intel386.h index 16f0645715c..114b7fef963 100644 --- a/src/m/intel386.h +++ b/src/m/intel386.h @@ -19,7 +19,6 @@ along with GNU Emacs. If not, see . */ #ifdef WINDOWSNT -#define VIRT_ADDR_VARIES #define DATA_START get_data_start () #endif @@ -28,4 +27,3 @@ along with GNU Emacs. If not, see . */ /* we cannot get the maximum address for brk */ #define ULIMIT_BREAK_VALUE (32*1024*1024) #endif - diff --git a/src/m/template.h b/src/m/template.h index 54fb0da9521..38649e8ac6d 100644 --- a/src/m/template.h +++ b/src/m/template.h @@ -21,14 +21,6 @@ along with GNU Emacs. If not, see . */ does not define it automatically. Ones defined so far include m68k and many others */ -/* Define VIRT_ADDR_VARIES if the virtual addresses of - pure and impure space as loaded can vary, and even their - relative order cannot be relied on. - - Otherwise Emacs assumes that text space precedes data space, - numerically. */ -#define VIRT_ADDR_VARIES - /* After adding support for a new machine, modify the large case statement in configure.in to recognize reasonable configuration names, and add a description of the system to diff --git a/src/puresize.h b/src/puresize.h index c26c496a757..4290c30c68d 100644 --- a/src/puresize.h +++ b/src/puresize.h @@ -75,21 +75,7 @@ extern void pure_write_error (void) NO_RETURN; /* Define PURE_P. */ -#ifdef VIRT_ADDR_VARIES -/* For machines where text and data can go anywhere - in virtual memory. */ - extern EMACS_INT pure[]; #define PURE_P(obj) \ - ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE) \ - && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure) - -#else /* not VIRT_ADDR_VARIES */ - -extern char my_edata[]; - -#define PURE_P(obj) \ - ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) my_edata) - -#endif /* VIRT_ADDRESS_VARIES */ + ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE) diff --git a/src/s/cygwin.h b/src/s/cygwin.h index af5308ff7bb..8f5a0ab1fc7 100644 --- a/src/s/cygwin.h +++ b/src/s/cygwin.h @@ -91,9 +91,6 @@ along with GNU Emacs. If not, see . */ why it needed to be changed. */ #define GC_MARK_STACK GC_MAKE_GCPROS_NOOPS -/* Virtual addresses of pure and impure space can vary, as on Windows. */ -#define VIRT_ADDR_VARIES - /* Emacs supplies its own malloc, but glib (part of Gtk+) calls memalign and on Cygwin, that becomes the Cygwin-supplied memalign. As malloc is not the Cygwin malloc, the Cygwin memalign always diff --git a/src/s/hpux10-20.h b/src/s/hpux10-20.h index 1cd91a41b55..98bee64eb08 100644 --- a/src/s/hpux10-20.h +++ b/src/s/hpux10-20.h @@ -100,14 +100,6 @@ along with GNU Emacs. If not, see . */ header sections which lose when `static' is defined away, as it is on HP-UX. (You get duplicate symbol errors on linking). */ #undef _FILE_OFFSET_BITS - -/* Define VIRT_ADDR_VARIES if the virtual addresses of - pure and impure space as loaded can vary, and even their - relative order cannot be relied on. - - Otherwise Emacs assumes that text space precedes data space, - numerically. */ -#define VIRT_ADDR_VARIES /* The data segment on this machine always starts at address 0x40000000. */ #define DATA_SEG_BITS 0x40000000 -- 2.11.4.GIT