From 3e377a9a6da8d55835dd695c63defad84701ba40 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Fri, 24 Apr 2009 13:11:22 +0000 Subject: [PATCH] 1.0.27.37: fix host constant leaks Various ways in which a host constant can leak through the cross-compiler into the target are plugged. 5 commit messages follow: fix host most-positive-fixnum leak in declaration Found by comparing object code for SORT-VECTOR between clisp and sbcl xc hosts. Fix most-fooative-fixnum leak in number-psxhash Gah, floats. Most cases will be more complicated to fix than this one. (Fixing things absolutely properly would be hugely difficult; this fix should do for now...) more careful cross-compiler constant-form-value We need to take values from the xc info database in preference to using SYMBOL-VALUE, otherwise we'll leak from the host. (In particular, this one was for function in debug.lisp with lambda lists of the form (&optional (n most-positive-fixnum)) deal with another host fixnum-related constant leak This time it's in the definition of the integer constants which are both fixnums and exactly representable as floats. Amazingly, just above these definitions are the ones for SB!XC:MOST-POSITIVE-FIXNUM and friends; no alarm bells were ringing... fix a fixnum leak in unix-fd type This mistake [ (deftype foo () `(integer 0 ,most-positive-fixnum)) ] seems distressingly easy to make. Not easy to guard against, either. (Aside: is it sensible to define FDs as positive fixnums?) --- src/code/target-sxhash.lisp | 4 ++-- src/code/unix.lisp | 2 +- src/compiler/constantp.lisp | 14 +++++++++++++- src/compiler/generic/early-vm.lisp | 8 ++++---- src/compiler/srctran.lisp | 2 +- version.lisp-expr | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/code/target-sxhash.lisp b/src/code/target-sxhash.lisp index 28bbf84..a3e09b4 100644 --- a/src/code/target-sxhash.lisp +++ b/src/code/target-sxhash.lisp @@ -338,8 +338,8 @@ (etypecase key (integer (sxhash key)) (float (macrolet ((frob (type) - (let ((lo (coerce most-negative-fixnum type)) - (hi (coerce most-positive-fixnum type))) + (let ((lo (coerce sb!xc:most-negative-fixnum type)) + (hi (coerce sb!xc:most-positive-fixnum type))) `(cond (;; This clause allows FIXNUM-sized integer ;; values to be handled without consing. (<= ,lo key ,hi) diff --git a/src/code/unix.lisp b/src/code/unix.lisp index 7033fee..224911a 100644 --- a/src/code/unix.lisp +++ b/src/code/unix.lisp @@ -48,7 +48,7 @@ ;;;; Lisp types used by syscalls (deftype unix-pathname () 'simple-string) -(deftype unix-fd () `(integer 0 ,most-positive-fixnum)) +(deftype unix-fd () `(integer 0 ,sb!xc:most-positive-fixnum)) (deftype unix-file-mode () '(unsigned-byte 32)) (deftype unix-pid () '(unsigned-byte 32)) diff --git a/src/compiler/constantp.lisp b/src/compiler/constantp.lisp index 85bb5b8..1468534 100644 --- a/src/compiler/constantp.lisp +++ b/src/compiler/constantp.lisp @@ -49,7 +49,19 @@ form))) (typecase form (symbol - (symbol-value form)) + ;; KLUDGE: superficially, this might look good enough: we grab + ;; the value from the info database, and if it isn't there (or + ;; is NIL, but hey) we use the host's value. This works for + ;; MOST-POSITIVE-FIXNUM and friends, but still fails for + ;; float-related constants, where there is in fact no guarantee + ;; that we can represent our target value at all in the host, + ;; so we don't try. We should rework all uses of floating + ;; point so that we never try to use a host's value, and then + ;; make some kind of assertion that we never attempt to take + ;; a host value of a constant in the CL package. + #+sb-xc-host (or (info :variable :xc-constant-value form) + (symbol-value form)) + #-sb-xc-host (symbol-value form)) (list (if (special-operator-p (car form)) (constant-special-form-value form environment envp) diff --git a/src/compiler/generic/early-vm.lisp b/src/compiler/generic/early-vm.lisp index 2a39fc3..feb1abd 100644 --- a/src/compiler/generic/early-vm.lisp +++ b/src/compiler/generic/early-vm.lisp @@ -47,13 +47,13 @@ "the fixnum closest in value to negative infinity") (def!constant most-positive-exactly-single-float-fixnum - (min #xffffff most-positive-fixnum)) + (min #xffffff sb!xc:most-positive-fixnum)) (def!constant most-negative-exactly-single-float-fixnum - (max #x-ffffff most-negative-fixnum)) + (max #x-ffffff sb!xc:most-negative-fixnum)) (def!constant most-positive-exactly-double-float-fixnum - (min #x1fffffffffffff most-positive-fixnum)) + (min #x1fffffffffffff sb!xc:most-positive-fixnum)) (def!constant most-negative-exactly-double-float-fixnum - (max #x-1fffffffffffff most-negative-fixnum)) + (max #x-1fffffffffffff sb!xc:most-negative-fixnum)) ;;;; Point where continuous area starting at dynamic-space-start bumps into ;;;; next space. diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp index 49616d4..10987c2 100644 --- a/src/compiler/srctran.lisp +++ b/src/compiler/srctran.lisp @@ -4155,7 +4155,7 @@ (start-1 (1- ,',start)) (current-heap-size (- ,',end ,',start)) (keyfun ,keyfun)) - (declare (type (integer -1 #.(1- most-positive-fixnum)) + (declare (type (integer -1 #.(1- sb!xc:most-positive-fixnum)) start-1)) (declare (type index current-heap-size)) (declare (type function keyfun)) diff --git a/version.lisp-expr b/version.lisp-expr index 963a79e..e63ce82 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.27.36" +"1.0.27.37" -- 1.7.10.4