1 ;;;; Linkage table specifics
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.
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*.
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 (define-load-time-global *linkage-info
*
31 (make-hash-table :test
'equal
:synchronized t
))
33 (defun write-linkage-table-entry (table-address real-address datap
)
34 (/show0
"write-linkage-table-entry")
35 (let ((reloc (int-sap table-address
))
36 (target (int-sap real-address
)))
38 (arch-write-linkage-table-ref reloc target
)
39 (arch-write-linkage-table-jmp reloc target
))))
41 ;;; Add the linkage information about a foreign symbol in the
42 ;;; persistent table, and write the linkage-table entry.
43 (defun link-foreign-symbol (name datap
)
44 (/show0
"link-foreign-symbol")
45 (let ((table-address (+ (* (hash-table-count *linkage-info
*)
46 sb
!vm
:linkage-table-entry-size
)
47 sb
!vm
:linkage-table-space-start
))
48 (real-address (ensure-dynamic-foreign-symbol-address name datap
)))
50 (unless (< table-address sb
!vm
:linkage-table-space-end
)
51 (error "Linkage-table full (~D entries): cannot link ~S."
52 (hash-table-count *linkage-info
*)
54 (write-linkage-table-entry table-address real-address datap
)
55 (setf (gethash (cons (logically-readonlyize name
) datap
) *linkage-info
*)
58 ;;; Add a foreign linkage entry if none exists, return the address
59 ;;; in the linkage table.
60 (defun ensure-foreign-symbol-linkage (name datap
)
61 (with-locked-system-table (*linkage-info
*)
62 (or (gethash (cons name datap
) *linkage-info
*)
63 (link-foreign-symbol name datap
))))
65 ;;; Update the linkage-table. Called during initialization after all
66 ;;; shared libraries have been reopened, and after a previously loaded
67 ;;; shared object is reloaded.
69 ;;; FIXME: Should figure out how to write only those entries that need
71 (defun update-linkage-table ()
72 (dohash ((name-and-datap table-address
) *linkage-info
* :locked t
)
73 (let* ((name (car name-and-datap
))
74 (datap (cdr name-and-datap
))
76 (ensure-dynamic-foreign-symbol-address name datap
)))
77 (aver (and table-address real-address
))
78 (write-linkage-table-entry table-address