This is the mail archive of the mailing list for the GCC 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 Sat, Jun 13, 2009 at 8:15 AM, Richard
Guenther<> wrote:
> On Sat, Jun 13, 2009 at 3:30 AM, Ian Lance Taylor<> wrote:
>> "H.J. Lu" <> writes:
>>> +@item ifunc ("@var{function}")
>>> +@cindex @code{ifunc} attribute
>>> +The @code{ifunc} attribute only applies to global function definition,
>>> +which causes the definition to be emitted as an indirec function. ?For
>>> +instance,
>>> +
>>> +@smallexample
>>> +void* f_ifunc () __attribute__ ((ifunc ("f")));
>>> +@end smallexample
>>> +
>>> +defines @samp{f_ifunc} to be an indirect function for @samp{f}. This
>>> +attribute is ignored if @samp{f_ifunc} is undefined in the same
>>> +translation unit.
>>> +
>>> +See @code{STT_GNU_IFUNC} specified in @file{ifunc.txt} at
>>> +@uref{}.
>>> +
>>> +Not all target machines support this attribute.
>> This documentation needs to be much better. ?I think most people reading
>> this would not understand the feature. ?I would suggest something more
>> along these lines, but I would like to hear what other people think.
>> I started to write my own version of the documentation, but I realized
>> that I don't even understand this. ?Which function is called by the
>> dynamic linker, "f" or "f_ifunc"? ?Why is the attribute ignored if
>> "f_ifunc" is not defined; shouldn't it be an error? ?I guess that means
>> that "f_ifunc" is called by the dynamic linker; in that case, what
>> happens if "func" is defined?
> Yeah. ?I would have proposed that
> void *foo (void) __attribute__((__ifunc__))
> {
> ?return zero;
> }
> would simply generate foo with indirect function type.
> This of course causes a problem if you have a declaration for
> the real foo available - but then you should better not have that,
> as the compiler will then derive wrong properties for the real foo
> from the ifunc wrapper body.
> That would at least not introduce the confusion with the extra name ...

Here is the updated patch. I extended the ifunc attribute to
static functions and added testcases to show that we need
argument for ifunc attribute:

static foo_p
__attribute__ ((ifunc ("foo")))
foo_ifunc (void)
  return zero;

static int foo (int);

bar (int i)
  return foo (i);

I also updated document to say

`ifunc ("FUNCTION")'
     The `ifunc' attribute only applies to function definition, which
     causes the definition to be emitted as an indirec function.  For

          void* f_ifunc () __attribute__ ((ifunc ("f")));

     defines `f_ifunc' to be an indirect function for `f'.  The
     indirect function `f_ifunc' is called by dynamic linker, and
     returns a pointer to the actual function that should be executed as
     `f'.  This attribute is ignored if `f_ifunc' is undefined in the
     same translation unit unless the symbol type is generated for
     undefined symbol.

This patch also addressed the IFUNC symbol binding, which should
always be global since it needs to go through PLT.  I reused one bit
in base for TREE_IFUNC_NAME. Any comments?



2009-06-19  H.J. Lu  <>

	* c-common.c (handle_ifunc_attribute): New.
	(c_common_attribute_table): Add "ifunc".

	* c-decl.c (c_write_global_declarations_1): Don't warn undefined
	IFUNC symbol.

	* cgraphunit.c (process_function_and_variable_attributes): Check
	* ipa-pure-const.c (check_decl): Likewise.
	* ipa-reference.c (has_proper_scope_for_analysis): Likewise.
	* ipa-type-escape.c (has_proper_scope_for_analysis): Likewise.

	* tree.c (decl_assembler_name): Handle ifunc attribute.

	* tree.h (TREE_IFUNC_NAME): New.

	* varasm.c (default_binds_local_p_1): Return false for

	* config/elfos.h (ASM_DECLARE_FUNCTION_NAME): Output
	"gnu_indirect_function" instead of "function" for ifunc

	* doc/extend.texi: Document ifunc attribute.


2009-06-19  H.J. Lu  <>

	* gcc.dg/torture/ifunc-1.c: New.
	* gcc.dg/torture/ifunc-2.c: Likewise.
	* gcc.dg/torture/ifunc-3.c: Likewise.
	* gcc.dg/torture/ifunc-4.c: Likewise.

Attachment: gcc-ifunc-3.patch
Description: Text document

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