gcc-patches@gcc.gnu.org
[Top] [All Lists]

Re: [IFUNC] PATCH: Add an ifunc attribute

Subject: Re: [IFUNC] PATCH: Add an ifunc attribute
From: Jakub Jelinek
Date: Thu, 2 Jul 2009 09:20:20 +0200
On Wed, Jul 01, 2009 at 11:07:16PM -0700, Mark Mitchell wrote:
> Richard Guenther wrote:
> 
> >> When using asm to change C++ symbol name, you have to mangle it
> >> by hand. When you change the prototype of the ifunc function,
> >> you have to mangle the symbol name again.  Should we ask gcc
> >> users which approach is better?
> > 
> > No.
> 
> Richard, I disagree with your position in this thread.  In particular, I
> do think that we should try to make this attribute work for C++ without
> users having to do by-hand mangling of names.  That's clearly the right
> user interface; C++ programmers should never have to know about mangling.

If mangling is the issue, then just allow asm and alias attribute to specify
decl for mangling, as alternative to the current string.  That would help
not only using asm with ifunc attribute, but also other asms used for symbol
redirection and the alias attribute.  Currently in C++, if you want to have
both foo and bar implemented by the same routine, you need to write:

void
foo (int)
{
}

__typeof (foo) bar __attribute__((alias ("_Z3fooi")));
__typeof (foo) baz __attribute__((alias ("_Z3fooi")));

If we had:
void
foo (int)
{
}

__typeof (foo) bar __attribute__((alias (mangle (foo))));
__typeof (::foo) baz __attribute__((alias (mangle (::foo))));

Or

int foo (int, long);
static int foo1 (int x, long y) { return x + y; }
static int foo2 (int x, long y) { return x - y; }
__typeof (foo) *foo_ifunc (void) __asm (mangle (foo))
{
  if (cpuid & have_ADD)
    return foo1;
  return foo2;
}

I'd say keep the extensions simple, well defined, and let the users stack
them if they need it the way they want.  Changing the return type and
arguments from prototype looks like very non-obvious extension and one that
will cause a can of worms in GCC for years.

        Jakub

<Prev in Thread] Current Thread [Next in Thread>