
@K7]c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 m Z e j d e j  d Z d Z d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z e e e e e f Z d Z d e BZ e j  d Z! e! d k r4e" e d  p@e" e d  Z# d e$ f d     YZ% d e& f d     YZ' d e& f d     YZ( d  e& f d!     YZ) d" d#  Z* d$   Z+ d%   Z, d&   Z- d'   Z. d( e& f d)     YZ/ d*   Z0 d+   Z1 d, d-  Z2 d.   Z3 d/ d d/ d d0  Z5 d1   Z6 d2 e) f d3     YZ7 d4 Z8 d" Z9 d5 Z: d Z; d6 Z< d Z= d5 Z> d Z? d7 Z@ d8 ZA d9 ZB d: ZC d; ZD d< ZE d= ZF d> ZG d ZH d" ZI d5 ZJ d ZK d6 ZL d? ZM d@ ZN dA ZO dB ZP dC ZQ eO dD ZR eO dE ZS eO dF ZT d" ZU d5 ZV d ZW d6 ZX d? ZY d@ ZZ dG Z[ d7 Z\ dH Z] dI Z^ dJ Z_ dK Z` dL Za dM Zb dN Zc dO Zd dP Ze dA Zf d" Zg d5 Zh d6 Zi dM Zj d Zk dQ Zl dR Zm dS Zn dT Zo dU Zp dV Zq dW Zr dX Zs dY Zt d Zu d" Zv d5 Zw d Zx d6 Zy d? Zz d@ Z{ dG Z| d7 Z} dH Z~ dI Z dJ Z d Z d Z dK Z dL Z dM Z dN Z dO Z dP Z d8 Z dZ Z d[ Z d\ Z d Z d] Z d^ Z d_ Z d Z d` Z dA Z da Z dB Z dC Z db e& f dc     YZ dd e& f de     YZ df e& f dg     YZ dh e) f di     YZ dj e) f dk     YZ dl e) f dm     YZ dn e& f do     YZ dp g  dq  Z e dr  Z e ds  Z e dt  Z du   Z dv   Z d/ dw dx  Z e e d/ dw dy  Z dw dz  Z e e d/ dw d{  Z dw d|  Z d}   Z d~   Z d   Z d   Z d   Z d   Z d   Z e d k re j e    n  d S(   i(   t   print_functionN(   t   ensure_listt
   get_loggert   levels  
Usage: ldd [OPTION]... FILE...
      --help              print this help and exit
      --version           print version information and exit
  -d, --data-relocs       process data relocations
  -r, --function-relocs   process data and function relocations
  -u, --unused            print unused direct dependencies
  -v, --verbose           print all information

