Intercepting calls in PIC mode
Shawn Webb
lattera at gmail.com
Fri Jul 4 14:43:24 UTC 2014
You could hijack the GOT entry, but that assumes the symbol has been
resolved first (either LD_BIND_NOW or the function has been called at
least once). You could also use LD_PRELOAD.
On Jul 04, 2014 04:12 PM +0400, Ivan A. Kosarev wrote:
> Hello,
>
> Consider the following:
>
> ---
> #include <stdio.h>
> #include <string.h>
>
> extern "C" void* memset(void *block, int c, size_t size)
> __attribute__((weak, alias("__int_memset"), visibility("default")));
>
> extern "C" __attribute__((visibility("default")))
> void* __int_memset(void *block, int c, size_t size) {
> puts("Hello");
> return NULL;
> }
>
> int main()
> {
> void *(*F)(void *b, int c, size_t len) = memset;
> char a[5];
> memset(a, 0, sizeof(a));
> F(a, 0, sizeof(a));
> return 0;
> }
> ---
>
> It intercepts the memset() calls without issue on both x86-64 FreeBSD
> 9.2 and Linux. However, with the -fPIC option specified in the cc's
> command line, only the first (direct) call work on FreeBSD, but not the
> second (indirect) one. Note is that on Linux both the calls are
> intercepted--no matter whether the -fPIC option is specified or not.
>
> The question is: is there a way to intercept indirect calls on FreeBSD?
>
> Thanks,
>
> --
>
> _______________________________________________
> freebsd-current at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-current/attachments/20140704/7772a7ce/attachment.sig>
More information about the freebsd-current
mailing list