From owner-svn-soc-all@FreeBSD.ORG Wed Jun 4 09:50:43 2014 Return-Path: Delivered-To: svn-soc-all@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 86AF7EDE for ; Wed, 4 Jun 2014 09:50:43 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5963E2C95 for ; Wed, 4 Jun 2014 09:50:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s549ohwN049124 for ; Wed, 4 Jun 2014 09:50:43 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s549og6F049118 for svn-soc-all@FreeBSD.org; Wed, 4 Jun 2014 09:50:42 GMT (envelope-from op@FreeBSD.org) Date: Wed, 4 Jun 2014 09:50:42 GMT Message-Id: <201406040950.s549og6F049118@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r269045 - soc2014/op/tests/ifunc-vs-kpatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jun 2014 09:50:43 -0000 Author: op Date: Wed Jun 4 09:50:42 2014 New Revision: 269045 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269045 Log: added NOTES to ifunc-vs-kpatch Signed-off-by: Oliver Pinter Added: soc2014/op/tests/ifunc-vs-kpatch/NOTES Added: soc2014/op/tests/ifunc-vs-kpatch/NOTES ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tests/ifunc-vs-kpatch/NOTES Wed Jun 4 09:50:42 2014 (r269045) @@ -0,0 +1,29 @@ +https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Function-Attributes.html + -- 8< -- + ifunc ("resolver") + The ifunc attribute is used to mark a function as an indirect function using the STT_GNU_IFUNC symbol type extension to the ELF standard. This allows the resolution of the symbol value to be determined dynamically at load time, and an optimized version of the routine can be selected for the particular processor or other system characteristics determined then. To use this attribute, first define the implementation functions available, and a resolver function that returns a pointer to the selected implementation function. The implementation functions' declarations must match the API of the function being implemented, the resolver's declaration is be a function returning pointer to void function returning void: + + void *my_memcpy (void *dst, const void *src, size_t len) + { + ... + } + + static void (*resolve_memcpy (void)) (void) + { + return my_memcpy; // we'll just always select this routine + } + + + The exported header file declaring the function the user calls would contain: + + extern void *memcpy (void *, const void *, size_t); + + + allowing the user to call this as a regular function, unaware of the implementation. Finally, the indirect function needs to be defined in the same translation unit as the resolver function: + + void *memcpy (void *, const void *, size_t) + __attribute__ ((ifunc ("resolve_memcpy"))); + + + Indirect functions cannot be weak, and require a recent binutils (at least version 2.20.1), and GNU C library (at least version 2.11.1). + -- 8< --