Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* Library Interposition on Tru64?
@ 2001-08-15  8:29 Kerry Kopp
  2001-08-15 17:08 ` Dan Riley
  0 siblings, 1 reply; 4+ messages in thread
From: Kerry Kopp @ 2001-08-15  8:29 UTC (permalink / raw)


Hey there, I'm a newbie when it comes to Dec/OSF, and I was looking
for
a little guidance. :)

I'm hoping to create a library interposer to debug a machine in the
field that is having problems, but I can't seem to locate any
documentation on whether this is possible on Dec/OSF/Tru64/whatever
it's called. (Rev 4.0F, build 1229).

Does anyone have any good hints or pointers to documentation? All I
can find is the standard Solaris & Linux info...

Thanks much!
Kerry Kopp


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Library Interposition on Tru64?
  2001-08-15  8:29 Library Interposition on Tru64? Kerry Kopp
@ 2001-08-15 17:08 ` Dan Riley
  2001-08-16  2:42   ` Kerry Kopp
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Riley @ 2001-08-15 17:08 UTC (permalink / raw)


kerry@yahoo.com (Kerry Kopp) writes:
> I'm hoping to create a library interposer to debug a machine in the
> field that is having problems, but I can't seem to locate any
> documentation on whether this is possible on Dec/OSF/Tru64/whatever
> it's called. (Rev 4.0F, build 1229).

See the loader(5) man page.  The Tru64 equivalent of

LD_PRELOAD=/here/there/mylib.so

is

_RLD_LIST=/here/there/mylib.so:DEFAULT

However, I don't see an obvious equivalent to RTLD_NEXT.
-- 
Dan Riley                                         dsr@mail.lns.cornell.edu
Wilson Lab, Cornell University      <URL:http://www.lns.cornell.edu/~dsr/>
	  "A new life awaits you in the off-world colonies"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Library Interposition on Tru64?
  2001-08-15 17:08 ` Dan Riley
@ 2001-08-16  2:42   ` Kerry Kopp
  2001-08-20 19:17     ` Kerry Kopp
  0 siblings, 1 reply; 4+ messages in thread
From: Kerry Kopp @ 2001-08-16  2:42 UTC (permalink / raw)


Dan Riley <dsr@mail.lns.cornell.edu> wrote in message news:<shd75xw8rh.fsf@lnxcu9.lns.cornell.edu>...

> See the loader(5) man page.  The Tru64 equivalent of
> 
> LD_PRELOAD=/here/there/mylib.so
> 
> is
> 
> _RLD_LIST=/here/there/mylib.so:DEFAULT
> 
Ahh, cool. I did actually find _RLD_LIST, but must have missed the
DEFAULT part, so things weren't working quite right.

> However, I don't see an obvious equivalent to RTLD_NEXT.

Hmmmm, crud. I've seen some docs about iterating over the various
symbols (on Solaris, of course), so I'll try and figure out if that's
possible. (Although I'm hoping that someone out there knows how to do
it... :) )

Thanks, Dan!
Kerry


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Library Interposition on Tru64?
  2001-08-16  2:42   ` Kerry Kopp
@ 2001-08-20 19:17     ` Kerry Kopp
  0 siblings, 0 replies; 4+ messages in thread
From: Kerry Kopp @ 2001-08-20 19:17 UTC (permalink / raw)


kerry@yahoo.com (Kerry Kopp) wrote in message news:<72ee5672.0108151842.5cdac734@posting.google.com>...
> Dan Riley <dsr@mail.lns.cornell.edu> wrote in message news:<shd75xw8rh.fsf@lnxcu9.lns.cornell.edu>...
> 

> 
> > However, I don't see an obvious equivalent to RTLD_NEXT.
> 
> Hmmmm, crud. I've seen some docs about iterating over the various
> symbols (on Solaris, of course), so I'll try and figure out if that's
> possible. (Although I'm hoping that someone out there knows how to do
> it... :) )

Allllrighty, I figured it out, sort of. It's not as auto-magic as
RTLD_NEXT, but hey, it works. :)

/*
 * Example of a library interposer on DEC/Tru64: interpose on
malloc().
 * (Tested on 4.0F, Rev 1229)
 * Build and use this interposer as following:
 * 1) compile the shared lib
 *    % cc -o malloc_interposer.so -shared malloc_interposer.c
 * 2) tell the interposer the nameof the real library that has the
function
 *    that we are interposing. For malloc(), this is libc.so. (This is
done
 *    as an environment variable so that it can be changed at runtime)
 *    Note: you don't need a full path, as the loader will resolve it
for you.
 *    % setenv INTERPOSE_TARGET_LIB libc.so
 * 3) Tell the loader to look in our library first, then the default
libs.
 *    (This is the equivalent to LD_PRELOAD on Solaris)
 *    % setenv _RLD_LIST $cwd/malloc_interposer.so:DEFAULT
 * 4) Run the app as normal. See the pretty printouts.
 * 5) Turn off the interposition if needed
 *    % unsetenv _RLD_LIST
 *
 * In theory, maybe we should dlclose the shared lib that we are
opening, but,
 * well, this is an example, right? :)


 * Created from Solaris interposition examples, some research, and a
little help
 * from Dan Riley on Usenet, 8/16/2001, Kerry Kopp kerry@yahoo.com
 */


#include <stdio.h> /* For printf() */
#include <dlfcn.h> /* For dlopen(), dlsym() */
#include <stdlib.h> /* For getenv() */


/* The environment var that has the real library we want */
#define LIB_PATH_ENV_VAR "INTERPOSE_TARGET_LIB"


void *malloc(size_t size)
{
  static void * (*func)();
  char * libPath = NULL;
  void * handle = NULL;


  libPath = getenv(LIB_PATH_ENV_VAR);
  if ( !libPath ) {
    printf("LibPath is null, bailing\n");
    return NULL;
  }
  handle = dlopen(libPath, RTLD_NOW);
  if ( !handle ) {
    printf("Handle is null, bailing.\n");
    return NULL;
  }
  if(!func) {
    func = (void *(*)()) dlsym(handle, "malloc");
  }
  printf("malloc(%d) was called\n", size);


  return(func(size));
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-08-20 19:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-15  8:29 Library Interposition on Tru64? Kerry Kopp
2001-08-15 17:08 ` Dan Riley
2001-08-16  2:42   ` Kerry Kopp
2001-08-20 19:17     ` Kerry Kopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox