(in-package "SB!IMPL")
+#!-(or elf mach-o)
+(error "Not an ELF or Mach-O platform?")
+
+(defun extern-alien-name (name)
+ (handler-case
+ #!+elf (coerce name 'base-string)
+ #!+mach-o (concatenate 'base-string "_" name)
+ (error ()
+ (error "invalid external alien name: ~S" name))))
+
;;; *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
(defvar *static-foreign-symbols* (make-hash-table :test 'equal))
(defun find-foreign-symbol-in-table (name table)
- (some (lambda (prefix)
- (gethash (concatenate 'string prefix name) table))
- #("" "ldso_stub__")))
+ (let ((extern (extern-alien-name name)))
+ (or (gethash extern table)
+ (gethash (concatenate 'base-string "ldso_stub__" extern) table))))
(defun foreign-symbol-address-as-integer-or-nil (name &optional datap)
(declare (ignorable datap))
(progn
#-sb-xc-host
(values #!-linkage-table
- (get-dynamic-foreign-symbol-address name)
+ (get-dynamic-foreign-symbol-address name datap)
#!+linkage-table
(ensure-foreign-symbol-linkage name datap)
t))))
(defun foreign-symbol-address (symbol &optional datap)
(declare (ignorable datap))
- (let ((name (sb!vm:extern-alien-name symbol)))
- #!-linkage-table
- (int-sap (foreign-symbol-address-as-integer name))
- #!+linkage-table
- (multiple-value-bind (addr sharedp)
- (foreign-symbol-address-as-integer name datap)
- #+sb-xc-host
- (aver (not sharedp))
- ;; If the address is from linkage-table and refers to data
- ;; we need to do a bit of juggling.
- (if (and sharedp datap)
- ;; FIXME: 64bit badness here
- (int-sap (sap-ref-32 (int-sap addr) 0))
- (int-sap addr)))))
+ #!-linkage-table
+ (int-sap (foreign-symbol-address-as-integer symbol))
+ #!+linkage-table
+ (multiple-value-bind (addr sharedp)
+ (foreign-symbol-address-as-integer symbol datap)
+ #+sb-xc-host
+ (aver (not sharedp))
+ ;; If the address is from linkage-table and refers to data
+ ;; we need to do a bit of juggling.
+ (if (and sharedp datap)
+ (int-sap (sap-ref-word (int-sap addr) 0))
+ (int-sap addr))))
#-sb-xc-host
(defun foreign-reinit ()
#!+os-provides-dlopen
(reopen-shared-objects)
#!+linkage-table
- (linkage-table-reinit))
+ (update-linkage-table))
;;; Cleanups before saving a core
#-sb-xc-host
;; get dynamic symbols thru the runtime as well, so cheking the
;; list of *shared-objects* is not enough. Eugh & blech.
#!+(and os-provides-dlopen (not linkage-table))
- (warn "~@<Saving cores with alien definitions referring to non-static
- foreign symbols is unsupported on this platform: references to
- such foreign symbols from the restarted core will not work. You
- may be able to work around this limitation by reloading all
- foreign definitions and code using them in the restarted core,
- but no guarantees.~%~:@>")
+ (when (dynamic-foreign-symbols)
+ (warn "~@<Saving cores with alien definitions referring to non-static ~
+ foreign symbols is unsupported on this platform: references to ~
+ such foreign symbols from the restarted core will not work. You ~
+ may be able to work around this limitation by reloading all ~
+ foreign definitions and code using them in the restarted core, ~
+ but no guarantees.~%~%Dynamic foreign symbols in this core: ~
+ ~{~A~^, ~}~:@>" (dynamic-foreign-symbols)))
#!+os-provides-dlopen
(close-shared-objects))
(dolist (symbol *!initial-foreign-symbols*)
(setf (gethash (car symbol) *static-foreign-symbols*) (cdr symbol)))
#!+os-provides-dlopen
- (setf *runtime-dlhandle* (dlopen-or-lose nil)
+ (setf *runtime-dlhandle* (dlopen-or-lose)
*shared-objects* nil))
#!-os-provides-dlopen