]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gprofng/testsuite/gprofng.display/synprog/callso.c
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
26 #include "stopwatch.h"
29 #define DYNSOROUTINE "so_cputime"
30 #define DYNSONAME "./so_syn.so"
32 /* callso -- dynamically link a shared object, and call a routine in it */
36 static void *so_object
= NULL
;
37 static void closeso (void);
48 hrtime_t start
= gethrtime ();
49 hrtime_t vstart
= gethrvtime ();
52 wlog ("start of callso", NULL
);
54 /* see if already linked */
55 if (so_object
!= NULL
)
57 fprintf (stderr
, "Execution error -- callso: so_object already linked\n");
61 /* open the dynamic shared object */
63 while (so_object
== NULL
)
65 so_object
= dlopen (DYNSONAME
, RTLD_NOW
);
66 if (so_object
!= NULL
)
72 p
= "dlerror() returns NULL";
78 fprintf (stderr
, "Execution error -- callso: dlopen of %s failed--%s, errno=%d (%s)\n",
79 q
, p
, errnum
, strerror (errnum
));
84 /* look up the routine name in it */
85 int (*so_routine
)() = (int (*)())dlsym (so_object
, DYNSOROUTINE
);
86 if (so_routine
== NULL
)
88 fprintf (stderr
, "Execution error -- callso: dlsym %s not found\n",
93 /* invoke the routine */
100 while (start
+ testtime
* 1e9
> gethrtime ());
103 sprintf (buf
, "end of callso, %s returned %d", DYNSOROUTINE
, i
);
105 fprintf (stderr
, " Performed %lld while-loop iterations\n", count
);
106 whrvlog ((gethrtime () - start
), (gethrvtime () - vstart
), "callso", NULL
);
110 /* closeso -- close a DSO */
115 wlog ("start of closeso", NULL
);
117 /* ensure already linked */
118 if (so_object
== NULL
)
120 fprintf (stderr
, "Execution error -- closeso: so_object not linked\n");
124 /* close the dynamic shared object */
125 int rc
= dlclose (so_object
);
128 fprintf (stderr
, "Execution error -- closeso: dlclose() failed--%s\n",
133 /* clear the pointer */
135 wlog ("end of closeso", NULL
);
139 #else /* NONSHARED */
152 #endif /* NONSHARED */