Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 04 Jul 2014 16:12:51 +0400
From:      "Ivan A. Kosarev" <ivan@ivan-labs.com>
To:        freebsd-current@freebsd.org
Subject:   Intercepting calls in PIC mode
Message-ID:  <53B69A43.3000100@ivan-labs.com>

next in thread | raw e-mail | index | archive | help
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,

-- 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53B69A43.3000100>