This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add ifunc attribute


On Sun, Jun 28, 2009 at 10:59 PM, Roland McGrath<roland@redhat.com> wrote:
>> > Note that foo_finder is static, so "foo_finder" would be a local symbol (or
>> > could in theory be renamed arbitrarily by the compiler, etc.), but this has
>>
>> Static member function in C++ has global binding.
>
> That was exactly my point about the difference in the second example. ?The
> first example uses a plain static function for "foo_finder", not any kind
> of member function.
>
>> What symbol name should compiler generate for "foo_finder"?
>
> It's irrelevant here. ?It can generate whatever symbol name it normally
> would as defined without the __attribute__ ((ifunc ("foo"))).
>
>> You may have many member functions named "foo" with different prototypes.
>
> Sure. ?So? ?Each __attribute__ ((ifunc ("foo"))) definition is separate and
> applies to the appropriate mangling of "foo" for the type affected by that
> individual definition. ?It is immaterial what you might choose to call the
> "finder" functions. ?I think C++ won't allow you to call several of them
> "foo_finder" and rely on overloading, because they'd differ only in return
> type.
>
>> How do you handle
>>
>> class ifunc
>> {
>> private:
>> ? int foo1 (int);
>> ? int foo2 (float);
>>
>> public:
>> ? int foo (int);
>> ? int foo (float);
>> ? int bar (int);
>> ? int bar (float);
>> };
>>
>> int
>> __attribute__ ((ifunc))
>> ifunc::foo (int)
>> {
>> ? return &ifunc::foo1;
>> }
>>
>> int
>> __attribute__ ((ifunc))
>> ifunc::foo (float)
>> {
>> ? return &ifunc::foo2;
>> }
>>
>> int
>> ifunc::bar (int x)
>> {
>> ? return foo (x);
>> }
>>
>> int
>> ifunc::bar (float x)
>> {
>> ? return foo (x);
>> }
>
> Nothing new here.
>
> ? ?static int (ifunc::*foo1_finder ()) (int) __attribute__ ((ifunc ("foo")))
> ? ?{
> ? ? ?return &ifunc::foo1;
> ? ?}
> ? ?static int (Foo::*foo2_finder ()) (float) __attribute__ ((ifunc ("foo")))
> ? ?{
> ? ? ?return &ifunc::foo2;
> ? ?}
>
> if inside the class (corresponds to my second example). ?Or, corresponding
> to my first example, the same outside the class but s/"foo"/"ifunc::foo"/
> and then you'd have to address the privateness of foo[12] with a friend
> function decl or something (but that is just a normal wrinkle of defining
> any normal function could return that pointer). ?Simply put, the only
> departure from just defining some function you could otherwise define that
> returns such pointers, is adding __attribute__ ((ifunc ("foo"))).

Your proposal requires determining the mangling from the return type
and the ifunc attribute argument.  That's even more weird than HJs
proposal.

If you go down that far, why not do a proper C++ extension like

__ifunc ifunc::foo (int)
{
  return &ifunc::foo1;
}

__ifunc ifunc::foo (float)
{
  return &ifunc::foo2;
}

?

No, I'm not serious.  Keep it simple please, build on existing features.

Thanks,
Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]