From owner-freebsd-current@FreeBSD.ORG Fri Jul 4 12:18:25 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3AF90A1B for ; Fri, 4 Jul 2014 12:18:25 +0000 (UTC) Received: from ivan-labs.com (ivan-labs.com [162.243.251.239]) by mx1.freebsd.org (Postfix) with ESMTP id 11A3D2410 for ; Fri, 4 Jul 2014 12:18:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ivan-labs.com (Postfix) with ESMTP id 69B24120E29 for ; Fri, 4 Jul 2014 16:13:02 +0400 (MSK) X-Virus-Scanned: Debian amavisd-new at Received: from ivan-labs.com ([127.0.0.1]) by localhost (ivan-labs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9SuuMTk-cK+y for ; Fri, 4 Jul 2014 16:13:02 +0400 (MSK) Received: from [192.168.43.253] (host-108-157-66-217.spbmts.ru [217.66.157.108]) by ivan-labs.com (Postfix) with ESMTPSA id 15526120A13 for ; Fri, 4 Jul 2014 16:12:59 +0400 (MSK) Message-ID: <53B69A43.3000100@ivan-labs.com> Date: Fri, 04 Jul 2014 16:12:51 +0400 From: "Ivan A. Kosarev" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Intercepting calls in PIC mode Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jul 2014 12:18:25 -0000 Hello, Consider the following: --- #include #include 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, --