Can I add a library refence to existing Shared Object?
Thank you "Employed Russian", you gave me the information needed to search deeper. Solaris already ships with "elfedit", so if others wants to know, these are the instructions
# elfedit libfsimage.so.1.0.0 libfsimage.so.1.0.0-new> dyn:value DT_NEEDED index tag value [0] NEEDED 0x4f81 libpthread.so.1 [1] NEEDED 0x4fac libxml2.so.2 [2] NEEDED 0x4fc2 libgcc_s.so.1> dyn:value -add -s DT_NEEDED libscf.so index tag value [35] NEEDED 0x500d libscf.so> dyn:value DT_NEEDED index tag value [0] NEEDED 0x4f81 libpthread.so.1 [1] NEEDED 0x4fac libxml2.so.2 [2] NEEDED 0x4fc2 libgcc_s.so.1 [35] NEEDED 0x500d libscf.so> :write> :quit# ldd libfsimage.so.1.0.0-new libpthread.so.1 => /lib/libpthread.so.1 libxml2.so.2 => /lib/libxml2.so.2 libgcc_s.so.1 => /usr/sfw/lib/libgcc_s.so.1 libscf.so => /lib/libscf.so libz.so.1 => /lib/libz.so.1 libm.so.2 => /lib/libm.so.2 libsocket.so.1 => /lib/libsocket.so.1 libnsl.so.1 => /lib/libnsl.so.1 libc.so.1 => /lib/libc.so.1 libuutil.so.1 => /lib/libuutil.so.1 libgen.so.1 => /lib/libgen.so.1 libnvpair.so.1 => /lib/libnvpair.so.1 libsmbios.so.1 => /usr/lib/libsmbios.so.1 libmp.so.2 => /lib/libmp.so.2 libmd.so.1 => /lib/libmd.so.1
Not easily.
Most UNIX
systems (AIX
is a notable exception) consider *.so
a "final" link product, and it is not suitable as an input for any further link.
To add a new DT_NEEDED tag to the dynamic section of fsimage.so
, you would need to rewrite its .dynamic
section. Removing an entry from .dynamic
is relatively easy -- you can just "slide" the other entries up, and replace the last entry with DT_NULL
.
On the other hand, adding a new entry requires that you append a whole new .dynamic
section to the file, and then update all pointers (offsets) within fsimage.so
to point to the new section. This requires "deep" understanding of the ELF format.
There are existing tools to do this, e.g. rpath
but I've had mixed success with it.
You can use PatchELF. Release 0.9 is out since 29 Feb 2016 and lets you:
- Change the dynamic loader ("ELF interpreter") of executables
- Change the RPATH of executables and libraries
- Shrink the RPATH of executables and libraries
- Remove declared dependencies on dynamic libraries (DT_NEEDEDentries)
- Add a declared dependency on a dynamic library (DT_NEEDED)
- Replace a declared dependency on a dynamic library with another one (DT_NEEDED)
- Change SONAME of a dynamic library
In your case:
$ patchelf --add-needed /usr/lib/libgen.so /usr/lib/python2.4/vendor-packages/fsimage.so