home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / opt0.4.lcm / bin / ldd < prev    next >
Encoding:
Text File  |  2004-02-26  |  5.1 KB  |  190 lines

  1. #! /bin/sh
  2. # Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4.  
  5. # The GNU C Library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9.  
  10. # The GNU C Library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. # Lesser General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with the GNU C Library; if not, write to the Free
  17. # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. # 02111-1307 USA.
  19.  
  20.  
  21. # This is the `ldd' command, which lists what shared libraries are
  22. # used by given dynamically-linked executables.  It works by invoking the
  23. # run-time dynamic linker as a command and setting the environment
  24. # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
  25.  
  26. # We should be able to find the translation right at the beginning.
  27. TEXTDOMAIN=libc
  28. TEXTDOMAINDIR=/usr/share/locale
  29.  
  30. RTLDLIST=/lib/ld-linux.so.2
  31. warn=
  32. bind_now=
  33. verbose=
  34. file_magic_regex="ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib)"
  35.  
  36. while test $# -gt 0; do
  37.   case "$1" in
  38.   --vers | --versi | --versio | --version)
  39.     echo 'ldd (GNU libc) 2.3.1'
  40.     echo $"Copyright (C) 2003 Free Software Foundation, Inc.
  41. This is free software; see the source for copying conditions.  There is NO
  42. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  43. Written by Roland McGrath and Ulrich Drepper."
  44.     exit 0
  45.     ;;
  46.   --h | --he | --hel | --help)
  47.     echo $"Usage: ldd [OPTION]... FILE...
  48.       --help              print this help and exit
  49.       --version           print version information and exit
  50.   -d, --data-relocs       process data relocations
  51.   -r, --function-relocs   process data and function relocations
  52.   -v, --verbose           print all information
  53. Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
  54.     exit 0
  55.     ;;
  56.   -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
  57.   --data-rel | --data-relo | --data-reloc | --data-relocs)
  58.     warn=yes
  59.     shift
  60.     ;;
  61.   -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
  62.   --function | --function- | --function-r | --function-re | --function-rel | \
  63.   --function-relo | --function-reloc | --function-relocs)
  64.     warn=yes
  65.     bind_now=yes
  66.     shift
  67.     ;;
  68.   -v | --verb | --verbo | --verbos | --verbose)
  69.     verbose=yes
  70.     shift
  71.     ;;
  72.   --v | --ve | --ver)
  73.     echo >&2 $"ldd: option \`$1' is ambiguous"
  74.     exit 1
  75.     ;;
  76.   --)        # Stop option processing.
  77.     shift; break
  78.     ;;
  79.   -*)
  80.     echo >&2 'ldd:' $"unrecognized option" "\`$1'"
  81.     echo >&2 $"Try \`ldd --help' for more information."
  82.     exit 1
  83.     ;;
  84.   *)
  85.     break
  86.     ;;
  87.   esac
  88. done
  89.  
  90. nonelf ()
  91. {
  92.   # Maybe extra code for non-ELF binaries.
  93.   file=$1
  94.   # Run the ldd stub.
  95.   lddlibc4 "$file"
  96.   # Test the result.
  97.   if test $? -lt 3; then
  98.     return 0;
  99.   fi
  100.   # In case of an error punt.
  101.   return 1;
  102. }
  103.  
  104. add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
  105. add_env="$add_env LD_LIBRARY_VERSION=\$verify_out"
  106. add_env="$add_env LD_VERBOSE=$verbose"
  107. case $# in
  108. 0)
  109.   echo >&2 'ldd:' $"missing file arguments"
  110.   echo >&2 $"Try \`ldd --help' for more information."
  111.   exit 1
  112.   ;;
  113. 1)
  114.   single_file=t
  115.   ;;
  116. *)
  117.   single_file=f
  118.   ;;
  119. esac
  120.  
  121. result=0
  122. for file do
  123.   # We don't list the file name when there is only one.
  124.   test $single_file = t || echo "${file}:"
  125.   case $file in
  126.   */*) :
  127.        ;;
  128.   *) file=./$file
  129.      ;;
  130.   esac
  131.   if test ! -f "$file"; then
  132.     echo "ldd: ${file}:" $"No such file or directory" >&2
  133.     result=1
  134.   elif test -r "$file"; then
  135.     if eval file -L "$file" 2>/dev/null \
  136.     | sed 10q | egrep -v "$file_magic_regex" > /dev/null; then
  137.     test -x "$file" || echo 'ldd:' $"\
  138. warning: you do not have execution permission for" "\`$file'" >&2
  139.     fi
  140.     RTLD=
  141.     for rtld in ${RTLDLIST}; do
  142.       if test -x $rtld; then
  143.     verify_out=`${rtld} --verify "$file"`
  144.         ret=$?
  145.     case $ret in
  146.     [02]) RTLD=${rtld}; break;;
  147.     esac
  148.       fi
  149.     done
  150.     if test -z "${RTLD}"; then
  151.       set ${RTLDLIST}
  152.       RTLD=$1
  153.       verify_out=`${RTLD} --verify "$file"`
  154.       ret=$?
  155.     fi
  156.     case $ret in
  157.     0)
  158.       if [ ! -x "$file" ] && eval file -L "$file" 2>/dev/null \
  159.       | sed 10q | egrep "$file_magic_regex" > /dev/null; then
  160.         eval $add_env ${RTLD} '"$file"' || result=1
  161.       else
  162.         eval $add_env '"$file"' || result=1
  163.       fi
  164.       ;;
  165.     1)
  166.       # This can be a non-ELF binary or no binary at all.
  167.       nonelf "$file" || {
  168.     echo $"    not a dynamic executable"
  169.     result=1
  170.       }
  171.       ;;
  172.     2)
  173.       eval $add_env \${RTLD} '"$file"' || result=1
  174.       ;;
  175.     *)
  176.       echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
  177.       exit 1
  178.       ;;
  179.     esac
  180.   else
  181.     echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
  182.     result=1
  183.   fi
  184. done
  185.  
  186. exit $result
  187. # Local Variables:
  188. #  mode:ksh
  189. # End:
  190.