Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gnu

ld

elf

binutils

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.

like image 582
Swiss Frank Avatar asked Feb 06 '26 20:02

Swiss Frank


1 Answers

$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.

like image 124
Florian Weimer Avatar answered Feb 12 '26 14:02

Florian Weimer