x86: In ld.so, diagnose missing APX support in APX-only builds
[glibc.git] / gmon / tst-mcount-overflow.c
blob0e60f7e2e665cb03266fdd2caf986f577ccd4d2e
1 /* Test program to trigger mcount overflow in profiling collection.
2 Copyright (C) 2017-2024 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 /* Program with sufficiently complex, yet pointless, call graph
20 that it will trigger an mcount overflow, when you set the
21 minarcs/maxarcs tunables to very low values. */
23 #define PREVENT_TAIL_CALL asm volatile ("")
25 /* Calls REP(n) macro 16 times, for n=0..15.
26 * You need to define REP(n) before using this.
28 #define REPS \
29 REP(0) REP(1) REP(2) REP(3) REP(4) REP(5) REP(6) REP(7) \
30 REP(8) REP(9) REP(10) REP(11) REP(12) REP(13) REP(14) REP(15)
32 /* Defines 16 leaf functions named f1_0 to f1_15 */
33 #define REP(n) \
34 __attribute__ ((noinline, noclone, weak)) void f1_##n (void) {};
35 REPS
36 #undef REP
38 /* Calls all 16 leaf functions f1_* in succession */
39 __attribute__ ((noinline, noclone, weak)) void
40 f2 (void)
42 # define REP(n) f1_##n();
43 REPS
44 # undef REP
45 PREVENT_TAIL_CALL;
48 /* Defines 16 functions named f2_0 to f2_15, which all just call f2 */
49 #define REP(n) \
50 __attribute__ ((noinline, noclone, weak)) void \
51 f2_##n (void) { f2(); PREVENT_TAIL_CALL; };
52 REPS
53 #undef REP
55 __attribute__ ((noinline, noclone, weak)) void
56 f3 (int count)
58 for (int i = 0; i < count; ++i)
60 /* Calls f1_0(), f2_0(), f1_1(), f2_1(), f3_0(), etc */
61 # define REP(n) f1_##n(); f2_##n();
62 REPS
63 # undef REP
67 int
68 main (void)
70 f3 (1000);
71 return 0;