Skip to content

Commit f13d756

Browse files
committed
Merge #12373: Build: Add build support for profiling.
cfaac2a Add build support for 'gprof' profiling. (murrayn) Pull request description: Support for profiling build: `./configure --enable-profiling` Tree-SHA512: ea983cfce385f1893bb4ab7f94ac141b7d620951dc430da3bbc92ae1357fb05521eac689216e66dc87040171a8a57e76dd7ad98036e12a2896cfe5ab544347f0
2 parents 765a3eb + cfaac2a commit f13d756

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
@@ -148,9 +148,9 @@ AC_ARG_WITH([qrencode],
148148

149149
AC_ARG_ENABLE([hardening],
150150
[AS_HELP_STRING([--disable-hardening],
151-
[do not attempt to harden the resulting executables (default is to harden)])],
151+
[do not attempt to harden the resulting executables (default is to harden when possible)])],
152152
[use_hardening=$enableval],
153-
[use_hardening=yes])
153+
[use_hardening=auto])
154154

155155
AC_ARG_ENABLE([reduce-exports],
156156
[AS_HELP_STRING([--enable-reduce-exports],
@@ -219,6 +219,13 @@ AC_ARG_ENABLE([debug],
219219
[enable_debug=$enableval],
220220
[enable_debug=no])
221221

222+
# Enable gprof profiling
223+
AC_ARG_ENABLE([gprof],
224+
[AS_HELP_STRING([--enable-gprof],
225+
[use gprof profiling compiler flags (default is no)])],
226+
[enable_gprof=$enableval],
227+
[enable_gprof=no])
228+
222229
# Turn warnings into errors
223230
AC_ARG_ENABLE([werror],
224231
[AS_HELP_STRING([--enable-werror],
@@ -558,12 +565,30 @@ else
558565
AC_SEARCH_LIBS([clock_gettime],[rt])
559566
fi
560567

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

566590
if test x$use_hardening != xno; then
591+
use_hardening=yes
567592
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
568593
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
569594

@@ -1242,6 +1267,8 @@ AC_SUBST(BITCOIN_TX_NAME)
12421267

12431268
AC_SUBST(RELDFLAGS)
12441269
AC_SUBST(ERROR_CXXFLAGS)
1270+
AC_SUBST(GPROF_CXXFLAGS)
1271+
AC_SUBST(GPROF_LDFLAGS)
12451272
AC_SUBST(HARDENED_CXXFLAGS)
12461273
AC_SUBST(HARDENED_CPPFLAGS)
12471274
AC_SUBST(HARDENED_LDFLAGS)
@@ -1335,6 +1362,7 @@ echo " with bench = $use_bench"
13351362
echo " with upnp = $use_upnp"
13361363
echo " use asm = $use_asm"
13371364
echo " debug enabled = $enable_debug"
1365+
echo " gprof enabled = $enable_gprof"
13381366
echo " werror = $enable_werror"
13391367
echo
13401368
echo " target os = $TARGET_OS"

doc/developer-notes.md

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

145+
**compiling for gprof profiling**
146+
147+
Run configure with the --enable-gprof option, then make.
148+
145149
**debug.log**
146150

147151
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)