]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/ifuncmain6pie.c
Fix bad pointer / leak in regex code
[thirdparty/glibc.git] / elf / ifuncmain6pie.c
CommitLineData
3c30afc8
L
1/* Test STT_GNU_IFUNC symbols in PIE:
2
3 1. Direct function call.
4 2. Function pointer.
5 3. Reference from a shared library.
6 */
7
8#include <stdlib.h>
31c759bf 9#include "ifunc-sel.h"
3c30afc8
L
10
11typedef int (*foo_p) (void);
12extern foo_p foo_ptr;
13
14static int
15one (void)
16{
17 return -30;
18}
19
20void * foo_ifunc (void) __asm__ ("foo");
21__asm__(".type foo, %gnu_indirect_function");
22
9618c7c2 23void *
de659123 24inhibit_stack_protector
3c30afc8
L
25foo_ifunc (void)
26{
31c759bf 27 return ifunc_one (one);
3c30afc8
L
28}
29
30extern int foo (void);
31extern foo_p get_foo (void);
32extern foo_p get_foo_p (void);
33
34foo_p my_foo_ptr = foo;
35
36int
37main (void)
38{
39 foo_p p;
40
41 p = get_foo ();
42 if (p != foo)
43 abort ();
44 if ((*p) () != -30)
45 abort ();
46
47 p = get_foo_p ();
48 if (p != foo)
49 abort ();
50 if ((*p) () != -30)
51 abort ();
52
53 if (foo_ptr != foo)
54 abort ();
55 if (my_foo_ptr != foo)
56 abort ();
57 if ((*foo_ptr) () != -30)
58 abort ();
59 if ((*my_foo_ptr) () != -30)
60 abort ();
61 if (foo () != -30)
62 abort ();
63
64 return 0;
65}