delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/04/21/16:53:29

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <371E3B5E.E91FB48C@bgs.com>
Date: Wed, 21 Apr 1999 16:55:58 -0400
From: Eugene Kanter <eugene AT bgs DOT com>
X-Mailer: Mozilla 4.51 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
To: cygwin AT sourceware DOT cygnus DOT com
Subject: Re: ANNOUNCE: cygwin `ldd' script
References: <Pine DOT SUN DOT 3 DOT 93 DOT 981209163956 DOT 6180E-100000 AT modi DOT xraylith DOT wisc DOT edu> <366FF20A DOT 65BB0922 AT oranda DOT demon DOT co DOT uk>

--------------A3E4D4AB5A8337B15124C71E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I found a bug (duplicate names have been printed) in the script and
fixed it. See attached. Anyone care to optimize "for" loops or to write
a C program? Script is painfully slow, however does the job surprisingly
well. Good work, Gary!

Eugene.

"Gary V. Vaughan" wrote:
> 
> Attached is an all singing, all dancing ldd-a-like for cygwin.  Do with
> it what you will, perhaps add it to the ftp.franken.de repository?
> 
> I might convert some more of the functionality from cygcheck in a few
> weeks, once I have libtool fixed to build dlls.
> 
> Thanks again Mumit for the response:
> 
> Mumit Khan wrote:
> >
> > On Wed, 9 Dec 1998, Gary V. Vaughan wrote:
> >
> > > Ahh.. I didn't know dll's could depend on one another.  Are these
> > > dependencies encoded into the dependee by cygwin's ld at linktime?
> >
> > It's the same as on other Unix systems, where shared libraries can
> > have dependencies as well (the win32 dll architecture is of various
> > quite different from the various flavors of Unix shlibs, but it's the
> > same basic idea).
> 
> I see.  It appears (by experiment!) that the final link of win32 dll
> does indeed list the other link-time dlls in the .idata section of the
> resulting library.  Dll's are less brain-damaged than I had thought
> after all =)O|
> 
> > Few comments
> >
> > - absolute pathname may not work as is (eg., ``ldd /bin/sh.exe'')
> 
> You're right.  Fixed in the attached version.
> 
> > - You do need to sort out duplicates
> 
> Right again.  I fixed this too.
> 
> > - the path search is confusing. for example, let's say I have a file
> >   called foo.exe in my current working directory (which is not in my
> >   path), and a file called foo.exe in my PATH. Now if I do:
> >
> >     $ ldd foo.exe
> >
> >   it picks up the one in the PATH instead of the one in the current
> >   directory!
> 
> I think this is how it should work.  In the circumstance you describe
> above, if I typed `foo.exe' to my bash prompt, I would expect the
> foo.exe found in my $PATH to run.
> 
> I have changed the dll lookup (after an exe is found) to look in the
> executables directory, the current working directory and then to search
> the PATH.  Despite what I said about choosing an executable file to
> run,  I assume the win32 runtime loader will search for dlls as you
> describe, regardless of the shell being used.
> 
> > Hope I read the algorithm correctly -- don't have a windows
> > machine to test it out.
> 
> Yup, fine.  It is a little clearer in the new version I hope =)O|
> 
> >   You *may* need to extend the search path to include the default
> >   search path for win32 DLLs (different for win9x and NT), including
> >   the directory containing executable as well as the current working
> >   directory.
> 
> How do I find what these are?  I have /WINNT/System32 and /WINNT put in
> my path by either bash or the NT kernel... are these the directories you
> mean?
> 
> > Regards,
> > Mumit
> 
> Many thanks for taking the time to look at this.  I hope to roll this
> (and the rest of the required bits) into CVS libtool in the next week or
> two -- with luck libtool-1.3 should be able to build dll's when it is
> released [RSN =)O|]
> 
> Cheers,
>         Gary.
>
--------------A3E4D4AB5A8337B15124C71E
Content-Type: application/x-sh;
 name="ldd.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ldd.sh"

#! /bin/bash
#  -*- Mode: Sh -*- 
# ----------------------------------------------------------------------
# ldd --- an unix ldd(1) work-alike for cygwin
#
# Author:	      Gary V. Vaughan <garyv AT oranda DOT demon DOT co DOT uk>
# Maintainer:	      Gary V. Vaughan <garyv AT oranda DOT demon DOT co DOT uk>
# Created:	      Tue Dec  8 08:43:00 1998
# Last Modified:      Wed Apr 21 16:46:00 1999				      
#            by:      Eugene Kanter <eugene AT ultra DOT net>
#
# ----------------------------------------------------------------------
# @(#) $Id: ldd.sh,v 1.2 1999/04/21 20:48:10 eugene Exp $
# ----------------------------------------------------------------------
# Copyright (C) 1998 Gary V. Vaughan

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# Code:

