Use '%z' instead of '%Z' on printf functions
[glibc.git] / elf / ifuncmain9.c
blobd59778d6fe44bd1375181954ad7d9c08e6a8acbe
1 /* Test for IFUNC handling with local definitions.
2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* This test is based on gcc.dg/attr-ifunc-4.c. */
21 #include <config.h>
23 # include <stdbool.h>
24 # include <stdio.h>
26 /* Do not use the test framework, so that the process setup is not
27 disturbed. */
29 static volatile int implementation_called;
30 static volatile int resolver_called;
32 /* Just a random constant, to check that we called the right
33 function. */
34 enum { random_constant = 0x3a88d66d };
36 static int
37 implementation (void)
39 ++implementation_called;
40 return random_constant;
43 static __typeof__ (implementation) *
44 inhibit_stack_protector
45 resolver (void)
47 ++resolver_called;
48 return implementation;
51 static int magic (void) __attribute__ ((ifunc ("resolver")));
53 int
54 main (void)
56 bool errors = false;
58 if (implementation_called != 0)
60 printf ("error: initial value of implementation_called is not zero:"
61 " %d\n", implementation_called);
62 errors = true;
65 /* This can be zero if the reference is bound lazily. */
66 printf ("info: initial value of resolver_called: %d\n", resolver_called);
68 int magic_value = magic ();
69 if (magic_value != random_constant)
71 printf ("error: invalid magic value: 0x%x\n", magic_value);
72 errors = true;
75 printf ("info: resolver_called value: %d\n", resolver_called);
76 if (resolver_called == 0)
78 /* In theory, the resolver could be called multiple times if
79 several relocations are needed. */
80 puts ("error: invalid resolver_called value (must not be zero)");
81 errors = true;
84 printf ("info: implementation_called value: %d\n", implementation_called);
85 if (implementation_called != 1)
87 puts ("error: invalid implementation_called value (must be 1)");
88 errors = true;
91 return errors;