Search code examples
gnuldelfbinutils

GNU ld: -z origin? -rpath $ORIGIN/../lib?


A legacy makefile that I'm trying to understand has -Wl,-z,origin,-rpath,'$ORIGIN/../lib'

OK, I see -Wl means the following are linker options; the commas will be replaced with spaces.

The manpage for the GNU ld mysteriously only says:

   -z keyword
       The recognized keywords are:
           :
           :
       origin
           Marks the object may contain $ORIGIN.

Likewise the next option -rpath (relative path?) contains this $ORIGIN suggesting it's some kind of key word but $ORIGIN is not otherwise mentioned in the ld man page.


Solution

  • $ORIGIN is mentioned under Substitution Sequences in the ELF specification. DF_ORIGIN is documented as well.

    However, while GNU ld supports setting the DF_ORIGIN flag with the -z origin option, the dynamic loader in glibc always honors $ORIGIN, even if the flag is not set. This means that there is no reason to use the link editor flag when building for GNU/Linux.