Changeset 10813

Show
Ignore:
Timestamp:
06/20/05 16:22:49 (3 years ago)
Author:
rtoy
Message:
  • code/foreign.lisp (load-object-file): Take the truename of FILE in case we're given a logical pathname.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/code/foreign.lisp

    r10397 r10513  
    2929 
    3030(defvar *previous-linked-object-file* nil) 
    31 #-(or openbsd linux irix) 
     31#-(or linux bsd svr4 irix) 
    3232(defvar *foreign-segment-free-pointer* foreign-segment-start) 
    3333 
     
    8787;;; /usr/include/sys/elf_common.h and /usr/include/sys/elf32.h. 
    8888;;; 
    89 #+(or linux bsd svr4) 
     89#+(or linux (and bsd (not darwin)) svr4) 
    9090(progn 
    9191(alien:def-alien-type elf-address      (alien:unsigned 32)) 
     
    207207        (when (elf-p (alien:slot header 'elf-ident)) 
    208208          (eql et-shared-object (alien:slot header 'elf-type))))))) 
    209 ) ;; #+(or linux bsd svr4) 
     209) ;; #+(or linux (and bsd (not darwin)) svr4) 
     210  
     211 
     212 
     213;; Darwin loading of foreign code.  This uses the dlopen shims and thus 
     214;; appears like ELF to the rest of the code in this file.  However testing 
     215;; for shared libs obviously needs to test for Mach-O dylibs, and not 
     216;; ELF shared libraries... 
     217#+darwin 
     218(progn 
     219 
     220(alien:def-alien-type machheader 
     221  (alien:struct nil 
     222    (magic       (alien:unsigned 32)) 
     223    (cputype     (alien:signed 32)) 
     224    (cpusubtype  (alien:signed 32)) 
     225    (filetype    (alien:unsigned 32)) 
     226    (ncmds       (alien:unsigned 32)) 
     227    (sizeofcmds  (alien:unsigned 32)) 
     228    (flags       (alien:unsigned 32)))) 
     229 
     230;; values for magic 
     231(defconstant mh-magic   #xfeedface) 
     232 
     233;; values for filetype 
     234(defconstant mh-object        #x1) 
     235(defconstant mh-execute       #x2) 
     236(defconstant mh-fvmlib        #x3) 
     237(defconstant mh-core          #x4) 
     238(defconstant mh-preload       #x5) 
     239(defconstant mh-dylib         #x6) 
     240(defconstant mh-dylinker      #x7) 
     241(defconstant mh-bundle        #x8) 
     242(defconstant mh-dylib-stub    #x9) 
     243 
     244(defun mach-o-p (h) 
     245  "Make sure the header starts with the mach-o magic value." 
     246  (eql (alien:slot h 'magic) mh-magic)) 
     247 
     248(defun file-shared-library-p (pathname) 
     249  (with-open-file (obj pathname 
     250                       :direction :input 
     251                       :element-type '(unsigned-byte 8)) 
     252    (let ((fd (lisp::fd-stream-fd obj))) 
     253      (alien:with-alien ((header machheader)) 
     254        (unix:unix-read fd (alien:alien-sap header) 
     255                        (alien:alien-size machheader :bytes)) 
     256        (when (mach-o-p header) 
     257          (or (eql mh-dylib (alien:slot header 'filetype)) 
     258              (eql mh-bundle (alien:slot header 'filetype)))))))) 
     259) ; #+darwin 
    210260  
    211261 
     
    706756                        (list* 
    707757                         #+(or solaris linux FreeBSD4) "-G" 
    708                          #+(or OpenBSD irix) "-shared" 
     758                         #+(or OpenBSD NetBSD irix) "-shared" 
     759                         #+darwin "-dylib" 
    709760                         "-o" 
    710761                         output-file 
    711762                         ;; Cause all specified libs to be loaded in full 
    712                          #+(or OpenBSD linux FreeBSD4) "--whole-archive" 
     763                         #+(or OpenBSD linux FreeBSD4 NetBSD) "--whole-archive" 
    713764                         #+solaris "-z" #+solaris "allextract" 
     765                         #+darwin "-all_load" 
    714766                         (append (mapcar 
    715767                                  #'(lambda (name) 
     
    726778                                 ;; Return to default ld behaviour for libs 
    727779                                 (list 
    728                                   #+(or OpenBSD linux FreeBSD4) 
     780                                  #+(or OpenBSD linux FreeBSD4 NetBSD) 
    729781                                  "--no-whole-archive" 
    730782                                  #+solaris "-z" #+solaris "defaultextract")