11

The rpath of an executable specifies one or more directories wherein to look for shared objects at runtime.

My question is - do shared object files themselves also have statically-compiled rpaths?

I recently received a runtime error when linking with a shared object:

./example: /opt/swt/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./mylib.so)

This error indicates to me that the actually library itself - mylib.so, has an statically compiled rpath.

My understanding was that rpath only applied to executables, not shared objects. So does rpath also apply to shared objects?

Siler
  • 8,976
  • 11
  • 64
  • 124

1 Answers1

10

do shared object files themselves also have statically-compiled rpaths

They may (or may not) depending on whether they were linked with -Wl,-rpath=... option.

This error indicates to me that the actually library itself - mylib.so, has an statically compiled rpath.

The error message does not say that at all. Where did you get that idea?

If you want to know whether mylib.so has DT_RPATH or not, do this:

readelf -d mylib.so | grep 'R.*PATH'  # could also have RUNPATH

My understanding was that rpath only applied to executables, not shared objects. So does rpath also apply to shared objects?

Your understanding is incorrect, and RPATH (and RUNPATH) works for shared objects just as well.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Suppose the program `node` has its own `DT_RUNPATH`, then when it uses `dlopen` to open a shared object which has its own `DT_RUNPATH`, does the dynamic loader search both `DT_RUNPATH`? Or does it only consider the `DT_RUNPATH` inside the shared object? What happens if the shared object itself doesn't have a `DT_RUNPATH`? – CMCDragonkai May 14 '22 at 07:34
  • @CMCDragonkai Please don't ask additional extended questions in a comment -- just ask a new question. It's free. – Employed Russian May 14 '22 at 15:44