binutils-gdb/ld/testsuite/ld-ifunc/ifunc-main.c
H.J. Lu 731885c1ad Always load function pointer into a stack variable
This patch makes sure that compiler won't optimize out loading function
into a stack variable.

	* ld-ifunc/ifunc-main.c (get_bar): New function.
	(main): Use it.
2014-11-20 11:29:45 -08:00

39 lines
541 B
C

#include <stdio.h>
extern int foo(void);
extern int bar(void);
typedef int (*func_p) (void);
func_p foo_ptr = foo;
func_p
__attribute__((noinline))
get_bar (void)
{
return bar;
}
int
main (void)
{
func_p bar_ptr = get_bar ();
if (bar_ptr != bar)
__builtin_abort ();
if (bar_ptr() != -1)
__builtin_abort ();
if (bar() != -1)
__builtin_abort ();
if (foo_ptr != foo)
__builtin_abort ();
if (foo_ptr() != 1)
__builtin_abort ();
if (foo() != 1)
__builtin_abort ();
printf ("OK\n");
return 0;
}