Skip to content

Commit 77b018e

Browse files
committed
Make sure MPIR_Breakpoint() is compiled without CFLAGS.
In optimized builds, CFLAGS contains various optimizations such as -O3, and is propogated by automake to all files. To work-around this, isolate MPIR_Breakpoint() and other MPIR_* symbols into its own library built with debugger specific CFLAGS. To prevent CFLAGS from being polluted elsewhere in the make tree, build this in its own tiny stand-alone makefile. Fixes #7757 Signed-off-by: Austen Lauria <[email protected]>
1 parent c3fe37d commit 77b018e

File tree

6 files changed

+130
-58
lines changed

6 files changed

+130
-58
lines changed

config/orte_config_files.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ AC_DEFUN([ORTE_CONFIG_FILES],[
1919
orte/Makefile
2020
orte/include/Makefile
2121
orte/etc/Makefile
22-
22+
orte/orted/orted-mpir/Makefile
2323
orte/tools/orted/Makefile
2424
orte/tools/orterun/Makefile
2525
orte/tools/wrappers/Makefile

orte/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ SUBDIRS = \
2424
$(MCA_orte_FRAMEWORKS_SUBDIRS) \
2525
$(MCA_orte_FRAMEWORK_COMPONENT_STATIC_SUBDIRS) \
2626
etc \
27+
orted/orted-mpir \
2728
. \
2829
$(MCA_orte_FRAMEWORK_COMPONENT_DSO_SUBDIRS)
2930

3031
DIST_SUBDIRS = \
3132
include \
3233
etc \
34+
orted/orted-mpir \
3335
$(MCA_orte_FRAMEWORKS_SUBDIRS) \
3436
$(MCA_orte_FRAMEWORK_COMPONENT_ALL_SUBDIRS)
3537

@@ -39,7 +41,8 @@ lib_LTLIBRARIES = lib@[email protected]
3941
lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES =
4042
lib@ORTE_LIB_PREFIX@open_rte_la_LIBADD = \
4143
$(MCA_orte_FRAMEWORK_LIBS) \
42-
$(ORTE_TOP_BUILDDIR)/opal/lib@[email protected]
44+
$(ORTE_TOP_BUILDDIR)/opal/lib@[email protected] \
45+
orted/orted-mpir/lib@[email protected]
4346
lib@ORTE_LIB_PREFIX@open_rte_la_DEPENDENCIES = $(libopen_rte_la_LIBADD)
4447
lib@ORTE_LIB_PREFIX@open_rte_la_LDFLAGS = -version-info $(libopen_rte_so_version)
4548

orte/orted/orted-mpir/Makefile.am

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- makefile -*-
2+
#
3+
# Copyright (c) 2021 IBM Corporation. All rights reserved.
4+
# $COPYRIGHT$
5+
#
6+
# Additional copyrights may follow
7+
#
8+
# $HEADER$
9+
#
10+
11+
# This is not quite in the Automake spirit, but we have to do it.
12+
# Since the mpir portion of the library must be built with -g, we
13+
# must eliminate the CFLAGS that are passed in here by default (which
14+
# may already have debugging and/or optimization flags).
15+
16+
CFLAGS = $(CFLAGS_WITHOUT_OPTFLAGS) $(DEBUGGER_CFLAGS)
17+
18+
lib_LTLIBRARIES = lib@[email protected]
19+
lib@ORTE_LIB_PREFIX@open_orted_mpir_la_SOURCES = \
20+
orted_mpir_breakpoint.c \
21+
orted_mpir.h
22+
lib@ORTE_LIB_PREFIX@open_orted_mpir_la_LDFLAGS = -avoid-version

orte/orted/orted-mpir/orted_mpir.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Copyright (c) 2021 IBM Corporation. All rights reserved.
2+
* $COPYRIGHT$
3+
*
4+
* Additional copyrights may follow
5+
*
6+
* $HEADER$
7+
*/
8+
9+
#ifndef ORTED_MPIR_H
10+
#define ORTED_MPIR_H
11+
12+
#include "orte_config.h"
13+
14+
#include "orte/runtime/orte_globals.h"
15+
16+
BEGIN_C_DECLS
17+
18+
#define MPIR_MAX_PATH_LENGTH 512
19+
#define MPIR_MAX_ARG_LENGTH 1024
20+
21+
extern struct MPIR_PROCDESC *MPIR_proctable;
22+
extern int MPIR_proctable_size;
23+
extern volatile int MPIR_being_debugged;
24+
extern volatile int MPIR_debug_state;
25+
extern int MPIR_i_am_starter;
26+
extern int MPIR_partial_attach_ok;
27+
extern char MPIR_executable_path[MPIR_MAX_PATH_LENGTH];
28+
extern char MPIR_server_arguments[MPIR_MAX_ARG_LENGTH];
29+
extern volatile int MPIR_forward_output;
30+
extern volatile int MPIR_forward_comm;
31+
extern char MPIR_attach_fifo[MPIR_MAX_PATH_LENGTH];
32+
extern int MPIR_force_to_main;
33+
34+
ORTE_DECLSPEC void __opal_attribute_optnone__ MPIR_Breakpoint(void);
35+
36+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2021 IBM Corporation. All rights reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*/
10+
11+
#include "orte_config.h"
12+
#include "orte/constants.h"
13+
#include "orted_mpir.h"
14+
15+
/* instance the standard MPIR interfaces */
16+
struct MPIR_PROCDESC *MPIR_proctable = NULL;
17+
int MPIR_proctable_size = 0;
18+
volatile int MPIR_being_debugged = 0;
19+
volatile int MPIR_debug_state = 0;
20+
int MPIR_i_am_starter = 0;
21+
int MPIR_partial_attach_ok = 1;
22+
char MPIR_executable_path[MPIR_MAX_PATH_LENGTH] = {0};
23+
char MPIR_server_arguments[MPIR_MAX_ARG_LENGTH] = {0};
24+
volatile int MPIR_forward_output = 0;
25+
volatile int MPIR_forward_comm = 0;
26+
char MPIR_attach_fifo[MPIR_MAX_PATH_LENGTH] = {0};
27+
int MPIR_force_to_main = 0;
28+
29+
/*
30+
* Attempt to prevent the compiler from optimizing out
31+
* MPIR_Breakpoint().
32+
*
33+
* Some older versions of automake can add -O3 to every
34+
* file via CFLAGS (which was demonstrated in automake v1.13.4),
35+
* so there is a possibility that the compiler will see
36+
* this function as a NOOP and optimize it out on older versions.
37+
* While using the current/recommended version of automake
38+
* does not do this, the following will help those
39+
* stuck with an older version, as well as guard against
40+
* future regressions.
41+
*
42+
* See the following git issue for more discussion:
43+
* https://github.com/open-mpi/ompi/issues/5501
44+
*/
45+
volatile void* volatile orte_noop_mpir_breakpoint_ptr = NULL;
46+
47+
/*
48+
* Breakpoint function for parallel debuggers
49+
*/
50+
void MPIR_Breakpoint(void)
51+
{
52+
/*
53+
* Actually do something with this pointer to make
54+
* sure the compiler does not optimize out this function.
55+
* The compiler should be forced to keep this
56+
* function around due to the volatile void* type.
57+
*
58+
* This pointer doesn't actually do anything other than
59+
* prevent unwanted optimization, and
60+
* *should not* be used anywhere else in the code.
61+
* So pointing this to the weeds should be OK.
62+
*/
63+
orte_noop_mpir_breakpoint_ptr = (volatile void *) 0x42;
64+
return;
65+
}

orte/orted/orted_submit.c

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
1818
* Copyright (c) 2015-2018 Research Organization for Information Science
1919
* and Technology (RIST). All rights reserved.
20-
* Copyright (c) 2017 IBM Corporation. All rights reserved.
20+
* Copyright (c) 2017-2021 IBM Corporation. All rights reserved.
2121
* $COPYRIGHT$
2222
*
2323
* Additional copyrights may follow
@@ -108,6 +108,7 @@
108108
#include "orte/util/show_help.h"
109109

110110
#include "orted_submit.h"
111+
#include "orted-mpir/orted_mpir.h"
111112

112113
/**
113114
* Global struct for catching orte command line options.
@@ -156,63 +157,8 @@ static void run_debugger(char *basename, opal_cmd_line_t *cmd_line,
156157
int argc, char *argv[], int num_procs);
157158
static void print_help(void);
158159

159-
/* instance the standard MPIR interfaces */
160-
#define MPIR_MAX_PATH_LENGTH 512
161-
#define MPIR_MAX_ARG_LENGTH 1024
162-
struct MPIR_PROCDESC *MPIR_proctable = NULL;
163-
int MPIR_proctable_size = 0;
164-
volatile int MPIR_being_debugged = 0;
165-
volatile int MPIR_debug_state = 0;
166-
int MPIR_i_am_starter = 0;
167-
int MPIR_partial_attach_ok = 1;
168-
char MPIR_executable_path[MPIR_MAX_PATH_LENGTH] = {0};
169-
char MPIR_server_arguments[MPIR_MAX_ARG_LENGTH] = {0};
170-
volatile int MPIR_forward_output = 0;
171-
volatile int MPIR_forward_comm = 0;
172-
char MPIR_attach_fifo[MPIR_MAX_PATH_LENGTH] = {0};
173-
int MPIR_force_to_main = 0;
174160
static void orte_debugger_init_before_spawn(orte_job_t *jdata);
175161

176-
ORTE_DECLSPEC void __opal_attribute_optnone__ MPIR_Breakpoint(void);
177-
178-
/*
179-
* Attempt to prevent the compiler from optimizing out
180-
* MPIR_Breakpoint().
181-
*
182-
* Some older versions of automake can add -O3 to every
183-
* file via CFLAGS (which was demonstrated in automake v1.13.4),
184-
* so there is a possibility that the compiler will see
185-
* this function as a NOOP and optimize it out on older versions.
186-
* While using the current/recommended version of automake
187-
* does not do this, the following will help those
188-
* stuck with an older version, as well as guard against
189-
* future regressions.
190-
*
191-
* See the following git issue for more discussion:
192-
* https://github.com/open-mpi/ompi/issues/5501
193-
*/
194-
volatile void* volatile orte_noop_mpir_breakpoint_ptr = NULL;
195-
196-
/*
197-
* Breakpoint function for parallel debuggers
198-
*/
199-
void MPIR_Breakpoint(void)
200-
{
201-
/*
202-
* Actually do something with this pointer to make
203-
* sure the compiler does not optimize out this function.
204-
* The compiler should be forced to keep this
205-
* function around due to the volatile void* type.
206-
*
207-
* This pointer doesn't actually do anything other than
208-
* prevent unwanted optimization, and
209-
* *should not* be used anywhere else in the code.
210-
* So pointing this to the weeds should be OK.
211-
*/
212-
orte_noop_mpir_breakpoint_ptr = (volatile void *) 0x42;
213-
return;
214-
}
215-
216162
/* local objects */
217163
typedef struct {
218164
opal_object_t super;

0 commit comments

Comments
 (0)