1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  *                         University Research and Technology
4  *                         Corporation.  All rights reserved.
5  * Copyright (c) 2004-2005 The University of Tennessee and The University
6  *                         of Tennessee Research Foundation.  All rights
7  *                         reserved.
8  * Copyright (c) 2004-2010 High Performance Computing Center Stuttgart,
9  *                         University of Stuttgart.  All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  *                         All rights reserved.
12  * Copyright (c) 2009      Sun Microsystems, Inc.  All rights reserved.
13  * Copyright (c) 2009-2013 Cisco Systems, Inc.  All rights reserved.
14  * Copyright (c) 2013      Mellanox Technologies, Inc.
15  *                         All rights reserved.
16  * Copyright (c) 2015-2017 Research Organization for Information Science
17  *                         and Technology (RIST). All rights reserved.
18  * Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
19  * $COPYRIGHT$
20  *
21  * Additional copyrights may follow
22  *
23  * $HEADER$
24  *
25  * This file is included at the bottom of opal_config.h, and is
26  * therefore a) after all the #define's that were output from
27  * configure, and b) included in most/all files in Open MPI.
28  *
29  * Since this file is *only* ever included by opal_config.h, and
30  * opal_config.h already has #ifndef/#endif protection, there is no
31  * need to #ifndef/#endif protection here.
32  */
33 
34 #ifndef OPAL_CONFIG_H
35 #error "opal_config_bottom.h should only be included from opal_config.h"
36 #endif
37 
38 /*
39  * If we build a static library, Visual C define the _LIB symbol. In the
40  * case of a shared library _USERDLL get defined.
41  *
42  * OMPI_BUILDING and _LIB define how opal_config.h
43  * handles configuring all of Open MPI's "compatibility" code.  Both
44  * constants will always be defined by the end of opal_config.h.
45  *
46  * OMPI_BUILDING affects how much compatibility code is included by
47  * opal_config.h.  It will always be 1 or 0.  The user can set the
48  * value before including either mpi.h or opal_config.h and it will be
49  * respected.  If opal_config.h is included before mpi.h, it will
50  * default to 1.  If mpi.h is included before opal_config.h, it will
51  * default to 0.
52  */
53 #ifndef OMPI_BUILDING
54 #define OMPI_BUILDING 1
55 #endif
56 
57 /*
58  * Flex is trying to include the unistd.h file. As there is no configure
59  * option or this, the flex generated files will try to include the file
60  * even on platforms without unistd.h. Therefore, if we
61  * know this file is not available, we can prevent flex from including it.
62  */
63 #ifndef HAVE_UNISTD_H
64 #define YY_NO_UNISTD_H
65 #endif
66 
67 /***********************************************************************
68  *
69  * code that should be in ompi_config_bottom.h regardless of build
70  * status
71  *
72  **********************************************************************/
73 
74 /*
75  * BEGIN_C_DECLS should be used at the beginning of your declarations,
76  * so that C++ compilers don't mangle their names.  Use END_C_DECLS at
77  * the end of C declarations.
78  */
79 #undef BEGIN_C_DECLS
80 #undef END_C_DECLS
81 #if defined(c_plusplus) || defined(__cplusplus)
82 # define BEGIN_C_DECLS extern "C" {
83 # define END_C_DECLS }
84 #else
85 #define BEGIN_C_DECLS          /* empty */
86 #define END_C_DECLS            /* empty */
87 #endif
88 
89 /**
90  * The attribute definition should be included before any potential
91  * usage.
92  */
93 #if OPAL_HAVE_ATTRIBUTE_ALIGNED
94 #    define __opal_attribute_aligned__(a)    __attribute__((__aligned__(a)))
95 #    define __opal_attribute_aligned_max__   __attribute__((__aligned__))
96 #else
97 #    define __opal_attribute_aligned__(a)
98 #    define __opal_attribute_aligned_max__
99 #endif
100 
101 #if OPAL_HAVE_ATTRIBUTE_ALWAYS_INLINE
102 #    define __opal_attribute_always_inline__ __attribute__((__always_inline__))
103 #else
104 #    define __opal_attribute_always_inline__
105 #endif
106 
107 #if OPAL_HAVE_ATTRIBUTE_COLD
108 #    define __opal_attribute_cold__          __attribute__((__cold__))
109 #else
110 #    define __opal_attribute_cold__
111 #endif
112 
113 #if OPAL_HAVE_ATTRIBUTE_CONST
114 #    define __opal_attribute_const__         __attribute__((__const__))
115 #else
116 #    define __opal_attribute_const__
117 #endif
118 
119 #if OPAL_HAVE_ATTRIBUTE_DEPRECATED
120 #    define __opal_attribute_deprecated__    __attribute__((__deprecated__))
121 #else
122 #    define __opal_attribute_deprecated__
123 #endif
124 
125 #if OPAL_HAVE_ATTRIBUTE_FORMAT
126 #    define __opal_attribute_format__(a,b,c) __attribute__((__format__(a, b, c)))
127 #else
128 #    define __opal_attribute_format__(a,b,c)
129 #endif
130 
131 /* Use this __atribute__ on function-ptr declarations, only */
132 #if OPAL_HAVE_ATTRIBUTE_FORMAT_FUNCPTR
133 #    define __opal_attribute_format_funcptr__(a,b,c) __attribute__((__format__(a, b, c)))
134 #else
135 #    define __opal_attribute_format_funcptr__(a,b,c)
136 #endif
137 
138 #if OPAL_HAVE_ATTRIBUTE_HOT
139 #    define __opal_attribute_hot__           __attribute__((__hot__))
140 #else
141 #    define __opal_attribute_hot__
142 #endif
143 
144 #if OPAL_HAVE_ATTRIBUTE_MALLOC
145 #    define __opal_attribute_malloc__        __attribute__((__malloc__))
146 #else
147 #    define __opal_attribute_malloc__
148 #endif
149 
150 #if OPAL_HAVE_ATTRIBUTE_MAY_ALIAS
151 #    define __opal_attribute_may_alias__     __attribute__((__may_alias__))
152 #else
153 #    define __opal_attribute_may_alias__
154 #endif
155 
156 #if OPAL_HAVE_ATTRIBUTE_NO_INSTRUMENT_FUNCTION
157 #    define __opal_attribute_no_instrument_function__  __attribute__((__no_instrument_function__))
158 #else
159 #    define __opal_attribute_no_instrument_function__
160 #endif
161 
162 #if OPAL_HAVE_ATTRIBUTE_NOINLINE
163 #    define __opal_attribute_noinline__  __attribute__((__noinline__))
164 #else
165 #    define __opal_attribute_noinline__
166 #endif
167 
168 #if OPAL_HAVE_ATTRIBUTE_NONNULL
169 #    define __opal_attribute_nonnull__(a)    __attribute__((__nonnull__(a)))
170 #    define __opal_attribute_nonnull_all__   __attribute__((__nonnull__))
171 #else
172 #    define __opal_attribute_nonnull__(a)
173 #    define __opal_attribute_nonnull_all__
174 #endif
175 
176 #if OPAL_HAVE_ATTRIBUTE_NORETURN
177 #    define __opal_attribute_noreturn__      __attribute__((__noreturn__))
178 #else
179 #    define __opal_attribute_noreturn__
180 #endif
181 
182 /* Use this __atribute__ on function-ptr declarations, only */
183 #if OPAL_HAVE_ATTRIBUTE_NORETURN_FUNCPTR
184 #    define __opal_attribute_noreturn_funcptr__  __attribute__((__noreturn__))
185 #else
186 #    define __opal_attribute_noreturn_funcptr__
187 #endif
188 
189 #if OPAL_HAVE_ATTRIBUTE_PACKED
190 #    define __opal_attribute_packed__        __attribute__((__packed__))
191 #else
192 #    define __opal_attribute_packed__
193 #endif
194 
195 #if OPAL_HAVE_ATTRIBUTE_PURE
196 #    define __opal_attribute_pure__          __attribute__((__pure__))
197 #else
198 #    define __opal_attribute_pure__
199 #endif
200 
201 #if OPAL_HAVE_ATTRIBUTE_SENTINEL
202 #    define __opal_attribute_sentinel__      __attribute__((__sentinel__))
203 #else
204 #    define __opal_attribute_sentinel__
205 #endif
206 
207 #if OPAL_HAVE_ATTRIBUTE_UNUSED
208 #    define __opal_attribute_unused__        __attribute__((__unused__))
209 #else
210 #    define __opal_attribute_unused__
211 #endif
212 
213 #if OPAL_HAVE_ATTRIBUTE_VISIBILITY
214 #    define __opal_attribute_visibility__(a) __attribute__((__visibility__(a)))
215 #else
216 #    define __opal_attribute_visibility__(a)
217 #endif
218 
219 #if OPAL_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT
220 #    define __opal_attribute_warn_unused_result__ __attribute__((__warn_unused_result__))
221 #else
222 #    define __opal_attribute_warn_unused_result__
223 #endif
224 
225 #if OPAL_HAVE_ATTRIBUTE_WEAK_ALIAS
226 #    define __opal_attribute_weak_alias__(a) __attribute__((__weak__, __alias__(a)))
227 #else
228 #    define __opal_attribute_weak_alias__(a)
229 #endif
230 
231 #if OPAL_HAVE_ATTRIBUTE_DESTRUCTOR
232 #    define __opal_attribute_destructor__    __attribute__((__destructor__))
233 #else
234 #    define __opal_attribute_destructor__
235 #endif
236 
237 #if OPAL_HAVE_ATTRIBUTE_OPTNONE
238 #    define __opal_attribute_optnone__    __attribute__((__optnone__))
239 #else
240 #    define __opal_attribute_optnone__
241 #endif
242 
243 #if OPAL_HAVE_ATTRIBUTE_EXTENSION
244 #    define __opal_attribute_extension__    __extension__
245 #else
246 #    define __opal_attribute_extension__
247 #endif
248 
249 #  if OPAL_C_HAVE_VISIBILITY
250 #    define OPAL_DECLSPEC           __opal_attribute_visibility__("default")
251 #    define OPAL_MODULE_DECLSPEC    __opal_attribute_visibility__("default")
252 #  else
253 #    define OPAL_DECLSPEC
254 #    define OPAL_MODULE_DECLSPEC
255 #  endif
256 
257 #if !defined(__STDC_LIMIT_MACROS) && (defined(c_plusplus) || defined (__cplusplus))
258 /* When using a C++ compiler, the max / min value #defines for std
259    types are only included if __STDC_LIMIT_MACROS is set before
260    including stdint.h */
261 #define __STDC_LIMIT_MACROS
262 #endif
263 #include "opal_stdint.h"
264 
265 /***********************************************************************
266  *
267  * Code that is only for when building Open MPI or utilities that are
268  * using the internals of Open MPI.  It should not be included when
269  * building MPI applications
270  *
271  **********************************************************************/
272 #if OMPI_BUILDING
273 
274 /*
275  * Maximum size of a filename path.
276  */
277 #include <limits.h>
278 #ifdef HAVE_SYS_PARAM_H
279 #include <sys/param.h>
280 #endif
281 #if defined(PATH_MAX)
282 #define OPAL_PATH_MAX   (PATH_MAX + 1)
283 #elif defined(_POSIX_PATH_MAX)
284 #define OPAL_PATH_MAX   (_POSIX_PATH_MAX + 1)
285 #else
286 #define OPAL_PATH_MAX   256
287 #endif
288 
289 /*
290  * Set the compile-time path-separator on this system and variable separator
291  */
292 #define OPAL_PATH_SEP "/"
293 #define OPAL_ENV_SEP  ':'
294 
295 #if defined(MAXHOSTNAMELEN)
296 #define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
297 #elif defined(HOST_NAME_MAX)
298 #define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
299 #else
300 /* SUSv2 guarantees that "Host names are limited to 255 bytes". */
301 #define OPAL_MAXHOSTNAMELEN (255 + 1)
302 #endif
303 
304 /*
305  * Do we want memory debugging?
306  *
307  * A few scenarios:
308  *
309  * 1. In the OMPI C library: we want these defines in all cases
310  * 2. In the OMPI C++ bindings: we do not want them
311  * 3. In the OMPI C++ executables: we do want them
312  *
313  * So for 1, everyone must include <opal_config.h> first.  For 2, the
314  * C++ bindings will never include <opal_config.h> -- they will only
315  * include <mpi.h>, which includes <opal_config.h>, but after
316  * setting OMPI_BUILDING to 0  For 3, it's the same as 1 -- just include
317  * <opal_config.h> first.
318  *
319  * Give code that needs to include opal_config.h but really can't have
320  * this stuff enabled (like the memory manager code) a way to turn us
321  * off
322  */
323 #if OPAL_ENABLE_MEM_DEBUG && !defined(OPAL_DISABLE_ENABLE_MEM_DEBUG)
324 
325 /* It is safe to include opal/util/malloc.h here because a) it will only
326    happen when we are building OMPI and therefore have a full OMPI
327    source tree [including headers] available, and b) we guaranteed to
328    *not* to include anything else via opal/util/malloc.h, so we won't
329    have Cascading Includes Of Death. */
330 #    include "opal/util/malloc.h"
331 #    if defined(malloc)
332 #        undef malloc
333 #    endif
334 #    define malloc(size) opal_malloc((size), __FILE__, __LINE__)
335 #    if defined(calloc)
336 #        undef calloc
337 #    endif
338 #    define calloc(nmembers, size) opal_calloc((nmembers), (size), __FILE__, __LINE__)
339 #    if defined(realloc)
340 #        undef realloc
341 #    endif
342 #    define realloc(ptr, size) opal_realloc((ptr), (size), __FILE__, __LINE__)
343 #    if defined(free)
344 #        undef free
345 #    endif
346 #    define free(ptr) opal_free((ptr), __FILE__, __LINE__)
347 
348 /*
349  * If we're mem debugging, make the OPAL_DEBUG_ZERO resolve to memset
350  */
351 #    include <string.h>
352 #    define OPAL_DEBUG_ZERO(obj) memset(&(obj), 0, sizeof(obj))
353 #else
354 #    define OPAL_DEBUG_ZERO(obj)
355 #endif
356 
357 /*
358  * printf functions for portability (only when building Open MPI)
359  */
360 #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
361 #include <stdarg.h>
362 #include <stdlib.h>
363 #endif
364 
365 #if !defined(HAVE_ASPRINTF) || !defined(HAVE_SNPRINTF) || !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF)
366 #include "opal/util/printf.h"
367 #endif
368 
369 #ifndef HAVE_ASPRINTF
370 # define asprintf opal_asprintf
371 #endif
372 
373 #ifndef HAVE_SNPRINTF
374 # define snprintf opal_snprintf
375 #endif
376 
377 #ifndef HAVE_VASPRINTF
378 # define vasprintf opal_vasprintf
379 #endif
380 
381 #ifndef HAVE_VSNPRINTF
382 # define vsnprintf opal_vsnprintf
383 #endif
384 
385 /*
386  * Some platforms (Solaris) have a broken qsort implementation.  Work
387  * around by using our own.
388  */
389 #if OPAL_HAVE_BROKEN_QSORT
390 #ifdef qsort
391 #undef qsort
392 #endif
393 
394 #include "opal/util/qsort.h"
395 #define qsort opal_qsort
396 #endif
397 
398 /*
399  * On some homogenous big-iron machines (Sandia's Red Storm), there
400  * are no htonl and friends.  If that's the case, provide stubs.  I
401  * would hope we never find a platform that doesn't have these macros
402  * and would want to talk to the outside world... On other platforms
403  * we fail to detect them correctly.
404  */
405 #if !defined(HAVE_UNIX_BYTESWAP)
htonl(uint32_t hostvar)406 static inline uint32_t htonl(uint32_t hostvar) { return hostvar; }
ntohl(uint32_t netvar)407 static inline uint32_t ntohl(uint32_t netvar) { return netvar; }
htons(uint16_t hostvar)408 static inline uint16_t htons(uint16_t hostvar) { return hostvar; }
ntohs(uint16_t netvar)409 static inline uint16_t ntohs(uint16_t netvar) { return netvar; }
410 #endif
411 
412 /*
413  * Define __func__-preprocessor directive if the compiler does not
414  * already define it.  Define it to __FILE__ so that we at least have
415  * a clue where the developer is trying to indicate where the error is
416  * coming from (assuming that __func__ is typically used for
417  * printf-style debugging).
418  */
419 #if defined(HAVE_DECL___FUNC__) && !HAVE_DECL___FUNC__
420 #define __func__ __FILE__
421 #endif
422 
423 #define IOVBASE_TYPE  void
424 
425 /* ensure the bool type is defined as it is used everywhere */
426 #include <stdbool.h>
427 
428 /**
429  * If we generate our own bool type, we need a special way to cast the result
430  * in such a way to keep the compilers silent.
431  */
432 #  define OPAL_INT_TO_BOOL(VALUE)  (bool)(VALUE)
433 
434 /**
435  * Top level define to check 2 things: a) if we want ipv6 support, and
436  * b) the underlying system supports ipv6.  Having one #define for
437  * this makes it simpler to check throughout the code base.
438  */
439 #if OPAL_ENABLE_IPV6 && defined(HAVE_STRUCT_SOCKADDR_IN6)
440 #define OPAL_ENABLE_IPV6 1
441 #else
442 #define OPAL_ENABLE_IPV6 0
443 #endif
444 
445 #if !defined(HAVE_STRUCT_SOCKADDR_STORAGE) && defined(HAVE_STRUCT_SOCKADDR_IN)
446 #define sockaddr_storage sockaddr
447 #define ss_family sa_family
448 #endif
449 
450 /* Compatibility structure so that we don't have to have as many
451    #if checks in the code base */
452 #if !defined(HAVE_STRUCT_SOCKADDR_IN6) && defined(HAVE_STRUCT_SOCKADDR_IN)
453 #define sockaddr_in6 sockaddr_in
454 #define sin6_len sin_len
455 #define sin6_family sin_family
456 #define sin6_port sin_port
457 #define sin6_addr sin_addr
458 #endif
459 
460 #if !HAVE_DECL_AF_UNSPEC
461 #define AF_UNSPEC 0
462 #endif
463 #if !HAVE_DECL_PF_UNSPEC
464 #define PF_UNSPEC 0
465 #endif
466 #if !HAVE_DECL_AF_INET6
467 #define AF_INET6 AF_UNSPEC
468 #endif
469 #if !HAVE_DECL_PF_INET6
470 #define PF_INET6 PF_UNSPEC
471 #endif
472 
473 #if defined(__APPLE__) && defined(HAVE_INTTYPES_H)
474 /* Prior to Mac OS X 10.3, the length modifier "ll" wasn't
475    supported, but "q" was for long long.  This isn't ANSI
476    C and causes a warning when using PRI?64 macros.  We
477    don't support versions prior to OS X 10.3, so we dont'
478    need such backward compatibility.  Instead, redefine
479    the macros to be "ll", which is ANSI C and doesn't
480    cause a compiler warning. */
481 #include <inttypes.h>
482 #if defined(__PRI_64_LENGTH_MODIFIER__)
483 #undef __PRI_64_LENGTH_MODIFIER__
484 #define __PRI_64_LENGTH_MODIFIER__ "ll"
485 #endif
486 #if defined(__SCN_64_LENGTH_MODIFIER__)
487 #undef __SCN_64_LENGTH_MODIFIER__
488 #define __SCN_64_LENGTH_MODIFIER__ "ll"
489 #endif
490 #endif
491 
492 #ifdef MCS_VXWORKS
493 /* VXWorks puts some common functions in oddly named headers.  Rather
494    than update all the places the functions are used, which would be a
495    maintenance disatster, just update here... */
496 #ifdef HAVE_IOLIB_H
497 /* pipe(), ioctl() */
498 #include <ioLib.h>
499 #endif
500 #ifdef HAVE_SOCKLIB_H
501 /* socket() */
502 #include <sockLib.h>
503 #endif
504 #ifdef HAVE_HOSTLIB_H
505 /* gethostname() */
506 #include <hostLib.h>
507 #endif
508 #endif
509 
510 /* If we're in C++, then just undefine restrict and then define it to
511    nothing.  "restrict" is not part of the C++ language, and we don't
512    have a corresponding AC_CXX_RESTRICT to figure out what the C++
513    compiler supports. */
514 #if defined(c_plusplus) || defined(__cplusplus)
515 #undef restrict
516 #define restrict
517 #endif
518 
519 #else
520 
521 /* For a similar reason to what is listed in opal_config_top.h, we
522    want to protect others from the autoconf/automake-generated
523    PACKAGE_<foo> macros in opal_config.h.  We can't put these undef's
524    directly in opal_config.h because they'll be turned into #defines'
525    via autoconf.
526 
527    So put them here in case any only else includes OMPI/ORTE/OPAL's
528    config.h files. */
529 
530 #undef PACKAGE_BUGREPORT
531 #undef PACKAGE_NAME
532 #undef PACKAGE_STRING
533 #undef PACKAGE_TARNAME
534 #undef PACKAGE_VERSION
535 #undef PACKAGE_URL
536 #undef HAVE_CONFIG_H
537 
538 #endif /* OMPI_BUILDING */
539