aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/compilers/gnu_compiler.conf
blob: 9781f752f6046127c21f0404e16decf518642850 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
_STD_CXX=-std=$_STD_CXX_VERSION

_OPTIMIZE_RELEASE=
when ($_BUILD_RELEASE == "yes") {
    when ($_BUILD_SIZE_OPTIMIZED == "yes") {
        # -Oz is clang's more size-aggressive version of -Os
        # For ARM specifically, clang -Oz is on par with gcc -Os:
        # https://github.com/android/ndk/issues/133#issuecomment-365763507
        when($CLANG == "yes") {
            _OPTIMIZE_RELEASE=-Oz
        }
        otherwise {
            _OPTIMIZE_RELEASE=-Os
        }
    }
    otherwise {
        _OPTIMIZE_RELEASE=-O3
    }
}

_SFDL_FLAGS=-E -C -x c++
when ($CLANG == "yes") {
    _SFDL_FLAGS+=-Qunused-arguments
}

_DEBUG_INFO_FLAGS=-g
when ($OS_LINUX == "yes") {
    _DEBUG_INFO_FLAGS=-g -ggnu-pubnames
}

_CROSS_SUFFIX=.pic
when ($FORCE_NO_PIC == "yes") {
    when ($TOOL_BUILD_MODE == "yes" && $PIC == "yes") {
        # FIXME(spreis): This is temporary fix until more appropriate control over pic-like-in-tools mode will come
    }
    otherwise {
        _CROSS_SUFFIX=
    }
}

OPTIMIZE=$_OPTIMIZE_RELEASE
FSTACK=-fstack-protector
DUMP_DEPS=
GCC_PREPROCESSOR_OPTS=$DUMP_DEPS $C_DEFINES

# PIE is only valid for executables, while PIC implies a shared library
# `-pie` with a shared library is either ignored or fails to link
when ($PIC == "yes") {
    CFLAGS+=-fPIC
    LDFLAGS+=-fPIC
}
elsewhen ($PIE == "yes") {
    CFLAGS+=-fPIE
    LDFLAGS+=-fPIE -pie
}

when ($CLANG == "yes" && $ARCH_AARCH64 == "yes") {
    # Clang generates outline atomics if libgcc version is >= 9.3.1
    # See https://github.com/llvm/llvm-project/commit/c5e7e649d537067dec7111f3de1430d0fc8a4d11
    CFLAGS+=-mno-outline-atomics
}

when ($CLANG16 == "yes") {
    CFLAGS+=-Wno-array-parameter -Wno-deprecate-lax-vec-conv-all -Wno-unqualified-std-cast-call -Wno-unused-but-set-parameter -Wno-implicit-function-declaration -Wno-int-conversion -Wno-incompatible-function-pointer-types -Wno-address-of-packed-member
}

when ($MSAN_TRACK_ORIGIN == "yes") {
    CFLAGS+=-fsanitize-memory-track-origins=2
}

when ($ARCH_XTENSA == "yes") {
    FSTACK=
}

when ($OS_EMSCRIPTEN == "yes") {
    FSTACK=-fno-stack-protector
    CFLAGS+=-D__EMSCRIPTEN__
    CFLAGS+=-D_LIBCPP_HAS_MUSL_LIBC
}

CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
CXXFLAGS+=$CFLAGS $_STD_CXX $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
NOGCCSTACKCHECK=yes
SFDL_FLAG=$_SFDL_FLAGS -o $SFDL_TMP_OUT
WERROR_FLAG=-Werror
DEBUG_INFO_FLAGS=$_DEBUG_INFO_FLAGS

when ($NO_WSHADOW == "yes") {
    C_WARNING_OPTS += -Wno-shadow
}

when ($NO_COMPILER_WARNINGS == "yes") {
    # Though -w is intended to switch off all the warnings,
    # it does not switch at least -Wregister and -Wreserved-user-defined-literal under clang.
    #
    # Use -Wno-everything to force warning suppression.
    when ($CLANG == "yes") {
        C_WARNING_OPTS = -Wno-everything
        CXX_WARNING_OPTS = -Wno-everything
    }

    # On gcc -Wno-everything is not supported, so we use -w
    # see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
    elsewhen ($GCC == "yes") {
        C_WARNING_OPTS = -w
        CXX_WARNING_OPTS = -w
    }
}

when ($NO_OPTIMIZE == "yes") {
    OPTIMIZE = -O0
}
when ($SAVE_TEMPS ==  "yes") {
    CXXFLAGS += -save-temps
}
when ($NOGCCSTACKCHECK != "yes") {
    FSTACK += -fstack-check
}

