Skip to content

Commit cfaac2a

Browse files
committed
Add build support for 'gprof' profiling.
1 parent d32528e commit cfaac2a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

configure.ac

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ AC_ARG_WITH([qrencode],
143143

144144
AC_ARG_ENABLE([hardening],
145145
[AS_HELP_STRING([--disable-hardening],
146-
[do not attempt to harden the resulting executables (default is to harden)])],
146+
[do not attempt to harden the resulting executables (default is to harden when possible)])],
147147
[use_hardening=$enableval],
148-
[use_hardening=yes])
148+
[use_hardening=auto])
149149

150150
AC_ARG_ENABLE([reduce-exports],
151151
[AS_HELP_STRING([--enable-reduce-exports],
@@ -214,6 +214,13 @@ AC_ARG_ENABLE([debug],
214214
[enable_debug=$enableval],
215215
[enable_debug=no])
216216

217+
# Enable gprof profiling
218+
AC_ARG_ENABLE([gprof],
219+
[AS_HELP_STRING([--enable-gprof],
220+
[use gprof profiling compiler flags (default is no)])],
221+
[enable_gprof=$enableval],
222+
[enable_gprof=no])
223+
217224
# Turn warnings into errors
218225
AC_ARG_ENABLE([werror],
219226
[AS_HELP_STRING([--enable-werror],
@@ -553,12 +560,30 @@ else
553560
AC_SEARCH_LIBS([clock_gettime],[rt])
554561
fi
555562

563+
if test "x$enable_gprof" = xyes; then
564+
dnl -pg is incompatible with -pie. Since hardening and profiling together doesn't make sense,
565+
dnl we simply make them mutually exclusive here. Additionally, hardened toolchains may force
566+
dnl -pie by default, in which case it needs to be turned off with -no-pie.
567+
568+
if test x$use_hardening = xyes; then
569+
AC_MSG_ERROR(gprof profiling is not compatible with hardening. Reconfigure with --disable-hardening or --disable-gprof)
570+
fi
571+
use_hardening=no
572+
AX_CHECK_COMPILE_FLAG([-pg],[GPROF_CXXFLAGS="-pg"],
573+
[AC_MSG_ERROR(gprof profiling requested but not available)], [[$CXXFLAG_WERROR]])
574+
575+
AX_CHECK_LINK_FLAG([[-no-pie]], [GPROF_LDFLAGS="-no-pie"])
576+
AX_CHECK_LINK_FLAG([[-pg]],[GPROF_LDFLAGS="$GPROF_LDFLAGS -pg"],
577+
[AC_MSG_ERROR(gprof profiling requested but not available)], [[$GPROF_LDFLAGS]])
578+
fi
579+
556580
if test x$TARGET_OS != xwindows; then
557581
# All windows code is PIC, forcing it on just adds useless compile warnings
558582
AX_CHECK_COMPILE_FLAG([-fPIC],[PIC_FLAGS="-fPIC"])
559583
fi
560584

561585
if test x$use_hardening != xno; then
586+
use_hardening=yes
562587
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
563588
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
564589

@@ -1237,6 +1262,8 @@ AC_SUBST(BITCOIN_TX_NAME)
12371262

12381263
AC_SUBST(RELDFLAGS)
12391264
AC_SUBST(ERROR_CXXFLAGS)
1265+
AC_SUBST(GPROF_CXXFLAGS)
1266+
AC_SUBST(GPROF_LDFLAGS)
12401267
AC_SUBST(HARDENED_CXXFLAGS)
12411268
AC_SUBST(HARDENED_CPPFLAGS)
12421269
AC_SUBST(HARDENED_LDFLAGS)
@@ -1330,6 +1357,7 @@ echo " with bench = $use_bench"
13301357
echo " with upnp = $use_upnp"
13311358
echo " use asm = $use_asm"
13321359
echo " debug enabled = $enable_debug"
1360+
echo " gprof enabled = $enable_gprof"
13331361
echo " werror = $enable_werror"
13341362
echo
13351363
echo " target os = $TARGET_OS"

doc/developer-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ Development tips and tricks
140140
Run configure with the --enable-debug option, then make. Or run configure with
141141
CXXFLAGS="-g -ggdb -O0" or whatever debug flags you need.
142142

143+
**compiling for gprof profiling**
144+
145+
Run configure with the --enable-gprof option, then make.
146+
143147
**debug.log**
144148

145149
If the code is behaving strangely, take a look in the debug.log file in the data directory;

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
DIST_SUBDIRS = secp256k1 univalue
66

7-
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS)
8-
AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS)
7+
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS)
8+
AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS)
99
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
1010
EXTRA_LIBRARIES =
1111

0 commit comments

Comments
 (0)