1 | /* Test program to trigger mcount overflow in profiling collection. |
2 | Copyright (C) 2017-2023 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
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. */ |
22 | |
23 | #define PREVENT_TAIL_CALL asm volatile ("") |
24 | |
25 | /* Calls REP(n) macro 16 times, for n=0..15. |
26 | * You need to define REP(n) before using this. |
27 | */ |
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) |
31 | |
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 |
37 | |
38 | /* Calls all 16 leaf functions f1_* in succession */ |
39 | __attribute__ ((noinline, noclone, weak)) void |
40 | f2 (void) |
41 | { |
42 | # define REP(n) f1_##n(); |
43 | REPS |
44 | # undef REP |
45 | PREVENT_TAIL_CALL; |
46 | } |
47 | |
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 |
54 | |
55 | __attribute__ ((noinline, noclone, weak)) void |
56 | f3 (int count) |
57 | { |
58 | for (int i = 0; i < count; ++i) |
59 | { |
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 |
64 | } |
65 | } |
66 | |
67 | int |
68 | main (void) |
69 | { |
70 | f3 (count: 1000); |
71 | return 0; |
72 | } |
73 | |