1 ;;;; stuff that knows how to load compiled code directly into core
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;; A CORE-OBJECT structure holds the state needed to resolve cross-component
15 ;;; references during in-core compilation.
16 (defstruct (core-object
17 (:constructor make-core-object ())
18 #-no-ansi-print-object
19 (:print-object (lambda (x s)
20 (print-unreadable-object (x s :type t))))
22 ;; A hashtable translating ENTRY-INFO structures to the corresponding actual
23 ;; FUNCTIONs for functions in this compilation.
24 (entry-table (make-hash-table :test 'eq) :type hash-table)
25 ;; A hashtable translating ENTRY-INFO structures to a list of pairs
26 ;; (<code object> . <offset>) describing the places that need to be
27 ;; backpatched to point to the function for ENTRY-INFO.
28 (patch-table (make-hash-table :test 'eq) :type hash-table)
29 ;; A list of all the DEBUG-INFO objects created, kept so that we can
30 ;; backpatch with the source info.
31 (debug-info () :type list))
33 ;;; Note the existence of FUNCTION.
34 (defun note-fun (info function object)
35 (declare (type function function)
36 (type core-object object))
37 (let ((patch-table (core-object-patch-table object)))
38 (dolist (patch (gethash info patch-table))
39 (setf (code-header-ref (car patch) (the index (cdr patch))) function))
40 (remhash info patch-table))
41 (setf (gethash info (core-object-entry-table object)) function)
44 ;;; Do "load-time" fixups on the code vector.
45 (defun do-core-fixups (code fixup-notes)
46 (declare (list fixup-notes))
47 (dolist (note fixup-notes)
48 (let* ((kind (fixup-note-kind note))
49 (fixup (fixup-note-fixup note))
50 (position (fixup-note-position note))
51 (name (fixup-name fixup))
52 (flavor (fixup-flavor fixup))
56 (or (gethash name *assembler-routines*)
57 (error "undefined assembler routine: ~S" name)))
60 (or (foreign-symbol-address-as-integer name)
61 (error "unknown foreign symbol: ~S" name)))
65 (values (get-lisp-obj-address code) t)))))
66 (sb!vm:fixup-code-object code position value kind))))
68 ;;; Stick a reference to the function FUN in CODE-OBJECT at index I. If the
69 ;;; function hasn't been compiled yet, make a note in the patch table.
70 (defun reference-core-fun (code-obj i fun object)
71 (declare (type core-object object) (type functional fun)
73 (let* ((info (leaf-info fun))
74 (found (gethash info (core-object-entry-table object))))
76 (setf (code-header-ref code-obj i) found)
77 (push (cons code-obj i)
78 (gethash info (core-object-patch-table object)))))
81 ;;; Call the top level lambda function dumped for ENTRY, returning the
82 ;;; values. ENTRY may be a :TOPLEVEL-XEP functional.
83 (defun core-call-toplevel-lambda (entry object)
84 (declare (type functional entry) (type core-object object))
85 (funcall (or (gethash (leaf-info entry)
86 (core-object-entry-table object))
87 (error "Unresolved forward reference."))))
89 ;;; Backpatch all the DEBUG-INFOs dumped so far with the specified
90 ;;; SOURCE-INFO list. We also check that there are no outstanding forward
91 ;;; references to functions.
92 (defun fix-core-source-info (info object &optional source-info)
93 (declare (type source-info info) (type core-object object))
94 (aver (zerop (hash-table-count (core-object-patch-table object))))
95 (let ((res (debug-source-for-info info)))
97 (setf (debug-source-info sinfo) source-info))
98 (dolist (info (core-object-debug-info object))
99 (setf (compiled-debug-info-source info) res))
100 (setf (core-object-debug-info object) ()))