This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/40528] Add a new ifunc attribute
- From: "agner at agner dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 8 Jul 2011 08:53:03 +0000
- Subject: [Bug c/40528] Add a new ifunc attribute
- Auto-submitted: auto-generated
- References: <bug-40528-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40528
--- Comment #16 from Agner Fog <agner at agner dot org> 2011-07-08 08:52:32 UTC ---
(In reply to comment #15)
> (In reply to comment #14)
> > (In reply to comment #13)
> > > What is the status of this issue?
> >
> > It is implemented on ifunc branch.
> >
> > > Is option 3 implemented?
> >
> > Yes, on ifunc branch.
> >
> > > Which versions of Linux and binutils support IFUNC?
> Still doesn't work.
> "warning: âifuncâ attribute directive ignored"
> GNU Binutils for Ubuntu 2.21.0.20110327
The ifunc attribute is described in
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html but it doesn't work
(see my previous comment). After some experimentation I found that the method
described below works. Either the compiler should be fixed or the onlinedocs
should be changed.
// Example of gnu indirect function
#include <stdio.h>
#include <time.h>
// Define different versions of my function
int myfunc1() {
return 1;
}
int myfunc2() {
return 2;
}
// Type definition for pointer to my function
typedef int (*MyFunctionPointer)(void);
// Prototype for the common entry point
extern "C" // remove this line if not C++
int myfunc();
__asm__ (".type myfunc, @gnu_indirect_function");
// Make the dispatcher function
MyFunctionPointer myfunc_dispatch (void) __asm__ ("myfunc");
MyFunctionPointer myfunc_dispatch (void) {
if (time(0) & 1) {
// If time is odd at first call, use version 1
return myfunc1;
}
else {
// else use version 2
return myfunc2;
}
}
int main() {
// Test the call to myfunc
printf("\nCalled function number %i\n", myfunc());
return 0;
}