diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2025-03-07 06:42:18 +0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2025-03-07 09:15:49 +0800 |
commit | d07a59a5ca830bf74705471f6bea6db1a47da2b5 (patch) | |
tree | ccfcffcec2d2fdc960a696dd496f1a832864b0d7 /gprof/testsuite/tst-gmon.c | |
parent | 1a764289c7ce57552a1bdf48ed92ac89b04caa4e (diff) | |
download | binutils-d07a59a5ca830bf74705471f6bea6db1a47da2b5.zip binutils-d07a59a5ca830bf74705471f6bea6db1a47da2b5.tar.gz binutils-d07a59a5ca830bf74705471f6bea6db1a47da2b5.tar.bz2 |
gprof: Copy a simple test from glibc
Copy a simple gprof test from glibc to test the basic gprof functionality.
1. Tested natively on Linux/x86-64 and Linux/i686.
2. Tested for the x86_64-solaris cross target without cross-compiler.
3. Tested for the aarch64-linux-gnu cross target with cross-compiler.
PR gprof/32764
* Makefile.am (SUBDIRS): Add testsuite
* configure.ac (AC_CONFIG_FILES): Removed.
(AC_OUTPUT): Add Makefile testsuite/Makefile
po/Makefile.in:po/Make-in.
(AM_CONDITIONAL): Add NATIVE.
* Makefile.in: Regenerated.
* configure: Likewise.
* testsuite/Makefile.am: New file.
* testsuite/tst-gmon-gprof.sh: Likewise.
* testsuite/tst-gmon.c: Likewise.
* testsuite/Makefile.in: Generated.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'gprof/testsuite/tst-gmon.c')
-rw-r--r-- | gprof/testsuite/tst-gmon.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gprof/testsuite/tst-gmon.c b/gprof/testsuite/tst-gmon.c new file mode 100644 index 0000000..add2d92 --- /dev/null +++ b/gprof/testsuite/tst-gmon.c @@ -0,0 +1,55 @@ +/* Test program for profiling information collection (_mcount/gprof). + Copyright (C) 2017-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sys/cdefs.h> + +/* This program does not use the test harness because we want tight + control over the call graph. */ + +__attribute__ ((weak)) +void +f1 (void) +{ +} + +__attribute__ ((weak)) +void +f2 (void) +{ + f1 (); + /* Prevent tail call. */ + asm volatile (""); +} + +__attribute__ ((weak)) +void +f3 (int count) +{ + for (int i = 0; i < count; ++i) + { + f1 (); + f2 (); + } +} + +int +main (void) +{ + f3 (1000); + return 0; +} |