For bug reporting instructions, please see:
<https://bugs.archlinux.org/>.
sp  
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool [-arch arch_type] [-fahlLDtdorSTMRIHGvVcXmqQjCP] [-mcpu=arg] [--version] <object file> ...
    -f print the fat headers
    -a print the archive header
    -h print the mach header
    -l print the load commands
    -L print shared libraries used
    -D print shared library id name
    -t print the text section (disassemble with -v)
    -p <routine name>  start dissassemble from routine name
    -s <segname> <sectname> print contents of section
    -d print the data section
    -o print the Objective-C segment
    -r print the relocation entries
    -S print the table of contents of a library
    -T print the table of contents of a dynamic shared library
    -M print the module table of a dynamic shared library
    -R print the reference table of a dynamic shared library
    -I print the indirect symbol table
    -H print the two-level hints table
    -G print the data in code table
    -v print verbosely (symbolically) when possible
    -V print disassembled operands symbolically
    -c print argument strings of a core file
    -X print no leading addresses or headers
    -m don't use archive(member) syntax
    -B force Thumb disassembly (ARM objects only)
    -q use llvm's disassembler (the default)
    -Q use otool(1)'s disassembler
    -mcpu=arg use `arg' as the cpu for disassembly
    -j print opcode bytes
    -P print the info plist section as strings
    -C print linker optimization hints
    --version print the version of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool
I    I    I    I    I    t   >t   <i   i   i   i#   i   i    I       i   i    i   t   maxsizet   maxintt   IncompleteReadc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s   t   ReadCheckWrapperc           B  s)   e  Z d  Z d   Z d   Z d   Z RS(   sG   
    Wrap a file-object to raises a exception on incomplete reads.
    c         C  s   | |  _  d  S(   N(   t	   _file_obj(   t   selft   file_obj(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   __init__   s    c         C  s7   |  j  j |  } t |  | k r3 t d   n  | S(   Ns(   requested number of bytes were not read.(   R   t   readt   lenR   (   R   t   sizet   buf(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s    c         C  s'   | d k r |  j  St |  j |  Sd  S(   NR   (   R   t   getattrR   (   R   t   attr(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   __getattr__   s    (   R	   R
   t   __doc__R   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s   		t   fileviewc           B  sY   e  Z d  Z d e d  Z d   Z d   Z d   Z d d  Z d   Z	 e d  Z
 RS(	   sh   
    A proxy for file-like objects that exposes a given view of a file.
    Modified from macholib.
    i    c         C  sJ   t  | t  r | j |  _ n	 | |  _ | |  _ | | |  _ d |  _ d  S(   Ni    (   t
   isinstanceR   t   _fileobjt   _startt   _endt   _pos(   R   t   fileobjt   startR   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s    		c         C  s   d |  j  |  j |  j f S(   Ns   <fileview [%d, %d] %r>(   R   R   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   __repr__   s    c         C  s   |  j  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   tell   s    c         C  sK   |  j  | k o |  j k n sG t d | | |  j  |  j f   n  d  S(   Ns*   %s to offset %d is outside window [%d, %d](   R   R   t   IOError(   R   t   seektot   op(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   _checkwindow   s    "c         C  s   | } | t  j k r% | |  j 7} nX | t  j k rK | |  j |  j 7} n2 | t  j k rj | |  j 7} n t d | f   |  j | d  |  j	 j
 |  | |  j |  _ d  S(   Ns#   Invalid whence argument to seek: %rt   seek(   t   ost   SEEK_SETR   t   SEEK_CURR   t   SEEK_ENDR   R"   R%   R   R&   (   R   t   offsett   whenceR#   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR&      s    c         C  sy   |  j  |  j } |  j | d  |  j | t |  d  |  j j | t j  |  j j |  |  j t |  7_ d  S(   Nt   write(	   R   R   R%   R   R   R&   R'   R(   R-   (   R   t   bytest   here(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR-      s    c         C  s   | d k s t   |  j |  j } |  j | d  t | |  j |  } |  j j | t j	  |  j j
 |  } |  j t |  7_ | S(   Ni    R   (   t   AssertionErrorR   R   R%   t   minR   R   R&   R'   R(   R   R   (   R   R   R/   R.   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s    (   R	   R
   R   R   R   R    R!   R%   R&   R-   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s   					t   UnixExecutablec           B  sJ   e  Z g  d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C  s1   g  |  _  g  |  _ g  |  _ g  |  _ | |  _ d  S(   N(   t   rpaths_transitivet   rpaths_nontransitivet   shared_librariest
   dt_runpatht	   dt_soname(   R   t   filet   initial_rpaths_transitive(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s
    				c         C  s   |  j  S(   N(   R3   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_rpaths_transitive   s    c         C  s   |  j  S(   N(   R4   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_rpaths_nontransitive   s    c         C  s   |  j  S(   N(   R5   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_shared_libraries   s    c         C  s   t  S(   N(   t   True(   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   is_executable   s    c         C  s   |  j  S(   N(   R6   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_runpaths   s    c         C  s   |  j  S(   N(   R7   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt
   get_soname   s    (	   R	   R
   R   R:   R;   R<   R>   R?   R@   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR2      s   					i   c         C  sE   t  j | d | |  j | d   } t |  d k rA | d S| S(   sm   
    Read a given number of 32-bits unsigned integers from the given file
    with the given endianness.
    t   Li   i   i    (   t   structt   unpackR   R   (   R8   t   endiant   numt   res(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt	   read_data   s    'c   
      C  s   | t  @t k r t |  |  } |  j | | t j  |  j | |  j   }	 |	 |	 j d   }	 |	 | k r |  j | | t j  |  j	 | j
   d j
    t Sn  t S(   Ns    (   t   LC_REQ_DYLDt   LC_LOAD_DYLIBSRG   R&   R'   R(   R   t   decodet   indexR-   t   encodeR=   t   False(
   R8   t   wheret   bitsRD   t   cmdt   cmdsizet   whatt   valt   name_offsett   load(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   replace_lc_load_dylib
  s    c   	      C  s   | t  @t k r| t |  |  } |  j | | t j  |  j | |  j   } | | j d   } t	 j
 | |  r| | Sn  d  S(   Ns    (   RH   RI   RG   R&   R'   R(   R   RJ   RK   t   ret   match(	   R8   RN   RO   RD   RP   RQ   RR   RT   RU   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   find_lc_load_dylib  s    c         C  sf   | t  k rb t |  |  } |  j | | t j  |  j | |  j   } | | j d   } | Sd  S(   Ns    (   t   LC_RPATHRG   R&   R'   R(   R   RJ   RK   (   R8   RN   RO   RD   RP   RQ   RT   RU   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   find_lc_rpath+  s    c      
   G  s   t  |  | d  \ } } } } }	 }
 | d k r@ t  |  |  n  g  } xt t |  D]f } |  j   } t  |  | d  \ } } | j | |  | | | | | |   |  j | | t j  qS W| | f S(   Ni   i@   i   (   RG   t   rangeR!   t   appendR&   R'   R(   (   R8   RO   RD   t   lc_operationt   argst   _cputypet   _cpusubtypet   filetypet   ncmdst   _sizeofcmdst   _flagst   resultst   _nRN   RP   RQ   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   do_macho8  s    $
t   offset_sizec           B  s   e  Z d  e d  Z RS(   i    c         C  s   | |  _  | |  _ d  S(   N(   R+   R   (   R   R+   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR   M  s    	(   R	   R
   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyRi   L  s   c         G  s  t  |  | j | j  }  t |  t  } | t k r t |  t  } xBt |  D]I } t |  t d  \ }	 }
 } } } t |  | t | |  | | |  qO Wn | t	 k r | d
 k r | j
 t |  d t | |   n | t k r| d k r| j
 t |  d t | |   nt | t k rM| d k rM| j
 t |  d t | |   n: | t k r| d k r| j
 t |  d t | |   n  d  S(   Ni   t   anyt   ppc32t   m68ki    t   i386t   ppc64i@   t   x86_64(   Rj   Rk   Rl   (   Rj   Rm   (   Rj   Rn   (   Rj   Ro   (   R   R+   R   RG   t
   BIG_ENDIANt	   FAT_MAGICR\   t   do_fileRi   t   MH_MAGICR]   Rh   t   MH_CIGAMt   LITTLE_ENDIANt   MH_MAGIC_64t   MH_CIGAM_64(   R8   R^   t   off_szt   archRf   R_   t   magict	   nfat_archRg   R`   Ra   R+   R   t   _align(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyRr   R  s     !"""c         C  s_   t  |  t  |  k s t  g  } t |  d  & } t | t t   | | | |  Wd QX| S(   s   
    Replace a given name (what) in any LC_LOAD_DYLIB command found in
    the given binary with a new name (value), provided it's shorter.
    s   r+bN(   R   R0   t   openRr   RV   Ri   (   t   pathRy   RR   t   valueRf   t   f(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   mach_o_changei  s    s   .*c         C  s&   g  } t  |  t t   | | |  | S(   s   
    Finds the executable's view of where any dylibs live
    without resolving any macros (@rpath, @loader_path, @executable_path)
    (   Rr   RY   Ri   (   t   ofileRy   t   regexRf   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   mach_o_find_dylibsx  s    c         C  s#   g  } t  |  t t   | |  | S(   s&   
    Finds ofile's list of rpaths
    (   Rr   R[   Ri   (   R   Ry   Rf   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   mach_o_find_rpaths  s    t    c           s  d } t }	 | s g  n | j d  }
   j d  r(| rE | g n@ |  j   |
 |  j   g  t |  D] } | j d |  ^ qi } x | D] }   j d |  j d |  j d |  } t j	 j
 |  } | o | o | j |  } | s | s | r | } t }	 Pq q W|	 s  d t f Sn t   f d   d	 D  r  j d |  j d |  } t j	 j
 |  } | o| o| j |  } n8   j d  r  d t f St j	 j |    d t f S| | | f S(
   sU  
       From `man ld.so`

       When resolving shared object dependencies, the dynamic linker first inspects each dependency
       string to see if it contains a slash (this can occur if a shared object pathname containing
       slashes was specified at link time).  If a slash is found, then the dependency string is
       interpreted as a (relative or absolute) pathname, and the shared object is loaded using that
       pathname.

       If a shared object dependency does not contain a slash, then it is searched for in the
       following order:

       o Using the directories specified in the DT_RPATH dynamic section attribute of the binary
         if present and DT_RUNPATH attribute does not exist.  Use of DT_RPATH is deprecated.

       o Using the environment variable LD_LIBRARY_PATH (unless the executable is being run in
         secure-execution mode; see below).  in which case it is ignored.

       o Using the directories specified in the DT_RUNPATH dynamic section attribute of the
         binary if present. Such directories are searched only to find those objects required
         by DT_NEEDED (direct dependencies) entries and do not apply to those objects' children,
         which must themselves have their own DT_RUNPATH entries. This is unlike DT_RPATH,
         which is applied to searches for all children in the dependency tree.

       o From the cache file /etc/ld.so.cache, which contains a compiled list of candidate
         shared objects previously found in the augmented library path. If, however, the binary
         was linked with the -z nodeflib linker option, shared objects in the default paths are
         skipped. Shared objects installed in hardware capability directories (see below) are
         preferred to other shared objects.

       o In the default path /lib, and then /usr/lib. (On some 64-bit architectures, the default
         paths for 64-bit shared objects are /lib64, and then /usr/lib64.)  If the binary was
         linked with the -z nodeflib linker option, this step is skipped.

       Returns a tuple of resolved location, rpath_used, in_sysroot
    t   :s   $RPATHs   $SYSROOTs   $SELFDIRs   $EXEDIRc         3  s   |  ] } |   k Vq d  S(   N(    (   t   .0t   a(   t
   unresolved(    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pys	   <genexpr>  s    t   /N(   s   $SELFDIRs   $EXEDIR(   t   NoneRM   t   splitt
   startswithR:   R;   R   t   replaceR'   R~   t   existsR=   Rj   t   join(   t   codefileR   t   exe_dirt   self_dirt   LD_LIBRARY_PATHt   default_pathst   sysroott   resolved_rpatht   rpath_resultt   foundt   ld_library_pathst   dpt   these_rpathst   rpatht   resolvedR   t   exists_sysroot(    (   R   s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   _get_resolved_location  s8    ,,c   
      C  sR   t  |  | | |  \ } } } | r- | }	 n t  |  | | | |  }	 | |	 | f S(   N(   R   (
   R   t   sot
   src_exedirt   src_selfdirt
   dst_exedirt   dst_selfdirt   src_resolvedR   t
   in_sysroott   dst_resolved(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt    _get_resolved_relocated_location  s
    	t	   machofilec           B  sD   e  Z g  d   Z d   Z d   Z d d  Z d   Z d   Z RS(   c         C  s-  | j  |  _ g  |  _ g  |  _ t j j | j   |  _ t | |  } | sO d  St	 |   \ } } | j
 d  | |  _ t	 t | |    \ } } g  | d D]$ }	 |	 r |  j |	 j d   ^ q }
 |  j j |
  |
 |  _ |  j j g  | d D]! } | r | |  j |  f ^ q  | j
 d  d  S(   Ni    R   (   t   namet   filenameR5   R6   R'   R~   t   dirnamet   _dirR   t   zipR&   R3   R   t   from_os_varnamest   rstript   extendR4   (   R   R8   Ry   R9   Rf   t   _t   sost
   _filetypest   rpathsR   t   local_rpathsR   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s$    			2		3c         C  s(   | j  d d  j  d d  j  d d  S(   sL   Don't make these functions - they are methods to match the API for elffiles.s   $SELFDIRs   @loader_paths   $EXEDIRs   @executable_paths   $RPATHs   @rpath(   R   (   R   t   input_(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   to_os_varnames  s    c         C  s(   | j  d d  j  d d  j  d d  S(   sL   Don't make these functions - they are methods to match the API for elffiles.s   @loader_paths   $SELFDIRs   @executable_paths   $EXEDIRs   @rpaths   $RPATH(   R   (   R   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR      s    R   c   
      C  s^   g  } xQ |  j  D]F \ } } t |  | | | |  \ } } }	 | j | | | |	 f  q W| S(   N(   R5   R   R]   (
   R   R   R   R   t   resultt   so_origR   R   R   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_resolved_shared_libraries  s
    !c   
      C  s[   g  } xN |  j  D]C } t |  | | | | |  \ } } }	 | j | | | |	 f  q W| S(   N(   R5   R   R]   (
   R   R   R   R   R   R   R   R   R   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_relocated_shared_libraries  s    c         C  s   |  j  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   uniqueness_key  s    (   R	   R
   R   R   R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s   			iFLEi   i   i   i   i(   i*   i2   i>   i   i   i   i   i   `i   piiPtiQtiRti   i	   i
   i   i   i   i   i   i   i   i@   i   i   i   i   i  I       i   i   i   i   i   i   i   i   i   iot	   elfheaderc           B  s   e  Z d    Z d   Z RS(   c         C  s  t  j t d | j d   \ |  _ g  |  _ g  |  _ |  j t k rJ d  St  j t d | j d   \ } | d k r~ d n d } t	 | d  } | d k r d n d } | |  _
 | |  _ | |  _ t  j t d | j d   \ } | d k r t n t } | |  _ t  j | d | j d   \ |  _ t  j | d | j d   \ |  _ t  j | d | j d   \ |  _ t  j | d | j d	   t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d | j d   \ |  _ t  j | | | j |   \ |  _ t  j | | | j |   \ |  _ t  j | | | j |   \ |  _ t  j | d | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ t  j | d
 | j d   \ |  _ | j   } | |  j k rt t  j  d j! | |  j   n  d  S(   NRA   i   t   Bi   i    i@   i   t   Qi   t   Hi   s   file.tell()={} != ehsize={}t   BBBBBBB("   RB   RC   Rp   R   t   hdrt	   dt_neededt   dt_rpatht   ELF_HDRRu   t   intt   bitnesst   sz_ptrt   ptr_typeRD   t   versiont   osabit   abivert   typet   machinet   entryt   phofft   shofft   flagst   ehsizet	   phentsizet   phnumt	   shentsizet   shnumt   shstrndxR!   R   R	   t   warningt   format(   R   R8   R   R   R   RD   t   loc(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     sF    %		"			"	%%%%%%%%%%%%%%%%c         C  s:   d j  |  j |  j |  j |  j t |  j  t |  j   S(   Ns@   bitness {}, endian {}, version {}, type {}, machine {}, entry {}(   R   R   RD   R   R   t   hexR   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   __str__  s    (   R	   R
   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s   	%t
   elfsectionc           B  s   e  Z d    Z d   Z RS(   c         C  s  | j  } | j } | j } t j | d | j d   \ |  _ t j | d | j d   \ |  _ t j | | | j |   \ |  _ t j | | | j |   \ |  _	 t j | | | j |   \ |  _
 t j | | | j |   \ |  _ t j | d | j d   \ |  _ t j | d | j d   \ |  _ t j | | | j |   \ |  _ t j | | | j |   \ |  _ |  j t k rd |  _ n	 d |  _ d  S(   NRA   i   i    i   (   R   R   RD   RB   RC   R   t   sh_namet   sh_typet   sh_flagst   sh_addrt	   sh_offsett   sh_sizet   sh_linkt   sh_infot   sh_addralignt
   sh_entsizet
   SHT_STRTABt   priority(   R   t   ehR8   R   R   RD   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s     			%%%%%%%%%%c         C  s  | j  j } | j  j } | j  j } |  j t k ra | j |  j  | j |  j	  j
   |  _ nB|  j t k rd  } g  } g  } g  }	 d }
 |  j d k r d } n t |  j	 |  j  } x t |  D] } | j |  j | |  j  t j | | | j |   \ } t j | | | j |   \ } | t k rJ| j |  q | t k rf| j |  q | t k r|	 j |  q | t k r| } q | t k r | }
 q q W| r| j |  \ } } | r| j t k rxB | D]: } | | j | j d  } | j j | j | | ! qWx | D] } | | j | j d  } | j | | !} g  | j d  D] } | rl| ^ ql} | j j g  | D] } | j d  ^ q q,Wx |	 D] } | | j | j d  } | j | | !} g  | j d  D] } | r| ^ q} | j  j g  | D] } | j d  ^ q# qW|
 d k r|
 | j |
 j d  } | j |
 | !| _! qqn  t" | j   rg  | _ qn  d  S(   Ns   $EXECUTABLEi    s    R   R   (#   t   ehdrR   R   RD   R   R   R&   R   R   R   RJ   t   tablet   SHT_DYNAMICR   R   R   R\   RB   RC   t	   DT_NEEDEDR]   t   DT_RPATHt
   DT_RUNPATHt	   DT_STRTABt	   DT_SONAMEt   find_section_and_offsetRK   R   R   R   R   R   R6   R7   R   (   R   t   elffileR8   R   R   RD   t   dt_strtab_ptrR   R   R6   R7   t   num_entriest   mt   d_tagt	   d_val_ptrt   strsect   _offsett   nt   endt   rR~   t   pR   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   postprocess  sd    ,	""	(0(0(   R	   R
   R   R  (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s   	t   programheaderc           B  s   e  Z d    Z d   Z RS(   c         C  s  | j  } | j } | j } t j | d | j d   \ |  _ | j d k rw t j | d | j d   \ |  _ n  t j | | | j |   \ |  _	 t j | | | j |   \ |  _
 t j | | | j |   \ |  _ t j | | | j |   \ |  _ t j | | | j |   \ |  _ | j d k rgt j | d | j d   \ |  _ n  t j | | | j |   \ |  _ d  S(   NRA   i   i@   i    (   R   R   RD   RB   RC   R   t   p_typeR   t   p_flagst   p_offsett   p_vaddrt   p_paddrt   p_fileszt   p_memszt   p_align(   R   R   R8   R   R   RD   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR   9  s    			%(%%%%%(c         C  s   |  j  t k rA | j |  j  | j |  j d  j   | _ nx |  j  t k r | j |  j  t	 | d  r | j
 j |  j  | j j |  j  q |  j g | _
 |  j g | _ n  d  S(   Ni   t   ptload_p_vaddr(   R  t	   PT_INTERPR&   R  R   R  RJ   t   program_interpretert   PT_LOADt   hasattrR  R]   R	  t   ptload_p_paddrR
  (   R   R   R8   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR  I  s    "(   R	   R
   R   R  (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR  8  s   	R   c           B  sV   e  Z g  d   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z	 RS(	   c         C  sO  t  |  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ d  |  _ d |  _	 t
 j j | j  |  _ xW t |  j j  D]C } | j |  j j | |  j j  |  j j t |  j |   qy WxW t |  j j  D]C } | j |  j j | |  j j  |  j j t |  j |   q W|  j j d d    x! |  j D] } | j |  |  q:Wx! |  j D] } | j |  |  q^Wg  |  j D] } | j d  ^ q} g  |  j D] } | j d  ^ q} g  | | D] }	 |  j |	  ^ q|  _ g  | D] }	 |  j |	  ^ q|  _ g  |  j D]( }
 |
 d |
 k r5|
 n d |
 f ^ q|  _  d  S(   Ns   $EXECUTABLEt   keyc         S  s   |  j  S(   N(   R   (   t   x(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   <lambda>i  R   R   s   $RPATH/(!   R   R   R   R   R6   t   programheaderst   elfsectionsR   R  R7   R'   R~   R   R   R   R\   R   R&   R   R   R]   R  R   R   R   R   t   sortR  R   R   R3   R4   R5   (   R   R8   R9   R   t   pht   esR  R   R6   R   t   needed(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR   X  s8    							! ! %%&"c         C  s=   |  j  j d k r d } n d } | j d d  j | d  S(   Ni   s   /lib64s   /libs   $SELFDIRs   $ORIGINs   $LIB(   R   R   R   (   R   t   inputt   libdir(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s
    	c         C  s=   |  j  j d k r d } n d } | j d d  j d |  S(   Ni   s   /lib64s   /libs   $ORIGINs   $SELFDIRs   $LIB(   R   R   R   (   R   R  R  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s
    	c         C  sc   x\ |  j  D]Q } | | j k r
 | | j | j k  r
 | j d k rJ q
 n  | | | j f Sq
 Wd S(   sE   Can be called immediately after the elfsections have been constructedi    N(   NN(   R  R   R   R   (   R   t   addrR  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    %R   c         C  s   g  } d d g } |  j  j d k r: | j d d g  n  x` |  j D]U \ } } t |  | | | d d d | d	 | \ } }	 }
 | j | | |	 |
 f  qD W| S(
   Ns   $SYSROOT/libs   $SYSROOT/usr/libi   s   $SYSROOT/lib64s   $SYSROOT/usr/lib64R   R   R   R   (   R   R   R   R5   R   R]   (   R   R   R   R   R   R   R   R   R   R   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   |  j  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   get_dir  s    c         C  s   |  j  S(   N(   R7   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   |  j  S(   N(   R7   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR@     s    (
   R	   R
   R   R   R   R   R   R   R   R@   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR   W  s   *					t   inscrutablefilec           B  sA   e  Z g  d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C  s   d  |  _ d  S(   N(   R   R   (   R   R8   R9   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   g  S(   N(    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR:     s    c         O  s   g  S(   N(    (   R   R_   t   kw(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   g  S(   N(    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR?     s    c         C  s   |  j  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   d S(   Nt   unknown(    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    (   R	   R
   R   R:   R   R?   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR!    s   				t   DLLfilec           B  sA   e  Z g  d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C  s   d  S(   N(    (   R   R8   R9   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   g  S(   N(    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR:     s    c         O  s   g  S(   N(    (   R   R_   R"  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   g  S(   N(    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR?     s    c         C  s   d  S(   N(   R   (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    c         C  s   d S(   NR#  (    (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    (   R	   R
   R   R:   R   R?   R   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR$    s   				t   EXEfilec           B  s   e  Z g  d   Z RS(   c         C  s   |  j  j |  | |  d  S(   N(   t   superR   (   R   R8   R9   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    (   R	   R
   R   (    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR%    s   Rj   c         C  s   |  j  j d  r% t |  t |   St j t d |  j d   \ } |  j d  | t	 t
 t t f k r t |  | t |   S| t k r t |  t |   St |  t |   Sd  S(   Ns   .dllRA   i   i    (   R   t   endswithR$  t   listRB   RC   Rp   R   R&   Rq   Rs   Rt   Rw   R   R   R   R!  (   R8   Ry   R9   Rz   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR     s    "c      	   C  s&  t  j j |   r1 | r d  St  j j |   }  n  t  j j |   rG d  S|  j d	  rZ t S|  j d  rm t S|  j d  r d  St  j j	 |   s t  j j
 |   d k  r d  St |  d  b } t j t d | j d   \ } | j d  | t t t t f k rt S| t k rt SWd  QXd  S(
   Ns   .dlls   .pyds   .exes   .classi   t   rbRA   i    (   s   .dlls   .pyd(   R'   R~   t   islinkR   t   realpatht   isdirR'  R$  R%  R   t   getsizeR}   RB   RC   Rp   R   R&   Rq   Rs   Rt   Rw   R   R   R   (   R   t   skip_symlinksR8   Rz   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   codefile_class  s,    +"
c         C  s    t  |  d | } | s t St S(   NR.  (   R/  RM   R=   (   R   R.  t   klass(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   is_codefile  s    c         C  s#   t  |  d | } | s d S| j S(   s&   Returns None, 'machofile' or 'elffile'R.  N(   R/  R   R	   (   R   R.  R0  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   codefile_type  s    c         C  s<   |  r8 x/ |  j  d  s' |  j  d  r4 |  d  }  q	 Wn  |  S(   NR   s   \i(   R'  (   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   _trim_sysroot  s    !c         C  s[   |  d k rW t  j d k r9 t  j d k r0 d n d }  qW t j   \ } } } } }  n  |  S(   Nt   nativet   win32i   i    Ro   t   i686I       (   t   syst   platformR   R'   t   uname(   Ry   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   _get_arch_if_native$  s
    R4  c      	   C  s  t  j j |   s d g  g  f St |  } t |  } t |  d   } y t t |  |  } Wn7 t	 k
 r t
 t  j d j |    d g  g  f SXt  j j |   } | j | | |  } | s | j   g  g  f St t t |    \ } } }	 }
 | j   | | f SWd QXd S(   sM   

    :param filename:
    :param sysroot:
    :param arch:
    :return:
    R)  s#   problems inspecting linkages for {}N(   R'   R~   R   R   R3  R:  R}   R   R   R   R   R	   R   R   R   R   R   t   mapR(  R   (   R   R   Ry   R   t   cfR   Rf   t
   orig_namest   resolved_namesR   t   _in_sysroot(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   _inspect_linkages_this/  s     	!c         C  s   t  j j |   s g  g  f St |  } t |  } t |  d   } t | | d d g  } | r g  | j D]: } t | | t  j j	 |   t  j j	 |   |  d ^ qn S| r g  | j D] } | j
 |  ^ q S| j SWd  QXd  S(   NR)  s   /libs   /usr/libi    (   R'   R~   R   R3  R:  R}   R   R4   R   R   R   (   R   t   resolve_dirnamest   use_os_varnamesR   Ry   R   R<  R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   inspect_rpathsO  s    
E#c      	   C  s`   t  j j |   s g  St |  } t |  d  ) } t | | d d g  } | j   SWd  QXd  S(   NR)  s   /libs   /usr/lib(   R'   R~   R   R:  R}   R   R?   (   R   Ry   R   R<  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyR?   f  s    c         C  s   t    } t  |  g  } t    } t    } x | | k r t t | |   }  t |  d | d | \ }	 }
 } |	 | k r | r | j |  n | j |
  | r | j |  n  | j |	  n  | j |   q- W| S(   NR   Ry   (   t   sett   nextt   iterR@  t   updatet   add(   R   t   resolve_filenamest   recurseR   Ry   t   already_seent   todot   doneRf   R   t
   these_origt   these_resolved(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   inspect_linkagesp  s"    			c         C  s   d d l  m } d g } | d k r; | j d | g  n | j d t j   d g  | j d |  g  | |  j d d	  } t j d
 | t j  } | S(   Ni(   t   check_outputs   /usr/bin/otoolR4  s   -archi   s   -Lt   encodingt   asciis   ^\t(.*) \(compatibility(	   t
   subprocessRQ  R   R'   R9  RJ   RW   t   findallt	   MULTILINE(   R   Ry   RQ  R_   R   t   groups(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   inspect_linkages_otool  s    	c         C  s   d d l  m } m } | d |  g d | d | } | j   \ } } | j d d  } | j d d  } t j d | t j  } | S(	   Ni(   t   PIPEt   Popens   /usr/bin/lddt   stdoutt   stderrRR  RS  s7   ^\t(?!linux-gate\.so\.1.*$)[^ ]+ => (.*) \([0-9a-fx]+\)(   RT  RY  RZ  t   communicateRJ   RW   RU  RV  (   R   RY  RZ  t   processR   t   errRW  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   inspect_linkages_ldd  s    	c          G  s   t  j d d d t  } | j d d d d | j d d	 d
 d d
 d d | j d d	 d d d | j |   }  |  j r t t  d S|  j r t	 |  j d t d t d |  j
 } t d j |  j |   d Sd S(   Nt   progt   otoolt   add_helps   -hs   --helpt   actiont
   store_trues   -archt   destt	   arch_typet   helpt   defaultR4  s   -LR   s   print shared libraries usedi    RI  RJ  Ry   s0   Shared libs used (non-recursively) by {} are:
{}i   (   t   argparset   ArgumentParserRM   t   add_argumentt
   parse_argsRh  t   printt   OTOOL_USAGER   RP  Rg  R   (   R_   t   parsert   shared_libs(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyRb    s"    	
	
c          G  s.   d d  l  } | j d |   j d d  } | S(   Nis   /usr/bin/otoolRR  RS  (   RT  RQ  RJ   (   R_   RT  R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt	   otool_sys  s    	c          G  s
   g  } | S(   N(    (   R_   R   (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   ldd_sys  s    c          G  s   t  j d d d t  } | j d d d d | j d  | j |   }  |  j ra t t  d	 S|  j r t	 |  j d
 t d t
 } t d j |  j |   d	 Sd S(   NRa  t   lddRc  s   -hs   --helpRd  Re  R   i    RI  RJ  s,   Shared libs used (recursively) by {} are:
{}i   (   Rj  Rk  RM   Rl  Rm  Rh  Rn  t	   LDD_USAGER   RP  R=   R   (   R_   Rp  Rq  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyRt    s    	
		
c         C  s   x t  |  d d !d  d  d   D] \ } } t j d |  rQ t |  d |   St j d |  ru t |  d |   St j j |  r! t |  } | s d S| t	 k r t |  d |   S| t
 k r t d |  d |  Sq! q! Wd S(   Ni    i   is   .*ldd(?:$|\.exe|\.py)s   .*otool(?:$|\.exe|\.py)i   s   -L(   t	   enumerateRW   RX   Rt  Rb  R'   R~   t   isfileR/  R   R   (   t   argvt   idxt   prognameR0  (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   main  s    -c          C  s  t  j d d k rd d  l }  t  j d } | d k re | d k re t  j d k r\ d } qe d } n  d  } g  t  j D]* } t j d |  ru t j d |  ^ qu } t |  r | d j d  \ } t	 j
 j |  } n d	 } | d k r9|  j t d
 | d t d t } t  j d k r0|  j t  } n  d } nZ | d k r|  j t d
 | d t d t } t  j j d  r|  j t  } n  d } n  t j | d |  } g  | D]: }	 t	 j
 j |	  st	 j
 j t	 j |	   r|	 ^ q} x | D] }	 t d j |	   | |	  }
 | r2| |	  } n |
 } t d j |
   t |
  t |  k st d j |	 t |
  t |     qWn t t  j  Sd  S(   Ni   t   testii   Rb  Rt  t   darwins   --sysroot=([^ ]+)R   R   RI  RJ  t   dylibt   linuxR   s   /usr/lib/*.s   
checking {}s   
s4   py-ldd result incorrect for {}, this:
{}
vs that:
{}(   R7  Rx  t	   functoolsR8  R   RW   RX   R   RW  R'   R~   t
   expandusert   partialRP  RM   RX  R=   R   R`  t   globR*  R   t   readlinkRn  R   R   RD  R0   R{  (   R  t   toolt	   test_thatt   argt   sysroot_argsR   t	   test_thist   SOEXTt	   codefilesR   t   thist   that(    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   main_maybe_test  sP    		*		:%t   __main__(   t
   __future__R    Rj  R  R'   RW   RB   R7  t   loggingt   conda_build.utilsR   R   t   basicConfigt   INFORu  Ro  Rs   Rt   Rv   Rw   Rq   Rp   Ru   t   LC_ID_DYLIBt   LC_LOAD_DYLIBt   LC_LOAD_WEAK_DYLIBt   LC_LOAD_UPWARD_DYLIBt   LC_REEXPORT_DYLIBt   LC_LAZY_LOAD_DYLIBRI   RH   RZ   t   version_infot   majverR   R   t	   ExceptionR   t   objectR   R   R2   RG   RV   RY   R[   Rh   Ri   Rr   R   R   R   R   R   R   R   R   t   E_TYPE_RELOCATABLEt   E_TYPE_EXECUTABLEt   E_TYPE_SHAREDt   E_TYPE_COREt   E_MACHINE_UNSPECIFIEDt   E_MACHINE_SPARCt   E_MACHINE_X86t   E_MACHINE_MIPSt   E_MACHINE_POWERPCt   E_MACHINE_ARMt   E_MACHINE_SUPERHt   E_MACHINE_IA_64t   E_MACHINE_X86_64t   E_MACHINE_AARCH64t   E_MACHINE_RISC_Vt   PT_NULLR  t
   PT_DYNAMICR  t   PT_NOTEt   PT_SHLIBt   PT_PHDRt   PT_LOOSt	   PT_LOPROCt	   PT_HIPROCt   PT_GNU_EH_FRAMEt   PT_GNU_STACKt   PT_GNU_RELROt   SHT_PROGBITSt
   SHT_SYMTABR   t   SHT_RELAt   SHT_HASHR   t   SHT_NOTEt
   SHT_NOBITSt   SHT_RELt	   SHT_SHLIBt
   SHT_DYNSYMt   SHT_INIT_ARRAYt   SHT_FINI_ARRAYt   SHT_PREINIT_ARRAYt	   SHT_GROUPt   SHT_SYMTAB_SHNDXt   SHT_NUMt   SHT_LOOSt	   SHF_WRITEt	   SHF_ALLOCt   SHF_EXECINSTRt	   SHF_MERGEt   SHF_STRINGSt   SHF_INFO_LINKt   SHF_LINK_ORDERt   SHF_OS_NONCONFORMINGt	   SHF_GROUPt   SHF_TLSt
   SHF_MASKOSt   SHF_MASKPROCt   SHF_ORDEREDt   SHF_EXCLUDEt   DT_NULLR   t   DT_PLTRELSZt	   DT_PLTGOTt   DT_HASHR   t	   DT_SYMTABt   DT_RELAt	   DT_RELASZt
   DT_RELAENTt   DT_STRSZt	   DT_SYMENTt   DT_INITt   DT_FINIR   R   t   DT_SYMBOLICt   DT_RELt   DT_RELSZt	   DT_RELENTt	   DT_PLTRELt   DT_DEBUGt
   DT_TEXTRELt	   DT_JMPRELt   DT_BIND_NOWt   DT_INIT_ARRAYt   DT_FINI_ARRAYt   DT_INIT_ARRAYSZt   DT_FINI_ARRAYSZR   t   DT_LOOSt   DT_HIOSt	   DT_LOPROCt	   DT_HIPROCR   R   R  R   R!  R$  R%  R   RM   R/  R=   R1  R2  R3  R:  R@  RC  R?   RP  RX  R`  Rb  Rr  Rs  Rt  R{  R  R	   t   exit(    (    (    s9   lib/python2.7/site-packages/conda_build/os_utils/pyldd.pyt   <module>   sb  @$	
*<						
	I	
?


0}a		 
							5