Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That something is rpath (also known as RUNPATH)

Pretty sure that runpath and rpath are distinct and have slightly distinct behavior. Can't fault you much for making the mistake, though. The two are not given names to be easily distinguished.



RPATH and RUNPATH are indeed different. However, I believe the -rpath flag is used to set either (--enable/disable-new-dtags determines which one is used), so the confusion is understandable.


What is the distinction between them? I always thought they were the same thing.


Depends on your libc.

Search order:

glibc: rpath > LD_LIBRARY_PATH > runpath > ld.so.cache > default paths.

musl: LD_LIBRARY_PATH > rpath=runpath > default paths.

Search path inheritance:

glibc: rpaths are inherited: When exe depends on libx depends on liby, then liby first considers its own rpaths, then libx's rpaths, then exe's rpaths. HOWEVER if liby specifies runpath, it will not consider rpaths from parents.

musl: rpaths and runpaths are the same and always inherited.

I verified the glibc/musl sources when writing https://github.com/haampie/libtree


The difference IIRC is the order they're used by the dynamic loader. One is prior to searching LD_LIBRARY_PATH, the other after.


There's also a difference for transitive dependencies. From the Linux manpage for ld.so, about RUNPATH:

> Such directories are searched only to find those objects required by DT_NEEDED (direct dependencies) entries and do not apply to those objects' children, which must themselves have their own DT_RUNPATH entries. This is unlike DT_RPATH, which is applied to searches for all children in the dependency tree.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: