[cfe-dev] Using IFUNC with template functions

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 18 10:12:58 PST 2020


On 12/11/2020 05:34, Amrita H S via cfe-dev wrote:
> I am interested to know if there any other better way to use ifuncs with 
> template functions. If there is none, is it worth suggesting to the C++ 
> standards?

ifunc is a GNU extension and isn't part of the C++ standard.  I think it 
would be great to be able to specify an ifunc resolver for a template 
function that it, itself, a template function.  I've found ifunc in 
combination with templates to be a very powerful tool, exposing a single 
function that is implemented by one of a small set of instantiations of 
a templated function, depending on the environment.  Generalising this 
to allow ifunc resolvers for template functions would be very interesting.

I'd suggest extending the ifunc attribute parser to accept <> at the end 
of the identifier for the resolver to signify template arguments and 
require that the resolver takes the same template arguments as the 
function itself.  This is a fairly small change in the parser.  Sema 
would then have to instantiate the ifunc resolver function for every 
instantiation of the underlying function and CodeGen would need to mark 
those all as ifunc resolvers.

There are lots of fiddly bits, but none of this sounds particularly hard.

I'd be happy to review clang patches but given that this is a GNU 
extension I'd like to see consensus that GCC will either implement the 
same thing or, at least, not implement something that would cause 
compatibility problems.

David



More information about the cfe-dev mailing list