when ($FORCE_CONSISTENT_DEBUG == "yes") {
    when ($CLANG == "yes") {
        CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T -Xclang -fdebug-compilation-dir -Xclang /tmp
    }
    otherwise {
        CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
        when ($ARCH_XTENSA == "yes") {
            CL_DEBUG_INFO=
        }
    }
    YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
}
elsewhen ($CONSISTENT_DEBUG == "yes") {
    when ($CLANG == "yes") {
        CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T -Xclang -fdebug-compilation-dir -Xclang /tmp
    }
    otherwise {
        CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
        when ($ARCH_XTENSA == "yes") {
            CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
        }
    }
    YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
}
elsewhen ($CONSISTENT_DEBUG_LIGHT == "yes") {
    when ($CLANG == "yes") {
        CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -Xclang -fdebug-compilation-dir -Xclang /tmp
    }
    otherwise {
        CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B
        when ($ARCH_XTENSA == "yes") {
            CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
        }
    }
    YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B ${env:"YASM_TEST_SUITE=1"}
}

when ($FORCE_CONSISTENT_BUILD == "yes") {
    CL_MACRO_INFO=-Wno-builtin-macro-redefined -D__DATE__=\""Sep 31 2019\"" -D__TIME__=\"00:00:00\" -fmacro-prefix-map=${ARCADIA_BUILD_ROOT}/= -fmacro-prefix-map=${ARCADIA_ROOT}/= -fmacro-prefix-map=$(TOOL_ROOT)/=
}
elsewhen ($CONSISTENT_BUILD == "yes") {
    CL_MACRO_INFO_DISABLE_CACHE__NO_UID__=-Wno-builtin-macro-redefined -D__DATE__=\""Sep 31 2019\"" -D__TIME__=\"00:00:00\" -fmacro-prefix-map=${ARCADIA_BUILD_ROOT}/= -fmacro-prefix-map=${ARCADIA_ROOT}/= -fmacro-prefix-map=$(TOOL_ROOT)/=
}

_CFLAGS_ARCH_I386=
when ($ARCH_I386 == "yes" && $ARCH_I686 != "yes") {
    _CFLAGS_ARCH_I386=-march=pentiumpro -mtune=pentiumpro
}

CFLAGS+=$_CFLAGS_ARCH_I386

BC_CFLAGS+=$CFLAGS
BC_CXXFLAGS+=$CXXFLAGS
C_DEFINES+=-D__LONG_LONG_SUPPORTED

OBJ_CROSS_SUF=$OBJ_SUF$_CROSS_SUFFIX
OBJECT_SUF=$OBJ_SUF$_CROSS_SUFFIX.o
GCC_COMPILE_FLAGS=$EXTRA_C_FLAGS -c -o $_COMPILE_OUTPUTS ${pre=-I:_C__INCLUDE}
EXTRA_COVERAGE_OUTPUT=${hide;noauto;output;suf=${OBJECT_SUF}.gcno:SRC}
CLANG_TIDY_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}.tidyjson:SRC}
YNDEXER_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}${COMPILE_OUT_SUFFIX}.ydx.pb2:SRC}

when ($DUMP_COMPILER_DEPS == "yes") {
    DUMP_DEPS=-MD ${hide;noauto;output;suf=${OBJ_SUF}.o.d:SRC}
}
elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
    DUMP_DEPS=-E -M -MF ${noauto;output;suf=${OBJ_SUF}.o.d:SRC}
}

_COMPILER_TIME_TRACE_GRANULARITY=500
when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
    _COMPILER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
}

_COMPILER_TIME_TRACE_FLAGS=
_COMPILER_TIME_TRACE_POSTPROCESS=
when (($TIME_TRACE == "yes" || $COMPILER_TIME_TRACE == "yes") && $_HAS_TIME_TRACE == "yes") {
    _COMPILER_TIME_TRACE_FLAGS=-ftime-trace -ftime-trace-granularity=$_COMPILER_TIME_TRACE_GRANULARITY
    _COMPILER_TIME_TRACE_POSTPROCESS=$YMAKE_PYTHON ${input:"build/scripts/find_time_trace.py"} $_COMPILE_OUTPUTS $_COMPILE_TIME_TRACE_OUTPUTS
}

_C_CPP_KV_STYLE=${hide;kv:"p CC"} ${hide;kv:"pc green"}
_C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC}
_C_CPP_KV_STYLE_P=p CC
_C_CPP_KV_STYLE_PC=pc green

