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.
17 ;;; A CORE-OBJECT structure holds the state needed to resolve cross-component
18 ;;; references during in-core compilation.
19 (defstruct (core-object
20 (:constructor make-core-object ())
21 #-no-ansi-print-object
22 (:print-object (lambda (x s)
23 (print-unreadable-object (x s :type t)))))
24 ;; A hashtable translating ENTRY-INFO structures to the corresponding actual
25 ;; FUNCTIONs for functions in this compilation.
26 (entry-table (make-hash-table :test 'eq) :type hash-table)
27 ;; A hashtable translating ENTRY-INFO structures to a list of pairs
28 ;; (<code object> . <offset>) describing the places that need to be
29 ;; backpatched to point to the function for ENTRY-INFO.
30 (patch-table (make-hash-table :test 'eq) :type hash-table)
31 ;; A list of all the DEBUG-INFO objects created, kept so that we can
32 ;; backpatch with the source info.
33 (debug-info () :type list))
35 ;;; Note the existence of FUNCTION.
36 (defun note-function (info function object)
37 (declare (type function function)
38 (type core-object object))
39 (let ((patch-table (core-object-patch-table object)))
40 (dolist (patch (gethash info patch-table))
41 (setf (code-header-ref (car patch) (the index (cdr patch))) function))
42 (remhash info patch-table))
43 (setf (gethash info (core-object-entry-table object)) function)
46 ;;; Do "load-time" fixups on the code vector.
47 (defun do-core-fixups (code fixups)
48 (declare (list fixups))
50 (let* ((kind (first info))
52 (name (fixup-name fixup))
53 (flavor (fixup-flavor fixup))
57 (assert (symbolp name))
58 (or (gethash name *assembler-routines*)
59 (error "undefined assembler routine: ~S" name)))
61 (assert (stringp name))
62 (or (sb!impl::foreign-symbol-address-as-integer name)
63 (error "unknown foreign symbol: ~S")))
67 (values (get-lisp-obj-address code) t)))))
68 (sb!vm:fixup-code-object code offset value kind))))
70 ;;; Stick a reference to the function Fun in Code-Object at index I. If the
71 ;;; function hasn't been compiled yet, make a note in the Patch-Table.
72 (defun reference-core-function (code-obj i fun object)
73 (declare (type core-object object) (type functional fun)
75 (let* ((info (leaf-info fun))
76 (found (gethash info (core-object-entry-table object))))
78 (setf (code-header-ref code-obj i) found)
79 (push (cons code-obj i)
80 (gethash info (core-object-patch-table object)))))
83 ;;; Call the top-level lambda function dumped for Entry, returning the
84 ;;; values. Entry may be a :TOP-LEVEL-XEP functional.
85 (defun core-call-top-level-lambda (entry object)
86 (declare (type functional entry) (type core-object object))
87 (funcall (or (gethash (leaf-info entry)
88 (core-object-entry-table object))
89 (error "Unresolved forward reference."))))
91 ;;; Backpatch all the DEBUG-INFOs dumped so far with the specified
92 ;;; SOURCE-INFO list. We also check that there are no outstanding forward
93 ;;; references to functions.
94 (defun fix-core-source-info (info object source-info)
95 (declare (type source-info info) (type core-object object))
96 (assert (zerop (hash-table-count (core-object-patch-table object))))
97 (let ((res (debug-source-for-info info)))
99 (setf (debug-source-info sinfo) source-info))
100 (dolist (info (core-object-debug-info object))
101 (setf (compiled-debug-info-source info) res))
102 (setf (core-object-debug-info object) ()))