LD_PRELOAD on AIX

aixtesting

Can someone here tell me if there is something similar to LD_PRELOAD on recent versions of AIX? More specifically I need to intercept calls from my binary to time(), returning a constant time, for testing purposes.

Best Solution

AIX 5.3 introduced the LDR_PRELOAD (for 32-bit programs) and LDR_PRELOAD64 (for 64-bit programs) variables. They are analoguous to LD_PRELOAD on Linux. Both are colon-separated lists of libraries, and symbols will be pre-emptively loaded from the listed shared objects before anything else.

For example, if you have a shared object foo.so:

 LDR_PRELOAD=foo.so

If you use archives, use the AIX style to specify the object within the archive:

 LDR_PRELOAD="bar.a(shr.so)"

And separate multiple entries with a colon:

 LDR_PRELOAD="foo.so:bar.a(shr.so)"