This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: runtime loader replaces argv[0]


perhaps you might be interested in lddtree:
$ lddtree --copy-to-tree /tmp/foo --bindir=/bin --generate-wrappers /bin/bash

$ tree /tmp/foo/
/tmp/foo/
|-- bin
|   |-- bash
|   `-- bash.elf
`-- lib64
    |-- ld-linux-x86-64.so.2
    |-- libc.so.6
    |-- libhistory.so.6
    |-- libncurses.so.5
    `-- libreadline.so.6

$ cat /tmp/foo/bin/bash
#!/bin/sh
if ! base=$(realpath "$0" 2>/dev/null); then
  case $0 in
  /*) base=$0;;
  *)  base=${PWD:-`pwd`}/$0;;
  esac
fi
basedir=${base%/*}
exec   "${basedir}/../lib64/ld-linux-x86-64.so.2"   --library-path "${basedir}/../lib64"   --inhibit-rpath ''   "${base}.elf"   "$@"

$ /tmp/foo/bin/bash --version
GNU bash, version 4.3.33(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ strace -f -e file /tmp/foo/bin/bash --version
...
execve("/tmp/foo/bin/../lib64/ld-linux-x86-64.so.2", ...
...
open("/tmp/foo/bin/bash.elf", O_RDONLY|O_CLOEXEC) = 3
open("/tmp/foo/bin/../lib64/libreadline.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/tmp/foo/bin/../lib64/libhistory.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/tmp/foo/bin/../lib64/libncurses.so.5", O_RDONLY|O_CLOEXEC) = 3
open("/tmp/foo/bin/../lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
...

it doesn't handle other deps that Carlos alluded to (like data files hardcoded 
in /etc or /usr/share), but does take care of all the libraries ...
-mike

Attachment: signature.asc
Description: Digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]