Don't define _FORTIFY_SOURCE on MinGW
[deliverable/binutils-gdb.git] / gdb / gdbsupport / common-defs.h
1 /* Common definitions.
2
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef COMMON_COMMON_DEFS_H
21 #define COMMON_COMMON_DEFS_H
22
23 #include "config.h"
24
25 #undef PACKAGE_NAME
26 #undef PACKAGE_VERSION
27 #undef PACKAGE_STRING
28 #undef PACKAGE_TARNAME
29
30 #ifdef GDBSERVER
31 #include "build-gnulib-gdbserver/config.h"
32 #else
33 #include "../../gnulib/config.h"
34 #endif
35
36 #undef PACKAGE_NAME
37 #undef PACKAGE_VERSION
38 #undef PACKAGE_STRING
39 #undef PACKAGE_TARNAME
40
41 /* From:
42 https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
43
44 "On some hosts that predate C++11, when using C++ one must define
45 __STDC_CONSTANT_MACROS to make visible the definitions of constant
46 macros such as INTMAX_C, and one must define __STDC_LIMIT_MACROS to
47 make visible the definitions of limit macros such as INTMAX_MAX.".
48
49 And:
50 https://www.gnu.org/software/gnulib/manual/html_node/inttypes_002eh.html
51
52 "On some hosts that predate C++11, when using C++ one must define
53 __STDC_FORMAT_MACROS to make visible the declarations of format
54 macros such as PRIdMAX."
55
56 Must do this before including any system header, since other system
57 headers may include stdint.h/inttypes.h. */
58 #define __STDC_CONSTANT_MACROS 1
59 #define __STDC_LIMIT_MACROS 1
60 #define __STDC_FORMAT_MACROS 1
61
62 /* Some distros enable _FORTIFY_SOURCE by default, which on occasion
63 has caused build failures with -Wunused-result when a patch is
64 developed on a distro that does not enable _FORTIFY_SOURCE. We
65 enable it here in order to try to catch these problems earlier;
66 plus this seems like a reasonable safety measure. The check for
67 optimization is required because _FORTIFY_SOURCE only works when
68 optimization is enabled. If _FORTIFY_SOURCE is already defined,
69 then we don't do anything. Also, on MinGW, fortify requires
70 linking to -lssp, and to avoid the hassle of checking for
71 that and linking to it statically, we just don't define
72 _FORTIFY_SOURCE there. */
73
74 #if (!defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ > 0 \
75 && !defined(__MINGW32__))
76 #define _FORTIFY_SOURCE 2
77 #endif
78
79 /* We don't support Windows versions before XP, so we define
80 _WIN32_WINNT correspondingly to ensure the Windows API headers
81 expose the required symbols. */
82 #if defined (__MINGW32__) || defined (__CYGWIN__)
83 # ifdef _WIN32_WINNT
84 # if _WIN32_WINNT < 0x0501
85 # undef _WIN32_WINNT
86 # define _WIN32_WINNT 0x0501
87 # endif
88 # else
89 # define _WIN32_WINNT 0x0501
90 # endif
91 #endif /* __MINGW32__ || __CYGWIN__ */
92
93 #include <stdarg.h>
94 #include <stdio.h>
95 #include <stdlib.h>
96 #include <stddef.h>
97 #include <stdint.h>
98 #include <string.h>
99 #ifdef HAVE_STRINGS_H
100 #include <strings.h> /* for strcasecmp and strncasecmp */
101 #endif
102 #include <errno.h>
103 #include <alloca.h>
104 /* Must be included before pathmax.h to avoid build errors about localtime_r
105 and gmtime_r in gnulib on MinGW. This is a gnulib bug:
106 https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00022.html */
107 #include <time.h>
108
109
110 #include "ansidecl.h"
111 /* This is defined by ansidecl.h, but we prefer gnulib's version. On
112 MinGW, gnulib might enable __USE_MINGW_ANSI_STDIO, which may or not
113 require use of attribute gnu_printf instead of printf. gnulib
114 checks that at configure time. Since _GL_ATTRIBUTE_FORMAT_PRINTF
115 is compatible with ATTRIBUTE_PRINTF, simply use it. */
116 #undef ATTRIBUTE_PRINTF
117 #define ATTRIBUTE_PRINTF _GL_ATTRIBUTE_FORMAT_PRINTF
118
119 #if GCC_VERSION >= 3004
120 #define ATTRIBUTE_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
121 #else
122 #define ATTRIBUTE_UNUSED_RESULT
123 #endif
124
125 #include "libiberty.h"
126 #include "pathmax.h"
127 #include "gdb/signals.h"
128 #include "gdb_locale.h"
129 #include "ptid.h"
130 #include "common-types.h"
131 #include "common-utils.h"
132 #include "gdb_assert.h"
133 #include "errors.h"
134 #include "print-utils.h"
135 #include "common-debug.h"
136 #include "cleanups.h"
137 #include "common-exceptions.h"
138 #include "gdbsupport/poison.h"
139
140 #define EXTERN_C extern "C"
141 #define EXTERN_C_PUSH extern "C" {
142 #define EXTERN_C_POP }
143
144 /* Pull in gdb::unique_xmalloc_ptr. */
145 #include "gdbsupport/gdb_unique_ptr.h"
146
147 /* String containing the current directory (what getwd would return). */
148 extern char *current_directory;
149
150 /* sbrk on macOS is not useful for our purposes, since sbrk(0) always
151 returns the same value. brk/sbrk on macOS is just an emulation
152 that always returns a pointer to a 4MB section reserved for
153 that. */
154
155 #if defined (HAVE_SBRK) && !__APPLE__
156 #define HAVE_USEFUL_SBRK 1
157 #endif
158
159 #endif /* COMMON_COMMON_DEFS_H */
This page took 0.03529 seconds and 5 git commands to generate.