_CPP_ARGS=\
    $CLANG_STATIC_ANALYZER_OPTIONS && \
    $CLANG_TIDY_ARGS \
    $YNDEXER_ARGS \
    $RETRY_ARGS \
    $CXX_COMPILER_OLD \
    $C_FLAGS_PLATFORM \
    $GCC_COMPILE_FLAGS \
    $CXXFLAGS \
    $CL_MACRO_INFO \
    $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
    $_COMPILER_TIME_TRACE_FLAGS \
    $EXTRA_OUTPUT \
    $SRCFLAGS \
    $_LANG_CFLAGS_VALUE \
    ${input:SRC} \
    $TOOLCHAIN_ENV \
    $YNDEXER_OUTPUT \
    && $_COMPILER_TIME_TRACE_POSTPROCESS \
    $_C_CPP_KV_STYLE

_CPP_ARGS_NEW_CMD_0=\
    $CLANG_STATIC_ANALYZER_OPTIONS_NEW

_CPP_ARGS_NEW_CMD_1_1=\
    $CLANG_TIDY_ARGS \
    $YNDEXER_ARGS \
    $RETRY_ARGS \
    $CXX_COMPILER \
    $C_FLAGS_PLATFORM \
    $GCC_COMPILE_FLAGS \
    $CXXFLAGS \
    $CL_MACRO_INFO \
    $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
    $_COMPILER_TIME_TRACE_FLAGS \
    $EXTRA_OUTPUT
_CPP_ARGS_NEW_CMD_1_2=\
    $SRCFLAGS \
    $_LANG_CFLAGS_VALUE_NEW \
    ${input:SRC} \
    $TOOLCHAIN_ENV \
    $YNDEXER_OUTPUT
_CPP_ARGS_NEW_CMD_2=\
    $_COMPILER_TIME_TRACE_POSTPROCESS \
    $_C_CPP_KV_STYLE_NEW \
    $SCU_NAME_KV_NEW

_C_ARGS=\
    $CLANG_TIDY_ARGS \
    $YNDEXER_ARGS \
    $RETRY_ARGS \
    $C_COMPILER_OLD \
    $C_FLAGS_PLATFORM \
    $GCC_COMPILE_FLAGS \
    $CFLAGS \
    $CL_MACRO_INFO \
    $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
    $_COMPILER_TIME_TRACE_FLAGS \
    $CONLYFLAGS \
    $EXTRA_OUTPUT \
    $SRCFLAGS \
    ${input:SRC} \
    $TOOLCHAIN_ENV \
    $YNDEXER_OUTPUT \
    $_C_CPP_KV_STYLE

_C_ARGS_NEW=\
    $CLANG_TIDY_ARGS \
    $YNDEXER_ARGS \
    $RETRY_ARGS \
    $C_COMPILER \
    $C_FLAGS_PLATFORM \
    $GCC_COMPILE_FLAGS \
    $CFLAGS \
    $CL_MACRO_INFO \
    $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
    $_COMPILER_TIME_TRACE_FLAGS \
    $CONLYFLAGS \
    $EXTRA_OUTPUT \
    $SRCFLAGS \
    ${input:SRC} \
    $TOOLCHAIN_ENV \
    $YNDEXER_OUTPUT \
    $_C_CPP_KV_STYLE_NEW \
    $SCU_NAME_KV_NEW

### _SRC_C_NODEPS_CMD is obtained from _C_ARGS by filtering the following elements:
### ${input:SRC}
### $CL_MACRO_INFO
### $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__
### $CLANG_TIDY_ARGS
### $EXTRA_OUTPUT
### $EXTRA_COVERAGE_OUTPUT
### $SRCFLAGS
### $YNDEXER_ARGS
### $YNDEXER_OUTPUT
###
### $GCC_COMPILE_FLAGS is substituted for $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC}
_SRC_C_NODEPS_CMD=\
    $C_COMPILER \
    $C_FLAGS_PLATFORM \
    $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC} \
    $CFLAGS \
    $CONLYFLAGS \
    $TOOLCHAIN_ENV \
    $_C_CPP_KV_STYLE

_FORCE_CPP_FLAGS=-x c++

_SRC_CPP_CMD=$_CPP_ARGS
_SRC_CPP_CMD_NEW=       $_CPP_ARGS_NEW_CMD_0                                           && $_CPP_ARGS_NEW_CMD_1_1                   $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2
_SRC_CPP_CMD_NEW_FORCED=$_CPP_ARGS_NEW_CMD_0 $CLANG_STATIC_ANALYZER_OPTIONS_NEW_FORCED && $_CPP_ARGS_NEW_CMD_1_1 $_FORCE_CPP_FLAGS $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2
_SRC_C_CMD=$_C_ARGS
_SRC_C_CMD_NEW=$_C_ARGS_NEW
_SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
_SRC_MASM_CMD=$_EMPTY_CMD