aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2010-09-09 14:12:57 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2010-09-09 14:12:57 +0000
commitba885ec559ca39e0dc23641dbbe67cc0072378f3 (patch)
treeda6907a1c5c815841942c5773bfc6c02f7b889e8 /gcc/doc
parente3cdb7cf9a0d934b9cdc24d40d730141e5752f60 (diff)
downloadgcc-ba885ec559ca39e0dc23641dbbe67cc0072378f3.zip
gcc-ba885ec559ca39e0dc23641dbbe67cc0072378f3.tar.gz
gcc-ba885ec559ca39e0dc23641dbbe67cc0072378f3.tar.bz2
configure.ac (gnu_indirect_function): New test.
* configure.ac (gnu_indirect_function): New test. * configure: Rebuilt. * config.in (HAVE_GAS_INDIRECT_FUNCTION): New. * defaults.h (IFUNC_ASM_TYPE): Provide default. * doc/extend.texi (Function Attributes): Document ifunc. * varasm.c (do_assemble_alias): Deal with ifuncs too. c-family/ * c-common.c (handle_alias_ifunc_attribute): New, broken out of ... (handle_alias_attribute): ... here. (handle_ifunc_attribute): New. testsuite/ * lib/target-supports-dg.exp (dg-require-ifunc): New. * lib/target-supports.exp (check_ifunc_available): New. * gcc.dg/attr-ifunc-1.c: New. * gcc.dg/attr-ifunc-2.c: New. * gcc.dg/attr-ifunc-3.c: New. * gcc.dg/attr-ifunc-4.c: New. * gcc.dg/attr-ifunc-5.c: New. * testsuite/g++.dg/ext/attr-ifunc-1.C * testsuite/g++.dg/ext/attr-ifunc-2.C * testsuite/g++.dg/ext/attr-ifunc-3.C * testsuite/g++.dg/ext/attr-ifunc-4.C From-SVN: r164110
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/extend.texi60
1 files changed, 53 insertions, 7 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index de6a30d..4f2cc07 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -1912,6 +1912,7 @@ the enclosing block.
@cindex functions that do not pop the argument stack on the 386
@cindex functions that have different compilation options on the 386
@cindex functions that have different optimization options
+@cindex functions that are dynamically resolved
In GNU C, you declare certain things about functions called in your program
which help the compiler optimize function calls and check your code more
@@ -1927,13 +1928,13 @@ attributes are currently defined for functions on all targets:
@code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg},
@code{no_instrument_function}, @code{section}, @code{constructor},
@code{destructor}, @code{used}, @code{unused}, @code{deprecated},
-@code{weak}, @code{malloc}, @code{alias}, @code{warn_unused_result},
-@code{nonnull}, @code{gnu_inline}, @code{externally_visible},
-@code{hot}, @code{cold}, @code{artificial}, @code{error} and
-@code{warning}. Several other attributes are defined for functions on
-particular target systems. Other attributes, including @code{section}
-are supported for variables declarations (@pxref{Variable Attributes})
-and for types (@pxref{Type Attributes}).
+@code{weak}, @code{malloc}, @code{alias}, @code{ifunc},
+@code{warn_unused_result}, @code{nonnull}, @code{gnu_inline},
+@code{externally_visible}, @code{hot}, @code{cold}, @code{artificial},
+@code{error} and @code{warning}. Several other attributes are defined
+for functions on particular target systems. Other attributes,
+including @code{section} are supported for variables declarations
+(@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}).
GCC plugins may provide their own attributes.
@@ -2585,6 +2586,51 @@ void __attribute__ ((interrupt, use_shadow_register_set,
use_debug_exception_return)) v7 ();
@end smallexample
+@item ifunc ("@var{resolver}")
+@cindex @code{ifunc} attribute
+The @code{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:
+
+@smallexample
+void *my_memcpy (void *dst, const void *src, size_t len)
+@{
+ @dots{}
+@}
+
+static void (*resolve_memcpy (void)) (void)
+@{
+ return my_memcpy; // we'll just always select this routine
+@}
+@end smallexample
+
+The exported header file declaring the function the user calls would
+contain:
+
+@smallexample
+extern void *memcpy (void *, const void *, size_t);
+@end smallexample
+
+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:
+
+@smallexample
+void *memcpy (void *, const void *, size_t)
+ __attribute__ ((ifunc ("resolve_memcpy")));
+@end smallexample
+
+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).
+
@item interrupt_handler
@cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors
Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to