while test $# -gt 0; do
  case "$1" in
  --v | --ve | --ver | --vers | --versi | --versio | --version)
    echo 'ldd (libtool) 0.9'
    echo "Copyright (C) 1998 Gary V. Vaughan
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
    exit 0
    ;;
  --h | --he | --hel | --help)
    echo "ldd [OPTION]... FILE
      --help              print this help and exit
      --version           print version information and exit
Report bugs to <gvaughan AT oranda DOT demon DOT co DOT uk>."
    exit 0
    ;;
  --)           # Stop option processing.
    shift; break
    ;;
  -*)
    echo >&2 'ldd:' "unrecognized option" "\`$1'"
    echo 
    exit 1
    ;;
  *)
    break
    ;;
  esac
done

if test $# != 1; then
  echo >&2 'ldd:' "missing file arguments"
  echo >&2 "Try \`ldd --help' for more information."
  exit 1
fi

LDDPATH=${LDDPATH=$PATH}

OBJDUMP=${OBJDUMP=objdump}
OBJDUMP_FLAGS=${OBJDUMP_FLAGS='-p -j idata'}

to_lower="tr 'A-Z' 'a-z'"		# convert to lower case
basename="sed s,^.*[/\\\\],,g"		# extract the basename from a path
dirname="sed s,[/\\\\][^/\\\\]*\$,,"	# extract the dirname from a path

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
sed_quote_subst='s,\([\\"\\`$\\\\]\),\\\1,g'

RE_dll='^	DLL Name: '

exts="exe dll"			# valid extensions
seen=""				# list of objects examined already
object=$1			# the object from the command line

case "$object" in
  /* | [A-Z]:* ) path=$object ;;
  */* | *\\* )   dir=`echo "$object"|$dirname`
                 path=`cd $dir && pwd``echo "$object"|$basename` ;;
  * )            path="" ;;
esac
objects=`echo "$object"|$basename|$to_lower`

# In a vain attempt to squeeze a bit of speed out of the main loop
# we try to remove any invalid directories or duplicates from the path...
#LDDPATH=`echo "$LDDPATH"| $to_lower`
lddpath=""
IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=':'
for dir in $LDDPATH; do
  IFS="$save_ifs"
  lower_dir=`echo "$dir"|$to_lower`
  if test -z "`echo ":$lddpath:" | $to_lower | grep ":$lower_dir:"`"; then
     test -d "$dir" && lddpath="$lddpath:$dir"
  fi
done
LDDPATH=`echo "$lddpath"|sed 's,^:,,'`


# MAIN LOOP:
############
while test -n "$objects"
do
  newobjects=""
  for object in $objects; do
    # if we have no dir for object, search the LDDPATH for it
    if test -z "$path"; then
      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=':'
      for dir in $LDDPATH; do
        IFS="$save_ifs"
        for ext in $exts; do
          if test -f "$dir/$object.$ext"; then
	    object="$object.$ext"
            path="$dir/$object"
  	    break
          fi
        done
        if test -z "$path" && test -f "$dir/$object"; then
          path="$dir/$object"
        fi
	# stop searching if we have a match
        test -z "$path" || break
      done
    else
      # we have a path, so just check for extensions
      dir=`echo "$path"|$dirname`
      for ext in $exts; do
        if test -f "$dir/$object.$ext"; then
	  object="$object.$ext"
          path="$dir/$object"
  	  break
        fi
      done
    fi
    test -n "$path" || path="not found"

    # show what we have so far
    echo "$object	-> $path"

    # start the next search if OBJECT was not found
    test -f "$path" || continue

    case $object in
      *.exe|*.dll)
        # ...being (a bit) careful not to introduce duplicates
        LDDPATH="$dir:.:"`echo :${LDDPATH}:|sed -e "s,:$dir:,:,;s,:\.:,,"`
	LDDPATH=`echo "$LDDPATH"|sed 's,^:,,;s,:$,,'`
	;;
    esac

    # escape any shell meta characters for the eval below
    path=`echo $path|sed -e "$sed_quote_subst"`
    
    #extract dependencies from current object
    new=`eval ${OBJDUMP} ${OBJDUMP_FLAGS} \""$path"\" \
	 | grep "$RE_dll"  | sed "s,$RE_dll,," | $to_lower`
    #add new to newobjects making sure we remove duplicates!
    for pending in $new;do
       test -z "`echo \" $newobjects \" | grep "\ $pending \"`" && newobjects="$newobjects $pending"
    done
    seen="$seen $object"
    path=""

    # only add NEWOBJECTS that we have not seen yet
    new=""
    for pending in $newobjects; do
      test -z "`echo \" $seen \" | grep \" $pending \"`" && new="$new $pending"
    done
    newobjects=$new
  done
  
  # maintain the loop invariants
  objects="$newobjects"
done

exit 0

# ldd ends here

--------------A3E4D4AB5A8337B15124C71E
Content-Type: text/plain; charset=us-ascii

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
--------------A3E4D4AB5A8337B15124C71E--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019