I've looked at the Linker and Libraries Guide and ld and ld.so.1 man pages,
but there are a few things I don't understand. The platform is Solaris 7
and up.
Say I want to link libA.so which depends on libB.so like this (some
flags which are not relevant here omitted):
ld -G -o libA.so *.o -R$ORIGIN -z lazyload -lB -z nolazyload -lc
Both libA and libB are some general-purpose libraries, but applications
use libA as a wrapper and they never use libB directly. libA doesn't
invoke chdir(2). Some applications might do it prior to loading libB.
ld.so.1 man page says:
LD_ORIGIN The immediate processing of $ORIGIN can be triggered by
setting the environment variable LD_ORIGIN to any non-
null value. This may be useful for applications that
invoke chdir(2) prior to locating dependencies that
employ the $ORIGIN string token.
I don't know how exactly is $ORIGIN handled by the run-time linker, but
the paragraph above implies it has to do something with the CWD of
the process in question. Which is kind of strange, since the binary
is usually not in the CWD when it's started, so I don't see why would
CWD be important. Except if it's only important in case when the binary
really is in the CWD (because of auxv handling).
Questions:
1. what does ld.so.1 do when it encounters $ORIGIN?
2. what exactly happens if the application invokes chdir(2) prior to
$ORIGIN processing?
3. Does it affect my libraries and should I use -z origin when linking libA?
4. Are there any performance penalties associated with the use of -zorigin?
5. If the answer to the previous question is no, why is -zorigin an option?
Is there any "creative" use of chdir(2) and $ORIGIN?
--
.-. .-. I don't work for my employer.
(_ \ / _)