I just downloaded a tar file that is supposed to include everything required to run a program that we can call some_binary. I extracted it's contents, and I see the following:
- A binary (let's call it
some_binary) - A
libfolder with various dynamic libraries (.so files) such as/lib/ld-linux-x86-64.so - and a shell script called
some_binary.sh
The script has the following contents:
#!/bin/bash
`dirname "$0"`/lib/ld-linux-x86-64.so.2 `dirname "$0"`/some_binary "$@"
and running it as ./some_binary.sh some arguments seems to run ./some_binary correctly. Oddly enough, running the following script:
#!/bin/bash
LD_LIBRARY_PATH=$CWD/LIB:$LD_LIBRARY_PATH
./some_binary "$@"
as ./my_script.sh some arguments does not work. It results in relocation errors (undefined symbols), presumably from incorrectly loading the libraries under ./lib
Moreover, running the following two statements from the command line results in segmentation fault:
> LD_LIBRARY_PATH=$CWD/LIB:$LD_LIBRARY_PATH
> ./some_binary some arguments
With this, my questions are:
- What does the first script do?
- Why do I get different results across these three attempts? and why can't I just add
$pwd/libtoLD_LIBRARY_PATHand then runsome_binarydirectly?