Remove some test noise. A drop in the ocean unfortunately.
[sbcl.git] / src / code / linkage-table.lisp
blobe9fa8d4ff938e3e17e629f17319a9f808e6ba202
1 ;;;; Linkage table specifics
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
12 ;;;; Linkage table itself is a mmapped memory area in C-land, which is
13 ;;;; initialized by INIT-LINKAGE-TABLE once all shared objects have
14 ;;;; been reopened, based on the information stored in *LINKAGE-INFO*.
15 ;;;;
16 ;;;; For data entries the linkage table holds the real address
17 ;;;; of the foreign symbol, and for code the entries are jumps
18 ;;;; to the real addresses.
20 (in-package "SB!IMPL")
22 (define-alien-routine arch-write-linkage-table-jmp void
23 (table-address system-area-pointer)
24 (real-address system-area-pointer))
26 (define-alien-routine arch-write-linkage-table-ref void
27 (table-address system-area-pointer)
28 (real-address system-area-pointer))
30 (defvar *linkage-info* (make-hash-table :test 'equal :synchronized t))
32 (defun write-linkage-table-entry (table-address real-address datap)
33 (/show0 "write-linkage-table-entry")
34 (let ((reloc (int-sap table-address))
35 (target (int-sap real-address)))
36 (if datap
37 (arch-write-linkage-table-ref reloc target)
38 (arch-write-linkage-table-jmp reloc target))))
40 ;;; Add the linkage information about a foreign symbol in the
41 ;;; persistent table, and write the linkage-table entry.
42 (defun link-foreign-symbol (name datap)
43 (/show0 "link-foreign-symbol")
44 (let ((table-address (+ (* (hash-table-count *linkage-info*)
45 sb!vm:linkage-table-entry-size)
46 sb!vm:linkage-table-space-start))
47 (real-address (ensure-dynamic-foreign-symbol-address name datap)))
48 (aver real-address)
49 (unless (< table-address sb!vm:linkage-table-space-end)
50 (error "Linkage-table full (~D entries): cannot link ~S."
51 (hash-table-count *linkage-info*)
52 name))
53 (write-linkage-table-entry table-address real-address datap)
54 (setf (gethash (cons name datap) *linkage-info*) table-address)))
56 ;;; Add a foreign linkage entry if none exists, return the address
57 ;;; in the linkage table.
58 (defun ensure-foreign-symbol-linkage (name datap)
59 (/show0 "ensure-foreign-symbol-linkage")
60 (with-locked-system-table (*linkage-info*)
61 (or (gethash (cons name datap) *linkage-info*)
62 (link-foreign-symbol name datap))))
64 ;;; Update the linkage-table. Called during initialization after all
65 ;;; shared libraries have been reopened, and after a previously loaded
66 ;;; shared object is reloaded.
67 ;;;
68 ;;; FIXME: Should figure out how to write only those entries that need
69 ;;; updating.
70 (defun update-linkage-table ()
71 (dohash ((name-and-datap table-address) *linkage-info* :locked t)
72 (let* ((name (car name-and-datap))
73 (datap (cdr name-and-datap))
74 (real-address
75 (ensure-dynamic-foreign-symbol-address name datap)))
76 (aver (and table-address real-address))
77 (write-linkage-table-entry table-address
78 real-address
79 datap))))