Skip to content

Commit 20f5840

Browse files
Add a compilation flag that adds unwind info to all files that are present in the stack starting from MPI_Init.
This is so when a debugger attaches using MPIR, it can step out of this stack back into main. This cannot be done with certain aggressive optimisations and missing debug information. Signed-off-by: James Clark <james.clark@arm.com> Signed-off-by: Jeff Squyres <jsquyres@cisco.com> Co-authored-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 4e5cacc commit 20f5840

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

config/orte_setup_debugger_flags.m4

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dnl Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
1010
dnl University of Stuttgart. All rights reserved.
1111
dnl Copyright (c) 2004-2005 The Regents of the University of California.
1212
dnl All rights reserved.
13-
dnl Copyright (c) 2006-2009 Cisco Systems, Inc. All rights reserved.
13+
dnl Copyright (c) 2006-2019 Cisco Systems, Inc. All rights reserved.
1414
dnl Copyright (c) 2006-2009 Sun Microsystems, Inc. All rights reserved.
1515
dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
1616
dnl reserved.
@@ -24,6 +24,28 @@ dnl
2424
dnl $HEADER$
2525
dnl
2626

27+
dnl Check to see if specific CFLAGS work
28+
dnl $1: compiler flags to check
29+
dnl $2: Action if the flags work
30+
dnl $3: Action if the flags do not work
31+
AC_DEFUN([_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS],[
32+
OPAL_VAR_SCOPE_PUSH([ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save])
33+
34+
ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save=$CFLAGS
35+
AC_MSG_CHECKING([if $1 compiler flag works])
36+
CFLAGS="$CFLAGS $1"
37+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[int i = 3;])],
38+
[ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=yes],
39+
[ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=no])
40+
AC_MSG_RESULT([$ORTE_SETUP_DEBUGGER_FLAGS_HAPPY])
41+
CFLAGS=$ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save
42+
43+
OPAL_VAR_SCOPE_POP
44+
45+
AS_IF([test $ORTE_SETUP_DEBUGGER_FLAGS_HAPPY = yes],
46+
[$2], [$3])
47+
])
48+
2749
AC_DEFUN([ORTE_SETUP_DEBUGGER_FLAGS],[
2850
#
2951
# Do a final process of the CFLAGS to make a WITHOUT_OPTFLAGS
@@ -53,4 +75,22 @@ AC_DEFUN([ORTE_SETUP_DEBUGGER_FLAGS],[
5375

5476
AC_SUBST(CFLAGS_WITHOUT_OPTFLAGS)
5577
AC_SUBST(DEBUGGER_CFLAGS)
78+
79+
# Check for compiler specific flag to add in unwind information.
80+
# This is needed when attaching using MPIR to unwind back to the
81+
# user's main function. Certain optimisations can prevent GDB from
82+
# producing a stack when explicit unwind information is unavailable.
83+
# This is implied by -g, but we want to save space and don't need
84+
# full debug symbols.
85+
_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-fasynchronous-unwind-tables],
86+
[MPIR_UNWIND_CFLAGS="-fasynchronous-unwind-tables"],
87+
[_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-Meh_frame -Mframe],
88+
[MPIR_UNWIND_CFLAGS="-Meh_frame -Mframe"],
89+
[MPIR_UNWIND_CFLAGS=-g])
90+
])
91+
92+
AC_MSG_CHECKING([for final compiler unwind flags])
93+
AC_MSG_RESULT([$MPIR_UNWIND_CFLAGS])
94+
95+
AC_SUBST(MPIR_UNWIND_CFLAGS)
5696
])

ompi/runtime/Makefile.am

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ headers += \
3333
lib@OMPI_LIBMPI_NAME@_la_SOURCES += \
3434
runtime/ompi_mpi_abort.c \
3535
runtime/ompi_mpi_dynamics.c \
36-
runtime/ompi_mpi_init.c \
3736
runtime/ompi_mpi_finalize.c \
3837
runtime/ompi_mpi_params.c \
3938
runtime/ompi_mpi_preconnect.c \
4039
runtime/ompi_cr.c \
4140
runtime/ompi_info_support.c \
4241
runtime/ompi_spc.c
42+
43+
# The MPIR portion of the library must be built with flags to
44+
# enable stepping out of MPI_INIT into main.
45+
# Use an intermediate library to isolate the debug object.
46+
noinst_LTLIBRARIES += libompi_mpir.la
47+
libompi_mpir_la_SOURCES = \
48+
runtime/ompi_mpi_init.c
49+
libompi_mpir_la_CFLAGS = $(MPIR_UNWIND_CFLAGS)
50+
51+
lib@OMPI_LIBMPI_NAME@_la_LIBADD += libompi_mpir.la

orte/mca/ess/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
AM_CPPFLAGS = $(LTDLINCL)
2121

22+
# Add unwind flags because files in this tree are
23+
# involved in startup.
24+
AM_CFLAGS = $(MPIR_UNWIND_CFLAGS)
25+
2226
# main library setup
2327
noinst_LTLIBRARIES = libmca_ess.la
2428
libmca_ess_la_SOURCES =

orte/mca/ess/pmi/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# $HEADER$
1212
#
1313

14+
# Add MPIR unwind flags because files in this tree are
15+
# involved in startup. This is not needed in the other
16+
# subdirs in orte/mca/ess because the other components are
17+
# solely used by daemons and thus are not accessible by the debugger.
18+
AM_CFLAGS = $(MPIR_UNWIND_CFLAGS)
19+
1420
AM_CPPFLAGS = $(ess_pmi_CPPFLAGS)
1521

1622
sources = \

orte/runtime/Makefile.am

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ headers += \
3838

3939
lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \
4040
runtime/orte_finalize.c \
41-
runtime/orte_init.c \
4241
runtime/orte_locks.c \
4342
runtime/orte_globals.c \
4443
runtime/orte_quit.c \
@@ -52,3 +51,12 @@ lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \
5251
runtime/orte_cr.c \
5352
runtime/orte_data_server.c \
5453
runtime/orte_info_support.c
54+
55+
# The MPIR portion of the library must be built with flags to
56+
# enable stepping out of MPI_INIT into main.
57+
# Use an intermediate library to isolate the debug object.
58+
noinst_LTLIBRARIES += libruntime_mpir.la
59+
libruntime_mpir_la_SOURCES = \
60+
runtime/orte_init.c
61+
libruntime_mpir_la_CFLAGS = $(MPIR_UNWIND_CFLAGS)
62+
lib@ORTE_LIB_PREFIX@open_rte_la_LIBADD += libruntime_mpir.la

0 commit comments

Comments
 (0)