1 ;;;; stuff which is not specific to any particular build phase, but
2 ;;;; used by most of them
4 ;;;; Note: It's specifically not used when bootstrapping PCL, because
5 ;;;; we do SAVE-LISP after that, and we don't want to save extraneous
6 ;;;; bootstrapping machinery into the frozen image which will
7 ;;;; subsequently be used as the mother of all Lisp sessions.
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
12 ;;;; This software is derived from the CMU CL system, which was
13 ;;;; written at Carnegie Mellon University and released into the
14 ;;;; public domain. The software is in the public domain and is
15 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
16 ;;;; files for more information.
18 ;;; GC tuning has little effect on the x86 due to the generational
19 ;;; collector. For the older stop & copy collector, it assuredly
20 ;;; does. GC time is proportional to the amount of non-garbage
21 ;;; needing collection and copying; when the application involved is
22 ;;; the SBCL compiler, it doesn't take any longer to collect 20 Mb than
23 ;;; to collect 2 Mb. -dan, 20000819
25 ;;; Actually, tweaking *BYTES-CONSED-BETWEEN-GCS* to 20Mb instead of
26 ;;; the default 2 seemed to make SBCL rebuild O(25%) faster on my 256
27 ;;; Mb K6/3, so I think it does have some effect on X86/GENCGC. I
28 ;;; haven't looked into why this would be, though. Also, I'm afraid
29 ;;; that using 20Mb here might be unfriendly to people using more-reasonable
30 ;;; machines (like old laptops with 48Mb of memory..) so I've
31 ;;; suppressed this tweak except for Alpha. -- WHN 2001-05-11
32 #+(and sbcl alpha) ; SBCL/Alpha uses stop-and-copy, and Alphas have lotso RAM.
35 (setf (sb-ext:bytes-consed-between-gcs) (* 20 (expt 10 6)))
39 ;;; FIXME: I'm now inclined to make all the bootstrap stuff run in CL-USER
40 ;;; instead of SB-COLD. If I do so, I should first take care to
41 ;;; UNINTERN any old stuff in CL-USER, since ANSI says (11.1.2.2, "The
42 ;;; COMMON-LISP-USER Package") that CL-USER can have arbitrary symbols in
43 ;;; it. (And of course I should set the USE list to only CL.)
44 (defpackage "SB-COLD" (:use "CL"))
45 (in-package "SB-COLD")
47 ;;; prefixes for filename stems when cross-compiling. These are quite arbitrary
48 ;;; (although of course they shouldn't collide with anything we don't want to
49 ;;; write over). In particular, they can be either relative path names (e.g.
50 ;;; "host-objects/" or absolute pathnames (e.g. "/tmp/sbcl-xc-host-objects/").
52 ;;; The cross-compilation process will force the creation of these directories
53 ;;; by executing CL:ENSURE-DIRECTORIES-EXIST (on the host Common Lisp).
54 (defvar *host-obj-prefix*)
55 (defvar *target-obj-prefix*)
57 ;;; suffixes for filename stems when cross-compiling. Everything
58 ;;; should work fine for any arbitrary string values here. With more
59 ;;; work maybe we could cause these automatically to become the
60 ;;; traditional extensions for whatever host and target architectures
61 ;;; (e.g. ".x86f" or ".axpf") we're currently doing. That would make
62 ;;; it easier for a human looking at the temporary files to figure out
63 ;;; what they're for, but it's not necessary for the compilation
64 ;;; process to work, so we haven't bothered.
65 (defvar *host-obj-suffix* ".lisp-obj")
66 (defvar *target-obj-suffix* ".lisp-obj")
68 ;;; a function of one functional argument, which calls its functional argument
69 ;;; in an environment suitable for compiling the target. (This environment
70 ;;; includes e.g. a suitable *FEATURES* value.)
71 (defvar *in-target-compilation-mode-fn*)
73 ;;; designator for a function with the same calling convention as
74 ;;; CL:COMPILE-FILE, to be used to translate ordinary Lisp source files into
75 ;;; target object files
76 (defvar *target-compile-file*)
78 ;;; designator for a function with the same calling convention as
79 ;;; SB-C:ASSEMBLE-FILE, to be used to translate assembly files into target
81 (defvar *target-assemble-file*)
85 ;;; Take the file named X and make it into a file named Y. Sorta like
86 ;;; UNIX, and unlike Common Lisp's bare RENAME-FILE, we don't allow
87 ;;; information from the original filename to influence the final
88 ;;; filename. (The reason that it's only sorta like UNIX is that in
89 ;;; UNIX "mv foo bar/" will work, but the analogous
90 ;;; (RENAME-FILE-A-LA-UNIX "foo" "bar/") should fail.)
92 ;;; (This is a workaround for the weird behavior of Debian CMU CL
93 ;;; 2.4.6, where (RENAME-FILE "dir/x" "dir/y") tries to create a file
94 ;;; called "dir/dir/y". If that behavior goes away, then we should be
95 ;;; able to get rid of this function and use plain RENAME-FILE in the
96 ;;; COMPILE-STEM function above. -- WHN 19990321
97 (defun rename-file-a-la-unix (x y)
99 ;; CLISP signals an error when the target file exists, which
100 ;; seems unjustified by the ANSI definition of RENAME-FILE.
102 #+clisp (ignore-errors (delete-file y))
105 ;; (Note that the TRUENAME expression here is lifted
106 ;; from an example in the ANSI spec for TRUENAME.)
107 (with-open-file (stream y :direction :output)
109 ;; From the ANSI spec: "In this case, the file is
110 ;; closed when the truename is tried, so the truename
111 ;; information is reliable."
113 (compile 'rename-file-a-la-unix)
115 ;;; a wrapper for compilation/assembly, used mostly to centralize
116 ;;; the procedure for finding full filenames from "stems"
118 ;;; Compile the source file whose basic name is STEM, using some
119 ;;; standard-for-the-SBCL-build-process procedures to generate the
120 ;;; full pathnames of source file and object file. Return the pathname
121 ;;; of the object file for STEM. Several &KEY arguments are accepted:
122 ;;; :SRC-PREFIX, :SRC-SUFFIX =
123 ;;; strings to be concatenated to STEM to produce source filename
124 ;;; :OBJ-PREFIX, :OBJ-SUFFIX =
125 ;;; strings to be concatenated to STEM to produce object filename
126 ;;; :TMP-OBJ-SUFFIX-SUFFIX =
127 ;;; string to be appended to the name of an object file to produce
128 ;;; the name of a temporary object file
129 ;;; :COMPILE-FILE, :IGNORE-FAILURE-P =
130 ;;; :COMPILE-FILE is a function to use for compiling the file
131 ;;; (with the same calling conventions as ANSI CL:COMPILE-FILE).
132 ;;; If the third return value (FAILURE-P) of this function is
133 ;;; true, a continuable error will be signalled, unless
134 ;;; :IGNORE-FAILURE-P is set, in which case only a warning will be
136 (defun compile-stem (stem
139 (obj-suffix (error "missing OBJ-SUFFIX"))
140 (tmp-obj-suffix-suffix "-tmp")
143 (compile-file #'compile-file)
146 (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common
147 ;; Lisp Way, although it works just fine for common UNIX environments.
148 ;; Should it come to pass that the system is ported to environments
149 ;; where version numbers and so forth become an issue, it might become
150 ;; urgent to rewrite this using the fancy Common Lisp PATHNAME
151 ;; machinery instead of just using strings. In the absence of such a
152 ;; port, it might or might be a good idea to do the rewrite.
154 (src (concatenate 'string src-prefix stem src-suffix))
155 (obj (concatenate 'string obj-prefix stem obj-suffix))
156 (tmp-obj (concatenate 'string obj tmp-obj-suffix-suffix)))
158 (ensure-directories-exist obj :verbose t)
160 ;; We're about to set about building a new object file. First, we
161 ;; delete any preexisting object file in order to avoid confusing
162 ;; ourselves later should we happen to bail out of compilation
164 (when (probe-file obj)
167 ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP
168 ;; mangles relative pathnames passed as :OUTPUT-FILE arguments,
169 ;; but works OK with absolute pathnames.
172 ;; (Note that this idiom is taken from the ANSI
173 ;; documentation for TRUENAME.)
174 (with-open-file (stream tmp-obj :direction :output)
178 ;; Try to use the compiler to generate a new temporary object file.
179 (multiple-value-bind (output-truename warnings-p failure-p)
180 (funcall compile-file src :output-file tmp-obj)
181 (declare (ignore warnings-p))
182 (cond ((not output-truename)
183 (error "couldn't compile ~S" src))
186 (warn "ignoring FAILURE-P return value from compilation of ~S"
190 ;; FIXME: This should have another option,
191 ;; redoing compilation.
192 (cerror "Continue, using possibly-bogus ~S."
193 "FAILURE-P was set when creating ~S."
195 (setf failure-p nil))
196 ;; Don't leave failed object files lying around.
197 (when (and failure-p (probe-file tmp-obj))
198 (delete-file tmp-obj)
199 (format t "~&deleted ~S~%" tmp-obj)))))
200 ;; Otherwise: success, just fall through.
203 ;; If we get to here, compilation succeeded, so it's OK to rename
204 ;; the temporary output file to the permanent object file.
205 (rename-file-a-la-unix tmp-obj obj)
207 ;; nice friendly traditional return value
209 (compile 'compile-stem)
211 ;;; other miscellaneous tools
212 (load "src/cold/read-from-file.lisp")
213 (load "src/cold/rename-package-carefully.lisp")
214 (load "src/cold/with-stuff.lisp")
216 ;;; Try to minimize/conceal any non-standardness of the host Common Lisp.
217 (load "src/cold/ansify.lisp")
219 ;;;; special read-macros for building the cold system (and even for
220 ;;;; building some of our tools for building the cold system)
222 (load "src/cold/shebang.lisp")
224 ;;; When cross-compiling, the *FEATURES* set for the target Lisp is
225 ;;; not in general the same as the *FEATURES* set for the host Lisp.
226 ;;; In order to refer to target features specifically, we refer to
227 ;;; *SHEBANG-FEATURES* instead of *FEATURES*, and use the #!+ and #!-
228 ;;; readmacros instead of the ordinary #+ and #- readmacros.
229 (setf *shebang-features*
230 (let* ((default-features
231 (append (read-from-file "base-target-features.lisp-expr")
232 (read-from-file "local-target-features.lisp-expr")))
233 (customizer-file-name "customize-target-features.lisp")
234 (customizer (if (probe-file customizer-file-name)
236 (read-from-file customizer-file-name))
238 (funcall customizer default-features)))
239 (let ((*print-length* nil)
242 "target features *SHEBANG-FEATURES*=~@<~S~:>~%"
245 ;;;; cold-init-related PACKAGE and SYMBOL tools
247 ;;; Once we're done with possibly ANSIfying the COMMON-LISP package,
248 ;;; it's probably a mistake if we change it (beyond changing the
249 ;;; values of special variables such as *** and +, anyway). Set up
250 ;;; machinery to warn us when/if we change it.
252 ;;; FIXME: All this machinery should probably be conditional on
253 ;;; #!+SB-SHOW, i.e. we should be able to wrap #!+SB-SHOW around both
254 ;;; the LOAD and the DEFVAR here.
255 (load "src/cold/snapshot.lisp")
256 (defvar *cl-snapshot* (take-snapshot "COMMON-LISP"))
258 ;;;; master list of source files and their properties
260 ;;; flags which can be used to describe properties of source files
262 *expected-stem-flags*
263 '(;; meaning: This file is not to be compiled when building the
264 ;; cross-compiler which runs on the host ANSI Lisp.
266 ;; meaning: This file is not to be compiled as part of the target
269 ;; meaning: This file is to be processed with the SBCL assembler,
270 ;; not COMPILE-FILE. (Note that this doesn't make sense unless
271 ;; :NOT-HOST is also set, since the SBCL assembler doesn't exist
272 ;; while the cross-compiler is being built in the host ANSI Lisp.)
274 ;; meaning: The #'COMPILE-STEM argument called :IGNORE-FAILURE-P
275 ;; should be true. (This is a KLUDGE: I'd like to get rid of it.
276 ;; For now, it exists so that compilation can proceed through the
277 ;; legacy warnings in src/compiler/x86/array.lisp, which I've
278 ;; never figured out but which were apparently acceptable in CMU
279 ;; CL. Eventually, it would be great to just get rid of all
280 ;; warnings and remove support for this flag. -- WHN 19990323)
283 (defparameter *stems-and-flags* (read-from-file "build-order.lisp-expr"))
285 (defmacro do-stems-and-flags ((stem flags) &body body)
286 (let ((stem-and-flags (gensym "STEM-AND-FLAGS-")))
287 `(dolist (,stem-and-flags *stems-and-flags*)
288 (let ((,stem (first ,stem-and-flags))
289 (,flags (rest ,stem-and-flags)))
292 ;;; Check for stupid typos in FLAGS list keywords.
293 (let ((stems (make-hash-table :test 'equal)))
294 (do-stems-and-flags (stem flags)
295 (if (gethash stem stems)
296 (error "duplicate stem ~S in *STEMS-AND-FLAGS*" stem)
297 (setf (gethash stem stems) t))
298 (let ((set-difference (set-difference flags *expected-stem-flags*)))
300 (error "found unexpected flag(s) in *STEMS-AND-FLAGS*: ~S"
303 ;;;; tools to compile SBCL sources to create the cross-compiler
305 ;;; Execute function FN in an environment appropriate for compiling the
306 ;;; cross-compiler's source code in the cross-compilation host.
307 (defun in-host-compilation-mode (fn)
308 (let ((*features* (cons :sb-xc-host *features*))
309 ;; the CROSS-FLOAT-INFINITY-KLUDGE, as documented in
310 ;; base-target-features.lisp-expr:
311 (*shebang-features* (set-difference *shebang-features*
312 '(:sb-propagate-float-type
313 :sb-propagate-fun-type))))
314 (with-additional-nickname ("SB-XC" "SB!XC")
316 (compile 'in-host-compilation-mode)
318 ;;; Process a file as source code for the cross-compiler, compiling it
319 ;;; (if necessary) in the appropriate environment, then loading it
320 ;;; into the cross-compilation host Common lisp.
321 (defun host-cload-stem (stem &key ignore-failure-p)
322 (let ((compiled-filename (in-host-compilation-mode
326 :obj-prefix *host-obj-prefix*
327 :obj-suffix *host-obj-suffix*
328 :compile-file #'cl:compile-file
329 :ignore-failure-p ignore-failure-p)))))
330 (load compiled-filename)))
331 (compile 'host-cload-stem)
333 ;;; Like HOST-CLOAD-STEM, except that we don't bother to compile.
334 (defun host-load-stem (stem &key ignore-failure-p)
335 (declare (ignore ignore-failure-p)) ; (It's only relevant when
336 ;; compiling.) KLUDGE: It's untidy to have the knowledge of how to
337 ;; construct complete filenames from stems in here as well as in
338 ;; COMPILE-STEM. It should probably be factored out somehow. -- WHN
340 (load (concatenate 'simple-string *host-obj-prefix* stem *host-obj-suffix*)))
341 (compile 'host-load-stem)
343 ;;;; tools to compile SBCL sources to create object files which will
344 ;;;; be used to create the target SBCL .core file
346 ;;; Run the cross-compiler on a file in the source directory tree to
347 ;;; produce a corresponding file in the target object directory tree.
348 (defun target-compile-stem (stem &key assem-p ignore-failure-p)
349 (funcall *in-target-compilation-mode-fn*
352 :obj-prefix *target-obj-prefix*
353 :obj-suffix *target-obj-suffix*
354 :ignore-failure-p ignore-failure-p
355 :compile-file (if assem-p
356 *target-assemble-file*
357 *target-compile-file*)))))
358 (compile 'target-compile-stem)
360 ;;; (This function is not used by the build process, but is intended
361 ;;; for interactive use when experimenting with the system. It runs
362 ;;; the cross-compiler on test files with arbitrary filenames, not
363 ;;; necessarily in the source tree, e.g. in "/tmp".)
364 (defun target-compile-file (filename)
365 (funcall *in-target-compilation-mode-fn*
367 (funcall *target-compile-file* filename))))
368 (compile 'target-compile-file)