3

I have to make ELF file to use absolute paths for libraries instead of searching in default paths (RPATH).

This is result from readelf:

readelf -d example

Dynamic section at offset 0xe28 contains 24 entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

But I want to get something like this:

readelf -d example

Dynamic section at offset 0xe28 contains 24 entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [/lib/libc.so.6]

Are there any linker options to achieve this?

BAD_BOT
  • 31
  • 1
  • 3
  • Possible duplicate of [What is the difference between ldd and objdump?](http://stackoverflow.com/questions/11524820/what-is-the-difference-between-ldd-and-objdump) – yugr Feb 21 '17 at 22:18

2 Answers2

0

The tool you want is ldd, because those absolute paths are not part of the ELF file but are decided by the dynamic loader. ldd is a wrapper around environment variables that cause the dynamic loader to output the paths to the libraries that would be (or have been, depending on how you see it) loaded.

Of course, library resolution is a system-specific task and your results may vary across installs even of the same distribution.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15
  • You may want to provide a justification of that? DT_NEEDED is used to provide an indication to the loader of where to find the libraries — clearly by the readelf output above, the file does not have an absolute path, it has literally the string "libc.so.6" — it's the dynamic loader loading it. It's not like I've not written about ELF for 10 years... https://blog.flameeyes.eu/tags/elf/ – Diego Elio Pettenò Feb 23 '17 at 11:55
  • 1
    I think the OP asks if it is possible to actually store an absolute path in `DT_NEEDED`. – Jan Tojnar Jan 30 '18 at 23:02
  • That's not how I'd read the question. Maybe I did misread it. Note that my comment was in reply to someone who telling me off, not sure where that comment went. – Diego Elio Pettenò Feb 01 '18 at 04:01
0

AFAIK specifying the .so file as a normal input, using the absolute path, will result in a binary that also refers to the .so using that same absolute path.

Not sure how that works with default libs like libc, but you could try adding /lib/libc.so.6 as the first linker input.

Paul Groke
  • 6,259
  • 2
  • 31
  • 32