diff --git a/build-order.lisp-expr b/build-order.lisp-expr index 1406867d1..92cdee987 100644 --- a/build-order.lisp-expr +++ b/build-order.lisp-expr @@ -425,7 +425,7 @@ ("src/code/load") - #+linkage-table ("src/code/linkage-table" :not-host) + ("src/code/linkage-table" :not-host) ("src/code/foreign" :not-host) #+os-provides-dlopen ("src/code/foreign-load" :not-host) #+(and os-provides-dlopen (not win32)) ("src/code/unix-foreign-load" :not-host) diff --git a/package-data-list.lisp-expr b/package-data-list.lisp-expr index 77f141ddd..3a5f32ac5 100644 --- a/package-data-list.lisp-expr +++ b/package-data-list.lisp-expr @@ -2777,7 +2777,6 @@ SB-KERNEL) have been undone, but probably more remain." "*PERIODIC-POLLING-PERIOD*" "*RUNTIME-DLHANDLE*" "*SHARED-OBJECTS*" - #-linkage-table "*STATIC-FOREIGN-SYMBOLS*" "*STDERR*" "*STDIN*" "*STDOUT*" "*TTY*" diff --git a/src/code/alieneval.lisp b/src/code/alieneval.lisp index 8db218d7a..e7a0a066e 100644 --- a/src/code/alieneval.lisp +++ b/src/code/alieneval.lisp @@ -1276,15 +1276,6 @@ (in-package "SB-ALIEN") -;;; *STATIC-FOREIGN-SYMBOLS* are static as opposed to "dynamic" (not -;;; as opposed to C's "extern"). The table contains symbols known at -;;; the time that the program was built, but not symbols defined in -;;; object files which have been loaded dynamically since then. -#-linkage-table -(progn - (declaim (type hash-table *static-foreign-symbols*)) - (defvar *static-foreign-symbols* (make-hash-table :test 'equal))) - #+sb-xc (defmacro maybe-with-pinned-objects (variables types &body body) (declare (ignorable variables types)) diff --git a/src/code/debug-int.lisp b/src/code/debug-int.lisp index d594a0546..e125180d8 100644 --- a/src/code/debug-int.lisp +++ b/src/code/debug-int.lisp @@ -957,15 +957,6 @@ (sb-alien:sap-alien (sb-vm::current-thread-offset-sap (+ tls-words n)) (* os-context-t)))) -;;; With :LINKAGE-TABLE symbols which come from the runtime go through -;;; an indirection table, but the debugger needs to know the actual -;;; address. -(defun static-foreign-symbol-address (name) - #+linkage-table - (find-dynamic-foreign-symbol-address name) - #-linkage-table - (foreign-symbol-address name)) - (defun catch-runaway-unwind (block) (declare (ignorable block)) #-(and win32 x86) ;; uses SEH @@ -3495,8 +3486,7 @@ register." (defun make-bpt-lra (real-lra) (declare (type #-(or x86 x86-64) lra #+(or x86 x86-64) system-area-pointer real-lra)) (macrolet ((symbol-addr (name) - ;; "static" is not really correct if #+linkage-table - `(static-foreign-symbol-address ,name)) + `(find-dynamic-foreign-symbol-address ,name)) (trap-offset () `(- (symbol-addr "fun_end_breakpoint_trap") src-start))) ;; These are really code labels, not variables: but this way we get diff --git a/src/code/foreign-load.lisp b/src/code/foreign-load.lisp index f66f2262a..5d0fbde98 100644 --- a/src/code/foreign-load.lisp +++ b/src/code/foreign-load.lisp @@ -88,16 +88,6 @@ will be signalled when the core is saved -- this is orthogonal from DONT-SAVE." (dlopen-or-lose obj)) (setf *shared-objects* (append (remove obj *shared-objects*) (list obj))) - ;; FIXME: Why doesn't the linkage table work on Windows? (Or maybe it - ;; does and this can be just #+linkage-table?) Note: remember to change - ;; FOREIGN-DEINIT as well then! - ;; - ;; Kovalenko 2010-11-24: I think so. Alien _data_ references - ;; are the only thing on win32 that is even slightly - ;; problematic. Handle function references in the same way as - ;; other linkage-table platforms is easy. - ;; - #+linkage-table (when (or old (cdr *linkage-info*)) ;; If OLD is non-NIL, then we're passing "true" which causes all foreign ;; symbols to get looked up again. Otherwise we're passing "false" @@ -118,7 +108,6 @@ Experimental." (when old (dlclose-or-lose old) (setf *shared-objects* (remove old *shared-objects*)) - #+linkage-table (update-linkage-table t) ;; Return T for unloaded, vs whatever update-linkage-info returns t))))) @@ -173,26 +162,3 @@ Experimental." (push obj saved))) (setf *shared-objects* saved)) (dlclose-or-lose)) - -;;; This table is unsynchronized, but the only platforms that use it -;;; lack thread support, and they don't work anyway. -#-linkage-table -(let ((symbols (make-hash-table :test #'equal))) - (defun ensure-dynamic-foreign-symbol-address (symbol &optional datap) - "Returns the address of the foreign symbol as an integer. On linkage-table -ports if the symbols isn't found a special guard address is returned instead, -accesses to which will result in an UNDEFINED-ALIEN-ERROR. On other ports an -error is immediately signalled if the symbol isn't found. The returned address -is never in the linkage-table." - (declare (ignorable datap)) - (let ((addr (find-dynamic-foreign-symbol-address symbol))) - (cond ((not addr) - (error 'undefined-alien-error :name symbol)) - (t - (setf (gethash symbol symbols) t) - addr)))) - (defun dynamic-foreign-symbols-p () - (plusp (hash-table-count symbols))) - (defun list-dynamic-foreign-symbols () - (loop for symbol being each hash-key in symbols - collect symbol))) diff --git a/src/code/foreign.lisp b/src/code/foreign.lisp index 3650905c2..6aa32fd19 100644 --- a/src/code/foreign.lisp +++ b/src/code/foreign.lisp @@ -14,9 +14,7 @@ (defun find-foreign-symbol-address (name) "Returns the address of the foreign symbol NAME, or NIL. Does not enter the symbol in the linkage table, and never returns an address in the linkage-table." - (or #-linkage-table - (find-foreign-symbol-in-table name *static-foreign-symbols*) - (find-dynamic-foreign-symbol-address name))) + (find-dynamic-foreign-symbol-address name)) ;;; Note that much conditionalization is for nothing at this point, because all ;;; platforms that we care about implement dlopen(). But if one did not, only @@ -28,23 +26,13 @@ symbol in the linkage table, and never returns an address in the linkage-table." ;;; flexibility of recompiling C without recompiling Lisp. (defun foreign-symbol-address (name &optional datap) "Returns the address of the foreign symbol NAME. DATAP must be true if the -symbol designates a variable (used only on linkage-table platforms). -Returns a secondary value T if the symbol is a dynamic foreign symbol. +symbol designates a variable. +Returns a secondary value T for historical reasons. -On linkage-table ports the returned address is always static: either direct -address of a static symbol, or the linkage-table address of a dynamic one. -Dynamic symbols are entered into the linkage-table if they aren't there already. - -On non-linkage-table ports signals an error if the symbol isn't found." +The returned address is always a linkage-table address. +Symbols are entered into the linkage-table if they aren't there already." (declare (ignorable datap)) - #+linkage-table - (values (ensure-foreign-symbol-linkage name datap) t) - #-linkage-table - (let ((static (find-foreign-symbol-in-table name *static-foreign-symbols*))) - (if static - (values static nil) - #+os-provides-dlopen (values (ensure-dynamic-foreign-symbol-address name) t) - #-os-provides-dlopen (error 'undefined-alien-error :name name)))) + (values (ensure-foreign-symbol-linkage name datap) t)) (defun foreign-symbol-sap (symbol &optional datap) "Returns a SAP corresponding to the foreign symbol. DATAP must be true if the @@ -52,9 +40,6 @@ symbol designates a variable (used only on linkage-table platforms). May enter the symbol into the linkage-table. On non-linkage-table ports signals an error if the symbol isn't found." (declare (ignorable datap)) - #-linkage-table - (int-sap (foreign-symbol-address symbol)) - #+linkage-table (multiple-value-bind (addr sharedp) (foreign-symbol-address symbol datap) ;; If the address is from linkage-table and refers to data @@ -66,21 +51,12 @@ if the symbol isn't found." (defun foreign-reinit () #+os-provides-dlopen (reopen-shared-objects) - #+linkage-table (update-linkage-table t)) + (update-linkage-table t)) ;;; Cleanups before saving a core (defun foreign-deinit () - #+(and os-provides-dlopen (not linkage-table)) - (when (dynamic-foreign-symbols-p) - (warn "~@" (list-dynamic-foreign-symbols))) ;; Clobber list of undefineds. Reinit will figure it all out again. - #+linkage-table (setf (cdr *linkage-info*) nil) + (setf (cdr *linkage-info*) nil) #+os-provides-dlopen (close-shared-objects)) @@ -89,7 +65,6 @@ if the symbol isn't found." (declare (ignorable sap)) (let ((addr (sap-int sap))) (declare (ignorable addr)) - #+linkage-table (when (<= sb-vm:linkage-table-space-start addr sb-vm:linkage-table-space-end) @@ -119,15 +94,8 @@ if the symbol isn't found." ;; static foreign symbols (and *linkage-info*, for that matter). )) -;;; How we learn about foreign symbols and dlhandles initially -(defvar *!initial-foreign-symbols*) - (defun !foreign-cold-init () (declare (special *runtime-dlhandle* *shared-objects*)) - #-linkage-table - (dovector (symbol *!initial-foreign-symbols*) - (setf (gethash (car symbol) *static-foreign-symbols*) (cdr symbol))) - #+linkage-table (loop for table-offset from 0 and reference across (symbol-value 'sb-vm::+required-foreign-symbols+) do (setf (gethash reference (car *linkage-info*)) table-offset)) diff --git a/src/code/globals.lisp b/src/code/globals.lisp index 4576ef02b..a06e6e752 100644 --- a/src/code/globals.lisp +++ b/src/code/globals.lisp @@ -95,7 +95,6 @@ *posix-argv*)) ;;; This constant is assigned by Genesis and never read by Lisp code. ;;; (To prove that it isn't used, it's not a toplevel form) -#+linkage-table (let () (defconstant sb-vm::+required-foreign-symbols+ (symbol-value 'sb-vm::+required-foreign-symbols+))) diff --git a/src/compiler/dump.lisp b/src/compiler/dump.lisp index 81451c1df..f6ea36822 100644 --- a/src/compiler/dump.lisp +++ b/src/compiler/dump.lisp @@ -943,7 +943,7 @@ ;; but its global value must be an immobile object. :immobile-symbol :symbol-value) (the symbol name)) - ((:foreign #+linkage-table :foreign-dataref) (the string name)) + ((:foreign :foreign-dataref) (the string name)) ((:named-call :static-call) name)))) (dump-object operand fasl-output) (dump-integer info fasl-output)) diff --git a/src/compiler/fndb.lisp b/src/compiler/fndb.lisp index 238dc0296..85097a55d 100644 --- a/src/compiler/fndb.lisp +++ b/src/compiler/fndb.lisp @@ -1963,7 +1963,6 @@ (defknown sb-vm::touch-object (t) (values) (always-translatable)) -#+linkage-table (defknown foreign-symbol-dataref-sap (simple-string) system-area-pointer (movable flushable)) diff --git a/src/compiler/generic/early-vm.lisp b/src/compiler/generic/early-vm.lisp index 8f8222179..4486cf5f1 100644 --- a/src/compiler/generic/early-vm.lisp +++ b/src/compiler/generic/early-vm.lisp @@ -109,7 +109,6 @@ (let ((stop (1- (ash 1 n-word-bits))) (start dynamic-space-start)) (dolist (other-start (list read-only-space-start static-space-start - #+linkage-table linkage-table-space-start)) (declare (notinline <)) ; avoid dead code note (when (< start other-start) diff --git a/src/compiler/generic/genesis.lisp b/src/compiler/generic/genesis.lisp index 3152c4a6c..2a7576b4c 100644 --- a/src/compiler/generic/genesis.lisp +++ b/src/compiler/generic/genesis.lisp @@ -2010,68 +2010,6 @@ core and return a descriptor to it." (defvar *cold-foreign-symbol-table*) (declaim (type hash-table *cold-foreign-symbol-table*)) -;; Read the sbcl.nm file to find the addresses for foreign-symbols in -;; the C runtime. -#-linkage-table -(defun load-cold-foreign-symbol-table (filename) - (with-open-file (file filename) - (loop for line = (read-line file nil nil) - while line do - ;; UNIX symbol tables might have tabs in them, and tabs are - ;; not in Common Lisp STANDARD-CHAR, so there seems to be no - ;; nice portable way to deal with them within Lisp, alas. - ;; Fortunately, it's easy to use UNIX command line tools like - ;; sed to remove the problem, so it's not too painful for us - ;; to push responsibility for converting tabs to spaces out to - ;; the caller. - ;; - ;; Other non-STANDARD-CHARs are problematic for the same reason. - ;; Make sure that there aren't any.. - (let ((ch (find-if (lambda (char) - (not (typep char 'standard-char))) - line))) - (when ch - (error "non-STANDARD-CHAR ~S found in foreign symbol table:~%~S" - ch - line))) - (setf line (string-trim '(#\space) line)) - (let ((p1 (position #\space line :from-end nil)) - (p2 (position #\space line :from-end t))) - (if (not (and p1 p2 (< p1 p2))) - ;; KLUDGE: It's too messy to try to understand all - ;; possible output from nm, so we just punt the lines we - ;; don't recognize. We realize that there's some chance - ;; that might get us in trouble someday, so we warn - ;; about it. - (warn "ignoring unrecognized line ~S in ~A" line filename) - (multiple-value-bind (value name) - (if (string= "0x" line :end2 2) - (values (parse-integer line :start 2 :end p1 :radix 16) - (subseq line (1+ p2))) - (values (parse-integer line :end p1 :radix 16) - (subseq line (1+ p2)))) - (multiple-value-bind (old-value found) - (gethash name *cold-foreign-symbol-table*) - (when (and found - (not (= old-value value))) - (warn "redefining ~S from #X~X to #X~X" - name old-value value))) - (setf (gethash name *cold-foreign-symbol-table*) value)))))) - (values)) ;; PROGN - -#-linkage-table -(defun cold-foreign-symbol-address (name) - (declare (ignorable name)) - #+crossbuild-test #xf00fa8 ; any random 4-octet-aligned value should do - #-crossbuild-test - (or (find-foreign-symbol-in-table name *cold-foreign-symbol-table*) - (progn - (format *error-output* "~&The foreign symbol table is:~%") - (maphash (lambda (k v) - (format *error-output* "~&~S = #X~8X~%" k v)) - *cold-foreign-symbol-table*) - (error "The foreign symbol ~S is undefined." name)))) - (defvar *cold-assembler-routines*) (defvar *cold-static-call-fixups*) @@ -2236,7 +2174,6 @@ Legal values for OFFSET are -4, -8, -12, ..." (:absolute (absolute (cdr item))))) (number-to-core (sb-c:pack-code-fixup-locs (absolute) (relative))))) -#+linkage-table (defun linkage-table-note-symbol (symbol-name datap) "Register a symbol and return its address in proto-linkage-table." (sb-vm::linkage-table-entry-address @@ -2244,21 +2181,9 @@ Legal values for OFFSET are -4, -8, -12, ..." *cold-foreign-symbol-table* (hash-table-count *cold-foreign-symbol-table*)))) -;;; *COLD-FOREIGN-SYMBOL-TABLE* becomes *!INITIAL-FOREIGN-SYMBOLS* in -;;; the core. When the core is loaded, !LOADER-COLD-INIT uses this to -;;; create *STATIC-FOREIGN-SYMBOLS*, which the code in -;;; target-load.lisp refers to. (defun foreign-symbols-to-core () (flet ((to-core (list transducer target-symbol) (cold-set target-symbol (vector-in-core (mapcar transducer list))))) - #-linkage-table - ;; Sort by name - (to-core (sort (%hash-table-alist *cold-foreign-symbol-table*) #'string< :key #'car) - (lambda (symbol) - (cold-cons (set-readonly (base-string-to-core (car symbol))) - (number-to-core (cdr symbol)))) - '*!initial-foreign-symbols*) - #+linkage-table ;; Sort by index into linkage table (to-core (sort (%hash-table-alist *cold-foreign-symbol-table*) #'< :key #'cdr) (lambda (pair &aux (key (car pair)) @@ -2780,17 +2705,9 @@ Legal values for OFFSET are -4, -8, -12, ..." (:asm-routine-nil-offset (- (lookup-assembler-reference sym) sb-vm:nil-value)) (:foreign - (let ((sym (base-string-from-core sym))) - #+linkage-table (linkage-table-note-symbol sym nil) - #-linkage-table (cold-foreign-symbol-address sym))) + (linkage-table-note-symbol (base-string-from-core sym) nil)) (:foreign-dataref - (let ((sym (base-string-from-core sym))) - #+linkage-table (linkage-table-note-symbol sym t) - #-linkage-table - (progn (maphash (lambda (k v) - (format *error-output* "~&~S = #X~8X~%" k v)) - *cold-foreign-symbol-table*) - (error "shared foreign symbol in cold load: ~S (~S)" sym kind)))) + (linkage-table-note-symbol (base-string-from-core sym) t)) (:code-object (descriptor-bits code-obj)) #+sb-thread ; ENSURE-SYMBOL-TLS-INDEX isn't defined otherwise (:symbol-tls-index (ensure-symbol-tls-index sym)) @@ -2840,7 +2757,6 @@ Legal values for OFFSET are -4, -8, -12, ..." (* 32 sb-vm:immobile-card-bytes)))) #-gencgc (check sb-vm:dynamic-0-space-start sb-vm:dynamic-0-space-end :dynamic-0) - #+linkage-table (check sb-vm:linkage-table-space-start sb-vm:linkage-table-space-end :linkage-table)))) ;;;; emitting C header file @@ -3336,7 +3252,7 @@ Legal values for OFFSET are -4, -8, -12, ..." "layouts" "type specifiers" "symbols" - #+linkage-table "linkage table"))) + "linkage table"))) (dotimes (i (length sections)) (format t "~4<~@R~>. ~A~%" (1+ i) (nth i sections)))) (format t "=================~2%") @@ -3422,7 +3338,6 @@ III. initially undefined function references (alphabetically): (mapc (lambda (cell) (format t "~X: ~S~%" (car cell) (cdr cell))) (sort (%hash-table-alist *cold-symbols*) #'< :key #'car)) - #+linkage-table (progn (format t "~%~|~%VIII. linkage table:~2%") (dolist (entry (sort (sb-int:%hash-table-alist *cold-foreign-symbol-table*) diff --git a/src/compiler/generic/parms.lisp b/src/compiler/generic/parms.lisp index 8692269c7..c6eef728a 100644 --- a/src/compiler/generic/parms.lisp +++ b/src/compiler/generic/parms.lisp @@ -205,8 +205,9 @@ ;; threading support #+sb-thread ,@'(sb-thread::*starting-threads* *free-tls-index*) - ;; dynamic runtime linking support - #+linkage-table +required-foreign-symbols+ + ;; runtime linking of lisp->C calls (regardless of whether + ;; the C function is in a dynamic shared object or not) + +required-foreign-symbols+ ;;; The following symbols aren't strictly required to be static ;;; - they are not accessed from C - but we make them static in order diff --git a/src/compiler/generic/utils.lisp b/src/compiler/generic/utils.lisp index 6b44d944c..97dbe79d7 100644 --- a/src/compiler/generic/utils.lisp +++ b/src/compiler/generic/utils.lisp @@ -50,13 +50,11 @@ 0)) ;;; the address of the linkage table entry for table index I. -#+linkage-table (defun linkage-table-entry-address (i) (ecase linkage-table-growth-direction (:up (+ (* i linkage-table-entry-size) linkage-table-space-start)) (:down (- linkage-table-space-end (* (1+ i) linkage-table-entry-size))))) -#+linkage-table (defun linkage-table-index-from-address (addr) (ecase linkage-table-growth-direction (:up diff --git a/src/compiler/saptran.lisp b/src/compiler/saptran.lisp index 0eae26af4..9f112d75c 100644 --- a/src/compiler/saptran.lisp +++ b/src/compiler/saptran.lisp @@ -13,7 +13,6 @@ ;;;; DEFKNOWNs -#+linkage-table (deftransform foreign-symbol-address ((symbol &optional datap) ((constant-arg simple-string) &optional (constant-arg boolean))) @@ -23,11 +22,6 @@ (deftransform foreign-symbol-sap ((symbol &optional datap) (simple-string &optional boolean)) - #-linkage-table - (if (null datap) - (give-up-ir1-transform) - `(foreign-symbol-sap symbol)) - #+linkage-table (if (and (constant-lvar-p symbol) (constant-lvar-p datap)) (if (lvar-value datap) `(foreign-symbol-dataref-sap symbol) diff --git a/src/compiler/target-disassem.lisp b/src/compiler/target-disassem.lisp index 6bbd1cda1..bb7d02ff7 100644 --- a/src/compiler/target-disassem.lisp +++ b/src/compiler/target-disassem.lisp @@ -2265,9 +2265,7 @@ name->addr))) (let ((code sb-fasl:*assembler-routines*)) (invert (%code-debug-info code) - (lambda (x) (sap-int (sap+ (code-instructions code) (car x)))))) - #-linkage-table - (invert *static-foreign-symbols* #'identity)) + (lambda (x) (sap-int (sap+ (code-instructions code) (car x))))))) (loop for name across sb-vm::+all-static-fdefns+ for address = #+immobile-code (sb-vm::function-raw-address name) @@ -2503,7 +2501,6 @@ (unless (typep address 'address) (return-from maybe-note-assembler-routine nil)) (multiple-value-bind (name offs) (find-assembler-routine address) - #+linkage-table (unless name (setq name (sap-foreign-symbol (int-sap address)))) (when name diff --git a/src/runtime/os-common.c b/src/runtime/os-common.c index 8ad3734b8..501f68af9 100644 --- a/src/runtime/os-common.c +++ b/src/runtime/os-common.c @@ -138,10 +138,9 @@ os_sem_destroy(os_sem_t *sem) #endif -/* When :LINKAGE-TABLE is enabled, the special category of /static/ foreign - * symbols disappears. Foreign fixups are resolved to linkage table locations - * during genesis, and for each of them a record is added to - * REQUIRED_FOREIGN_SYMBOLS vector, of the form "name" for a function reference, +/* Genesis-time foreign fixups are resolved to linkage table locations + * and for each of them a record is added to the REQUIRED_FOREIGN_SYMBOLS + * vector, of the form "name" for a function reference, * or ("name") for a data reference. "name" is a base-string. * * Before any code in lisp image can be called, we have to resolve all @@ -149,7 +148,7 @@ os_sem_destroy(os_sem_t *sem) * table entry for each element of REQUIRED_FOREIGN_SYMBOLS. */ -#if defined(LISP_FEATURE_LINKAGE_TABLE) && !defined(LISP_FEATURE_WIN32) +#ifndef LISP_FEATURE_WIN32 void * os_dlsym_default(char *name) { @@ -161,12 +160,6 @@ os_dlsym_default(char *name) int lisp_linkage_table_n_prelinked; void os_link_runtime() { - // There is a potentially better technique we could use which would simplify - // this function, rendering REQUIRED_FOREIGN_SYMBOLS unnecessary, namely: - // all we need are two prefilled entries: one for dlsym() itself, and one - // for the allocation region overflow handler ("alloc" or "alloc_tramp"). - // Lisp can fill in the linkage table as the very first action on startup. -#ifdef LISP_FEATURE_LINKAGE_TABLE int entry_index = 0; lispobj symbol_name; char *namechars; @@ -195,7 +188,6 @@ void os_link_runtime() ++entry_index; } -#endif /* LISP_FEATURE_LINKAGE_TABLE */ } void os_unlink_runtime() diff --git a/src/runtime/win32-os.c b/src/runtime/win32-os.c index 73b3e0289..37ae244d5 100644 --- a/src/runtime/win32-os.c +++ b/src/runtime/win32-os.c @@ -304,7 +304,6 @@ void unmap_gc_page() #endif -#if defined(LISP_FEATURE_LINKAGE_TABLE) /* This feature has already saved me more development time than it * took to implement. In its current state, ``dynamic RT<->core * linking'' is a protocol of initialization of C runtime and Lisp @@ -598,8 +597,6 @@ void* os_dlsym_default(char* name) return result; } -#endif /* LINKAGE_TABLE */ - #if defined(LISP_FEATURE_SB_THREAD) /* We want to get a slot in TIB that (1) is available at constant offset, (2) is our private property, so libraries wouldn't legally