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 ;;; SB-COLD holds stuff used to build the initial SBCL core file
40 ;;; (including not only the final construction of the core file, but
41 ;;; also the preliminary steps like e.g. building the cross-compiler
42 ;;; and running the cross-compiler to produce target FASL files).
43 (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 xc host Common Lisp).
54 (defvar *host-obj-prefix*)
55 (defvar *target-obj-prefix*)
57 ;;; suffixes for filename stems when cross-compiling
58 (defvar *host-obj-suffix*
60 ;; On some xc hosts, it's impossible to LOAD a fasl file unless it
61 ;; has the same extension that the host uses for COMPILE-FILE
62 ;; output, so we have to be careful to use the xc host's preferred
65 ;; FIXME: This is a little ugly and annoying to maintain. And
66 ;; there's very likely some way to rearrange the build process so
67 ;; that we never explicitly refer to host object file suffixes,
68 ;; only to the result of CL:COMPILE-FILE-PATHNAME.
69 #+lispworks ".ufsl" ; as per Lieven Marchand sbcl-devel 2002-02-01
70 ;; On most xc hosts, any old extension works, so we use an
73 (defvar *target-obj-suffix*
74 ;; Target fasl files are LOADed (actually only quasi-LOADed, in
75 ;; GENESIS) only by SBCL code, and it doesn't care about particular
76 ;; extensions, so we can use something arbitrary.
79 ;;; a function of one functional argument, which calls its functional argument
80 ;;; in an environment suitable for compiling the target. (This environment
81 ;;; includes e.g. a suitable *FEATURES* value.)
82 (defvar *in-target-compilation-mode-fn*)
84 ;;; designator for a function with the same calling convention as
85 ;;; CL:COMPILE-FILE, to be used to translate ordinary Lisp source files into
86 ;;; target object files
87 (defvar *target-compile-file*)
89 ;;; designator for a function with the same calling convention as
90 ;;; SB-C:ASSEMBLE-FILE, to be used to translate assembly files into target
92 (defvar *target-assemble-file*)
96 ;;; Take the file named X and make it into a file named Y. Sorta like
97 ;;; UNIX, and unlike Common Lisp's bare RENAME-FILE, we don't allow
98 ;;; information from the original filename to influence the final
99 ;;; filename. (The reason that it's only sorta like UNIX is that in
100 ;;; UNIX "mv foo bar/" will work, but the analogous
101 ;;; (RENAME-FILE-A-LA-UNIX "foo" "bar/") should fail.)
103 ;;; (This is a workaround for the weird behavior of Debian CMU CL
104 ;;; 2.4.6, where (RENAME-FILE "dir/x" "dir/y") tries to create a file
105 ;;; called "dir/dir/y". If that behavior goes away, then we should be
106 ;;; able to get rid of this function and use plain RENAME-FILE in the
107 ;;; COMPILE-STEM function above. -- WHN 19990321
108 (defun rename-file-a-la-unix (x y)
110 (let ((path ;; (Note that the TRUENAME expression here is lifted from an
111 ;; example in the ANSI spec for TRUENAME.)
112 (with-open-file (stream y :direction :output)
114 ;; From the ANSI spec: "In this case, the file is closed
115 ;; when the truename is tried, so the truename
116 ;; information is reliable."
119 (rename-file x path)))
120 (compile 'rename-file-a-la-unix)
122 ;;; a wrapper for compilation/assembly, used mostly to centralize
123 ;;; the procedure for finding full filenames from "stems"
125 ;;; Compile the source file whose basic name is STEM, using some
126 ;;; standard-for-the-SBCL-build-process procedures to generate the
127 ;;; full pathnames of source file and object file. Return the pathname
128 ;;; of the object file for STEM. Several &KEY arguments are accepted:
129 ;;; :SRC-PREFIX, :SRC-SUFFIX =
130 ;;; strings to be concatenated to STEM to produce source filename
131 ;;; :OBJ-PREFIX, :OBJ-SUFFIX =
132 ;;; strings to be concatenated to STEM to produce object filename
133 ;;; :TMP-OBJ-SUFFIX-SUFFIX =
134 ;;; string to be appended to the name of an object file to produce
135 ;;; the name of a temporary object file
136 ;;; :COMPILE-FILE, :IGNORE-FAILURE-P =
137 ;;; :COMPILE-FILE is a function to use for compiling the file
138 ;;; (with the same calling conventions as ANSI CL:COMPILE-FILE).
139 ;;; If the third return value (FAILURE-P) of this function is
140 ;;; true, a continuable error will be signalled, unless
141 ;;; :IGNORE-FAILURE-P is set, in which case only a warning will be
143 (defun compile-stem (stem
146 (obj-suffix (error "missing OBJ-SUFFIX"))
147 (tmp-obj-suffix-suffix "-tmp")
150 (compile-file #'compile-file)
153 (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common
154 ;; Lisp Way, although it works just fine for common UNIX environments.
155 ;; Should it come to pass that the system is ported to environments
156 ;; where version numbers and so forth become an issue, it might become
157 ;; urgent to rewrite this using the fancy Common Lisp PATHNAME
158 ;; machinery instead of just using strings. In the absence of such a
159 ;; port, it might or might be a good idea to do the rewrite.
161 (src (concatenate 'string src-prefix stem src-suffix))
162 (obj (concatenate 'string obj-prefix stem obj-suffix))
163 (tmp-obj (concatenate 'string obj tmp-obj-suffix-suffix)))
165 (ensure-directories-exist obj :verbose t)
167 ;; We're about to set about building a new object file. First, we
168 ;; delete any preexisting object file in order to avoid confusing
169 ;; ourselves later should we happen to bail out of compilation
171 (when (probe-file obj)
174 ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP
175 ;; mangles relative pathnames passed as :OUTPUT-FILE arguments,
176 ;; but works OK with absolute pathnames.
179 ;; (Note that this idiom is taken from the ANSI
180 ;; documentation for TRUENAME.)
181 (with-open-file (stream tmp-obj :direction :output)
185 ;; Try to use the compiler to generate a new temporary object file.
186 (multiple-value-bind (output-truename warnings-p failure-p)
187 (funcall compile-file src :output-file tmp-obj)
188 (declare (ignore warnings-p))
189 (cond ((not output-truename)
190 (error "couldn't compile ~S" src))
193 (warn "ignoring FAILURE-P return value from compilation of ~S"
197 ;; FIXME: This should have another option,
198 ;; redoing compilation.
199 (cerror "Continue, using possibly-bogus ~S."
200 "FAILURE-P was set when creating ~S."
202 (setf failure-p nil))
203 ;; Don't leave failed object files lying around.
204 (when (and failure-p (probe-file tmp-obj))
205 (delete-file tmp-obj)
206 (format t "~&deleted ~S~%" tmp-obj)))))
207 ;; Otherwise: success, just fall through.
210 ;; If we get to here, compilation succeeded, so it's OK to rename
211 ;; the temporary output file to the permanent object file.
212 (rename-file-a-la-unix tmp-obj obj)
214 ;; nice friendly traditional return value
216 (compile 'compile-stem)
218 ;;; other miscellaneous tools
219 (load "src/cold/read-from-file.lisp")
220 (load "src/cold/rename-package-carefully.lisp")
221 (load "src/cold/with-stuff.lisp")
223 ;;; Try to minimize/conceal any non-standardness of the host Common Lisp.
224 (load "src/cold/ansify.lisp")
226 ;;;; special read-macros for building the cold system (and even for
227 ;;;; building some of our tools for building the cold system)
229 (load "src/cold/shebang.lisp")
231 ;;; When cross-compiling, the *FEATURES* set for the target Lisp is
232 ;;; not in general the same as the *FEATURES* set for the host Lisp.
233 ;;; In order to refer to target features specifically, we refer to
234 ;;; *SHEBANG-FEATURES* instead of *FEATURES*, and use the #!+ and #!-
235 ;;; readmacros instead of the ordinary #+ and #- readmacros.
236 (setf *shebang-features*
237 (let* ((default-features
238 (append (read-from-file "base-target-features.lisp-expr")
239 (read-from-file "local-target-features.lisp-expr")))
240 (customizer-file-name "customize-target-features.lisp")
241 (customizer (if (probe-file customizer-file-name)
243 (read-from-file customizer-file-name))
245 (funcall customizer default-features)))
246 (let ((*print-length* nil)
249 "target features *SHEBANG-FEATURES*=~@<~S~:>~%"
252 ;;;; cold-init-related PACKAGE and SYMBOL tools
254 ;;; Once we're done with possibly ANSIfying the COMMON-LISP package,
255 ;;; it's probably a mistake if we change it (beyond changing the
256 ;;; values of special variables such as *** and +, anyway). Set up
257 ;;; machinery to warn us when/if we change it.
259 ;;; FIXME: All this machinery should probably be conditional on
260 ;;; #!+SB-SHOW, i.e. we should be able to wrap #!+SB-SHOW around both
261 ;;; the LOAD and the DEFVAR here.
262 (load "src/cold/snapshot.lisp")
263 (defvar *cl-snapshot* (take-snapshot "COMMON-LISP"))
265 ;;;; master list of source files and their properties
267 ;;; flags which can be used to describe properties of source files
269 *expected-stem-flags*
270 '(;; meaning: This file is not to be compiled when building the
271 ;; cross-compiler which runs on the host ANSI Lisp.
273 ;; meaning: This file is not to be compiled as part of the target
276 ;; meaning: This file is to be processed with the SBCL assembler,
277 ;; not COMPILE-FILE. (Note that this doesn't make sense unless
278 ;; :NOT-HOST is also set, since the SBCL assembler doesn't exist
279 ;; while the cross-compiler is being built in the host ANSI Lisp.)
281 ;; meaning: The #'COMPILE-STEM argument called :IGNORE-FAILURE-P
282 ;; should be true. (This is a KLUDGE: I'd like to get rid of it.
283 ;; For now, it exists so that compilation can proceed through the
284 ;; legacy warnings in src/compiler/x86/array.lisp, which I've
285 ;; never figured out but which were apparently acceptable in CMU
286 ;; CL. Eventually, it would be great to just get rid of all
287 ;; warnings and remove support for this flag. -- WHN 19990323)
290 (defparameter *stems-and-flags* (read-from-file "build-order.lisp-expr"))
292 (defmacro do-stems-and-flags ((stem flags) &body body)
293 (let ((stem-and-flags (gensym "STEM-AND-FLAGS-")))
294 `(dolist (,stem-and-flags *stems-and-flags*)
295 (let ((,stem (first ,stem-and-flags))
296 (,flags (rest ,stem-and-flags)))
299 ;;; Check for stupid typos in FLAGS list keywords.
300 (let ((stems (make-hash-table :test 'equal)))
301 (do-stems-and-flags (stem flags)
302 (if (gethash stem stems)
303 (error "duplicate stem ~S in *STEMS-AND-FLAGS*" stem)
304 (setf (gethash stem stems) t))
305 (let ((set-difference (set-difference flags *expected-stem-flags*)))
307 (error "found unexpected flag(s) in *STEMS-AND-FLAGS*: ~S"
310 ;;;; tools to compile SBCL sources to create the cross-compiler
312 ;;; Execute function FN in an environment appropriate for compiling the
313 ;;; cross-compiler's source code in the cross-compilation host.
314 (defun in-host-compilation-mode (fn)
315 (let ((*features* (cons :sb-xc-host *features*))
316 ;; the CROSS-FLOAT-INFINITY-KLUDGE, as documented in
317 ;; base-target-features.lisp-expr:
318 (*shebang-features* (set-difference *shebang-features*
319 '(:sb-propagate-float-type
320 :sb-propagate-fun-type))))
321 (with-additional-nickname ("SB-XC" "SB!XC")
323 (compile 'in-host-compilation-mode)
325 ;;; Process a file as source code for the cross-compiler, compiling it
326 ;;; (if necessary) in the appropriate environment, then loading it
327 ;;; into the cross-compilation host Common lisp.
328 (defun host-cload-stem (stem &key ignore-failure-p)
329 (let ((compiled-filename (in-host-compilation-mode
333 :obj-prefix *host-obj-prefix*
334 :obj-suffix *host-obj-suffix*
335 :compile-file #'cl:compile-file
336 :ignore-failure-p ignore-failure-p)))))
337 (load compiled-filename)))
338 (compile 'host-cload-stem)
340 ;;; like HOST-CLOAD-STEM, except that we don't bother to compile
341 (defun host-load-stem (stem &key ignore-failure-p)
342 (declare (ignore ignore-failure-p)) ; (It's only relevant when
343 ;; compiling.) KLUDGE: It's untidy to have the knowledge of how to
344 ;; construct complete filenames from stems in here as well as in
345 ;; COMPILE-STEM. It should probably be factored out somehow. -- WHN
347 (load (concatenate 'simple-string *host-obj-prefix* stem *host-obj-suffix*)))
348 (compile 'host-load-stem)
350 ;;;; tools to compile SBCL sources to create object files which will
351 ;;;; be used to create the target SBCL .core file
353 ;;; Run the cross-compiler on a file in the source directory tree to
354 ;;; produce a corresponding file in the target object directory tree.
355 (defun target-compile-stem (stem &key assem-p ignore-failure-p)
356 (funcall *in-target-compilation-mode-fn*
359 :obj-prefix *target-obj-prefix*
360 :obj-suffix *target-obj-suffix*
361 :ignore-failure-p ignore-failure-p
362 :compile-file (if assem-p
363 *target-assemble-file*
364 *target-compile-file*)))))
365 (compile 'target-compile-stem)
367 ;;; (This function is not used by the build process, but is intended
368 ;;; for interactive use when experimenting with the system. It runs
369 ;;; the cross-compiler on test files with arbitrary filenames, not
370 ;;; necessarily in the source tree, e.g. in "/tmp".)
371 (defun target-compile-file (filename)
372 (funcall *in-target-compilation-mode-fn*
374 (funcall *target-compile-file* filename))))
375 (compile 'target-compile-file)