indirect function support

H.J. Lu hjl.tools@gmail.com
Wed May 19 01:16:00 GMT 2010


On Tue, May 18, 2010 at 5:53 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Tue, May 18, 2010 at 11:49 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, May 18, 2010 at 3:37 PM, Nathan Sidwell <nathan@codesourcery.com> wrote:
>>> H.J. Lu wrote:
>>>
>>>> Is that a good idea to ask programmers to do name mangling by
>>>> hand?  It can be quite complicated for  complex C++ classes
>>>> and they have to update the alias when member functions are changed.
>>>> We need to make it easy to use.
>>>
>>> The alias attribute already requires this (for non-member functions, for
>>> member functions, alias was simply broken).  While it would be nice to
>>> improve alias, I don't see why that should be a requirement of adding ifunc
>>> support to alias.
>>
>> It is not about adding ifunc support to alias. It is about providing a user
>> friendly ifunc implementation.
>
> I don't think we need something beyond what Nathan implemented.
>
> The easiest way for the user is to forward to C linkage ifuncs from
> templates, members, etc. and this is what we should encourage
> in our documentation.
>
> Any support for mangling should be orthogonal, maybe by a
> C++ extension like __mangle decltype(...) or __mangle decl
> resulting in a string literal.
>

I am enclosing what we have today for ifunc. Glibc has

---
extern double __fma_sse2 (double x, double y, double z) attribute_hidden;

static double
__fma_fma (double x, double y, double z)
{
  asm ("vfmadd213sd %3, %2, %0" : "=x" (x) : "0" (x), "x" (y), "xm" (z));
  return x;
}

libm_ifunc (__fma, HAS_FMA ? __fma_fma : __fma_sse2);
----

But there are no type check and programmers have to know what
the symbol name is at assembly level. This ifunc proposal doesn't help
those areas. I am not sure how much this approach brings to programmers
than what we have now with some macros.


-- 
H.J.
---
static int
one (void)
{
  return 1;
}

static int
minus_one (void)
{
  return -1;
}

static int
zero (void)
{
  return 0;
}

void * foo_ifunc (void) __asm__ ("foo");
__asm__(".type foo, %gnu_indirect_function");

void *
foo_ifunc (void)
{
  return ifunc_sel (one, minus_one, zero);
}



More information about the Gcc-patches mailing list