X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcold%2Fshared.lisp;h=985a444d1bfba4372857fbf3ff99c4f8a57ae147;hb=3eb39e017e52b5d704e7d33405c873af52a533fd;hp=75a3b0470486a16c0dcc858ec1f8859bad2580d3;hpb=334af30b26555f0bf706f7157b399bdbd4fad548;p=sbcl.git diff --git a/src/cold/shared.lisp b/src/cold/shared.lisp index 75a3b04..985a444 100644 --- a/src/cold/shared.lisp +++ b/src/cold/shared.lisp @@ -15,25 +15,13 @@ ;;;; provided with absolutely no warranty. See the COPYING and CREDITS ;;;; files for more information. -;;; TO DO: Might it be possible to increase the efficiency of CMU CL's garbage -;;; collection on my large (256Mb) machine by doing larger incremental GC steps -;;; than the default 2 Mb of CMU CL 2.4.9? A quick test 19990729, setting this -;;; to 5E6 showed no significant improvement, but it's possible that more -;;; cleverness might help.. -;#+cmu (setf ext:*bytes-consed-between-gcs* (* 5 (expt 10 6))) - -;;; FIXME: I'm now inclined to make all the bootstrap stuff run in CL-USER -;;; instead of SB-COLD. If I do so, I should first take care to -;;; UNINTERN any old stuff in CL-USER, since ANSI says (11.1.2.2, "The -;;; COMMON-LISP-USER Package") that CL-USER can have arbitrary symbols in -;;; it. (And of course I should set the USE list to only CL.) +;;; SB-COLD holds stuff used to build the initial SBCL core file +;;; (including not only the final construction of the core file, but +;;; also the preliminary steps like e.g. building the cross-compiler +;;; and running the cross-compiler to produce target FASL files). (defpackage "SB-COLD" (:use "CL")) -(in-package "SB-COLD") -;;; prefix for source filename stems when cross-compiling -(defvar *src-prefix* "src/") -;;; (We don't bother to specify the source suffix here because ".lisp" is such -;;; a good default value that we never have to specify it explicitly.) +(in-package "SB-COLD") ;;; prefixes for filename stems when cross-compiling. These are quite arbitrary ;;; (although of course they shouldn't collide with anything we don't want to @@ -41,19 +29,32 @@ ;;; "host-objects/" or absolute pathnames (e.g. "/tmp/sbcl-xc-host-objects/"). ;;; ;;; The cross-compilation process will force the creation of these directories -;;; by executing CL:ENSURE-DIRECTORIES-EXIST (on the host Common Lisp). +;;; by executing CL:ENSURE-DIRECTORIES-EXIST (on the xc host Common Lisp). (defvar *host-obj-prefix*) (defvar *target-obj-prefix*) -;;; suffixes for filename stems when cross-compiling. Everything should work -;;; fine for any arbitrary string values here. With more work maybe we -;;; could cause these automatically to become the traditional extensions for -;;; whatever host and target architectures (e.g. ".x86f" or ".axpf") we're -;;; currently doing. That would make it easier for a human looking at the -;;; temporary files to figure out what they're for, but it's not necessary for -;;; the compilation process to work, so we haven't bothered. -(defvar *host-obj-suffix* ".lisp-obj") -(defvar *target-obj-suffix* ".lisp-obj") +;;; suffixes for filename stems when cross-compiling +(defvar *host-obj-suffix* + (or + ;; On some xc hosts, it's impossible to LOAD a fasl file unless it + ;; has the same extension that the host uses for COMPILE-FILE + ;; output, so we have to be careful to use the xc host's preferred + ;; extension. + ;; + ;; FIXME: This is a little ugly and annoying to maintain. And + ;; there's very likely some way to rearrange the build process so + ;; that we never explicitly refer to host object file suffixes, + ;; only to the result of CL:COMPILE-FILE-PATHNAME. + #+lispworks ".ufsl" ; as per Lieven Marchand sbcl-devel 2002-02-01 + #+openmcl ".pfsl" + ;; On most xc hosts, any old extension works, so we use an + ;; arbitrary one. + ".lisp-obj")) +(defvar *target-obj-suffix* + ;; Target fasl files are LOADed (actually only quasi-LOADed, in + ;; GENESIS) only by SBCL code, and it doesn't care about particular + ;; extensions, so we can use something arbitrary. + ".lisp-obj") ;;; a function of one functional argument, which calls its functional argument ;;; in an environment suitable for compiling the target. (This environment @@ -85,24 +86,26 @@ ;;; able to get rid of this function and use plain RENAME-FILE in the ;;; COMPILE-STEM function above. -- WHN 19990321 (defun rename-file-a-la-unix (x y) - (rename-file x - ;; (Note that the TRUENAME expression here is lifted from an - ;; example in the ANSI spec for TRUENAME.) - (with-open-file (stream y :direction :output) - (close stream) - ;; From the ANSI spec: "In this case, the file is closed - ;; when the truename is tried, so the truename - ;; information is reliable." - (truename stream)))) + + (let ((path ;; (Note that the TRUENAME expression here is lifted from an + ;; example in the ANSI spec for TRUENAME.) + (with-open-file (stream y :direction :output) + (close stream) + ;; From the ANSI spec: "In this case, the file is closed + ;; when the truename is tried, so the truename + ;; information is reliable." + (truename stream)))) + (delete-file path) + (rename-file x path))) (compile 'rename-file-a-la-unix) ;;; a wrapper for compilation/assembly, used mostly to centralize ;;; the procedure for finding full filenames from "stems" ;;; ;;; Compile the source file whose basic name is STEM, using some -;;; standard-for-the-SBCL-build-process procedures to generate the full -;;; pathnames of source file and object file. Return the pathname of the object -;;; file for STEM. Several &KEY arguments are accepted: +;;; standard-for-the-SBCL-build-process procedures to generate the +;;; full pathnames of source file and object file. Return the pathname +;;; of the object file for STEM. Several &KEY arguments are accepted: ;;; :SRC-PREFIX, :SRC-SUFFIX = ;;; strings to be concatenated to STEM to produce source filename ;;; :OBJ-PREFIX, :OBJ-SUFFIX = @@ -111,11 +114,12 @@ ;;; string to be appended to the name of an object file to produce ;;; the name of a temporary object file ;;; :COMPILE-FILE, :IGNORE-FAILURE-P = -;;; :COMPILE-FILE is a function to use for compiling the file (with the -;;; same calling conventions as ANSI CL:COMPILE-FILE). If the third -;;; return value (FAILURE-P) of this function is true, a continuable -;;; error will be signalled, unless :IGNORE-FAILURE-P is set, in which -;;; case only a warning will be signalled. +;;; :COMPILE-FILE is a function to use for compiling the file +;;; (with the same calling conventions as ANSI CL:COMPILE-FILE). +;;; If the third return value (FAILURE-P) of this function is +;;; true, a continuable error will be signalled, unless +;;; :IGNORE-FAILURE-P is set, in which case only a warning will be +;;; signalled. (defun compile-stem (stem &key (obj-prefix "") @@ -126,69 +130,90 @@ (compile-file #'compile-file) ignore-failure-p) - (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common - ;; Lisp Way, although it works just fine for common UNIX environments. - ;; Should it come to pass that the system is ported to environments - ;; where version numbers and so forth become an issue, it might become - ;; urgent to rewrite this using the fancy Common Lisp PATHNAME - ;; machinery instead of just using strings. In the absence of such a - ;; port, it might or might be a good idea to do the rewrite. - ;; -- WHN 19990815 - (src (concatenate 'string src-prefix stem src-suffix)) - (obj (concatenate 'string obj-prefix stem obj-suffix)) - (tmp-obj (concatenate 'string obj tmp-obj-suffix-suffix))) - - (ensure-directories-exist obj :verbose t) - - ;; We're about to set about building a new object file. First, we - ;; delete any preexisting object file in order to avoid confusing - ;; ourselves later should we happen to bail out of compilation with an - ;; error. - (when (probe-file obj) - (delete-file obj)) - - ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP mangles - ;; relative pathnames passed as :OUTPUT-FILE arguments, but works OK - ;; with absolute pathnames. - #+clisp - (setf tmp-obj - ;; (Note that this idiom is taken from the ANSI documentation - ;; for TRUENAME.) - (with-open-file (stream tmp-obj :direction :output) - (close stream) - (truename stream))) - - ;; Try to use the compiler to generate a new temporary object file. - (multiple-value-bind (output-truename warnings-p failure-p) - (funcall compile-file src :output-file tmp-obj) - (declare (ignore warnings-p)) - (cond ((not output-truename) - (error "couldn't compile ~S" src)) - (failure-p - (if ignore-failure-p - (warn "ignoring FAILURE-P return value from compilation of ~S" - src) - (unwind-protect - (progn - ;; FIXME: This should have another option, redoing - ;; compilation. - (cerror "Continue, using possibly-bogus ~S." - "FAILURE-P was set when creating ~S." - obj) - (setf failure-p nil)) - ;; Don't leave failed object files lying around. - (when (and failure-p (probe-file tmp-obj)) - (delete-file tmp-obj) - (format t "~&deleted ~S~%" tmp-obj))))) - ;; Otherwise: success, just fall through. - (t nil))) - - ;; If we get to here, compilation succeeded, so it's OK to rename the - ;; temporary output file to the permanent object file. - (rename-file-a-la-unix tmp-obj obj) - - ;; nice friendly traditional return value - (pathname obj))) + (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common + ;; Lisp Way, although it works just fine for common UNIX environments. + ;; Should it come to pass that the system is ported to environments + ;; where version numbers and so forth become an issue, it might become + ;; urgent to rewrite this using the fancy Common Lisp PATHNAME + ;; machinery instead of just using strings. In the absence of such a + ;; port, it might or might be a good idea to do the rewrite. + ;; -- WHN 19990815 + (src (concatenate 'string src-prefix stem src-suffix)) + (obj (concatenate 'string obj-prefix stem obj-suffix)) + (tmp-obj (concatenate 'string obj tmp-obj-suffix-suffix))) + + (ensure-directories-exist obj :verbose t) + + ;; We're about to set about building a new object file. First, we + ;; delete any preexisting object file in order to avoid confusing + ;; ourselves later should we happen to bail out of compilation + ;; with an error. + (when (probe-file obj) + (delete-file obj)) + + ;; Original comment: + ;; + ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP + ;; mangles relative pathnames passed as :OUTPUT-FILE arguments, + ;; but works OK with absolute pathnames. + ;; + ;; following discussion on cmucl-imp 2002-07 + ;; "COMPILE-FILE-PATHNAME", it would seem safer to deal with + ;; absolute pathnames all the time; it is no longer clear that the + ;; original behaviour in CLISP was wrong or that the current + ;; behaviour is right; and in any case absolutifying the pathname + ;; insulates us against changes of behaviour. -- CSR, 2002-08-09 + (setf tmp-obj + ;; (Note that this idiom is taken from the ANSI + ;; documentation for TRUENAME.) + (with-open-file (stream tmp-obj :direction :output) + (close stream) + (truename stream))) + ;; and some compilers (e.g. OpenMCL) will complain if they're + ;; asked to write over a file that exists already (and isn't + ;; recognizeably a fasl file), so + (when (probe-file tmp-obj) + (delete-file tmp-obj)) + + ;; Try to use the compiler to generate a new temporary object file. + (flet ((report-recompile-restart (stream) + (format stream "Recompile file ~S" src)) + (report-continue-restart (stream) + (format stream "Continue, using possibly bogus file ~S" obj))) + (tagbody + retry-compile-file + (multiple-value-bind (output-truename warnings-p failure-p) + (funcall compile-file src :output-file tmp-obj) + (declare (ignore warnings-p)) + (cond ((not output-truename) + (error "couldn't compile ~S" src)) + (failure-p + (if ignore-failure-p + (warn "ignoring FAILURE-P return value from compilation of ~S" + src) + (unwind-protect + (restart-case + (error "FAILURE-P was set when creating ~S." + obj) + (recompile () + :report report-recompile-restart + (go retry-compile-file)) + (continue () + :report report-continue-restart + (setf failure-p nil))) + ;; Don't leave failed object files lying around. + (when (and failure-p (probe-file tmp-obj)) + (delete-file tmp-obj) + (format t "~&deleted ~S~%" tmp-obj))))) + ;; Otherwise: success, just fall through. + (t nil))))) + + ;; If we get to here, compilation succeeded, so it's OK to rename + ;; the temporary output file to the permanent object file. + (rename-file-a-la-unix tmp-obj obj) + + ;; nice friendly traditional return value + (pathname obj))) (compile 'compile-stem) ;;; other miscellaneous tools @@ -224,6 +249,20 @@ (format t "target features *SHEBANG-FEATURES*=~@<~S~:>~%" *shebang-features*)) + +(defvar *shebang-backend-subfeatures* + (let* ((default-subfeatures nil) + (customizer-file-name "customize-backend-subfeatures.lisp") + (customizer (if (probe-file customizer-file-name) + (compile nil + (read-from-file customizer-file-name)) + #'identity))) + (funcall customizer default-subfeatures))) +(let ((*print-length* nil) + (*print-level* nil)) + (format t + "target backend-subfeatures *SHEBANG-BACKEND-FEATURES*=~@<~S~:>~%" + *shebang-backend-subfeatures*)) ;;;; cold-init-related PACKAGE and SYMBOL tools @@ -232,11 +271,11 @@ ;;; values of special variables such as *** and +, anyway). Set up ;;; machinery to warn us when/if we change it. ;;; -;;; FIXME: All this machinery should probably be conditional on -;;; #!+SB-SHOW, i.e. we should be able to wrap #!+SB-SHOW around both -;;; the LOAD and the DEFVAR here. -(load "src/cold/snapshot.lisp") -(defvar *cl-snapshot* (take-snapshot "COMMON-LISP")) +;;; All code depending on this is itself dependent on #!+SB-SHOW. +#!+sb-show +(progn + (load "src/cold/snapshot.lisp") + (defvar *cl-snapshot* (take-snapshot "COMMON-LISP"))) ;;;; master list of source files and their properties @@ -263,9 +302,9 @@ ;; warnings and remove support for this flag. -- WHN 19990323) :ignore-failure-p)) -(defparameter *stems-and-flags* (read-from-file "stems-and-flags.lisp-expr")) +(defparameter *stems-and-flags* (read-from-file "build-order.lisp-expr")) -(defmacro for-stems-and-flags ((stem flags) &body body) +(defmacro do-stems-and-flags ((stem flags) &body body) (let ((stem-and-flags (gensym "STEM-AND-FLAGS-"))) `(dolist (,stem-and-flags *stems-and-flags*) (let ((,stem (first ,stem-and-flags)) @@ -274,9 +313,9 @@ ;;; Check for stupid typos in FLAGS list keywords. (let ((stems (make-hash-table :test 'equal))) - (for-stems-and-flags (stem flags) + (do-stems-and-flags (stem flags) (if (gethash stem stems) - (error "duplicate stem ~S in stems-and-flags data" stem) + (error "duplicate stem ~S in *STEMS-AND-FLAGS*" stem) (setf (gethash stem stems) t)) (let ((set-difference (set-difference flags *expected-stem-flags*))) (when set-difference @@ -296,24 +335,24 @@ :sb-propagate-fun-type)))) (with-additional-nickname ("SB-XC" "SB!XC") (funcall fn)))) -;;; FIXME: This COMPILE caused problems in sbcl-0.6.11.26. (bug 93) -;;;(compile 'in-host-compilation-mode) +(compile 'in-host-compilation-mode) ;;; Process a file as source code for the cross-compiler, compiling it ;;; (if necessary) in the appropriate environment, then loading it ;;; into the cross-compilation host Common lisp. (defun host-cload-stem (stem &key ignore-failure-p) - (load (in-host-compilation-mode - (lambda () - (compile-stem stem - :src-prefix *src-prefix* - :obj-prefix *host-obj-prefix* - :obj-suffix *host-obj-suffix* - :compile-file #'cl:compile-file - :ignore-failure-p ignore-failure-p))))) + (let ((compiled-filename (in-host-compilation-mode + (lambda () + (compile-stem + stem + :obj-prefix *host-obj-prefix* + :obj-suffix *host-obj-suffix* + :compile-file #'cl:compile-file + :ignore-failure-p ignore-failure-p))))) + (load compiled-filename))) (compile 'host-cload-stem) -;;; Like HOST-CLOAD-STEM, except that we don't bother to compile. +;;; like HOST-CLOAD-STEM, except that we don't bother to compile (defun host-load-stem (stem &key ignore-failure-p) (declare (ignore ignore-failure-p)) ; (It's only relevant when ;; compiling.) KLUDGE: It's untidy to have the knowledge of how to @@ -332,7 +371,6 @@ (funcall *in-target-compilation-mode-fn* (lambda () (compile-stem stem - :src-prefix *src-prefix* :obj-prefix *target-obj-prefix* :obj-suffix *target-obj-suffix* :ignore-failure-p ignore-failure-p