Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Dynamic linker

by pc88mxer (Vicar)
on Jul 14, 2008 at 14:57 UTC ( [id://697490]=note: print w/replies, xml ) Need Help??


in reply to Dynamic linker

What do you mean by "get/set status"? Do you mean the exit status of a child process? If so, the answer is $?.

As for using LD_PRELOAD, using it works just fine with perl. For instance, see this example. Note, however, that depending on how it was built, perl may use it's own libraries for some things (like I/O) instead of the "standard" ones.

Replies are listed 'Best First'.
Re^2: Dynamic linker
by zamanfou (Initiate) on Jul 14, 2008 at 19:15 UTC
    Yes, this is what I mean :)
    I would like to know how to do this:

    #include <sys/syscall.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <stdio.h>

    pid_t getpid(void)
    {
    printf("Hello, world!\n");
    return syscall(SYS_getpid);
    }

    in Perl.

    -zmf

      It's still not entirely clear to me what you want to achieve.

      In case the idea is to override a Perl builtin (kind of analogously to what you could use LD_PRELOAD for with C libs), you could use CORE::GLOBAL, e.g. like this (I'm using getppid() in the example, as Perl has no builtin named getpid() ):

      #!/usr/bin/perl BEGIN { *CORE::GLOBAL::getppid = sub () { return "Hello world!\n" . CORE::getppid(); } } print getppid();

      (but note that you can only override builtins whose effective prototype can be expressed as a Perl prototype — print() for example cannot be overridden due to its print FH $something, ... syntax (i.e. no comma after FH) )

      When you put the override code into a module (say "mygetppid.pm"):

      *CORE::GLOBAL::getppid = sub () { return "Hello world!\n" . CORE::getppid(); }; 1;

      you could then write

      $ perl -Mmygetppid -e "print getppid()" Hello world! 23726

      where the -Mmygetppid is sematically similar to saying something like LD_PRELOAD=mygetppid.so in order to override some function call made from a given C binary.

      OTOH, if the idea is to use the regular LD_PRELOAD mechanism to override some C library function which is being called under the hood by perl, you can do it just the same way you would if that library function was being called by some other binary. For example, Re: mocking or trapping system calls shows how to override the C lib execvp() call (invoked from perl).

      Are you looking for perldoc -f syscall (or syscall)?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697490]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found