aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/compilers/gnu_compiler.conf
blob: 747e1793d1c8d7aaee5ced6dbb179ed599642efb (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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
_C_DEFINES_ANDROID=
_C_DEFINES_ANDROID_OTHERWISE=
when ($OS_ANDROID == "yes") {
    _C_DEFINES_ANDROID=-DANDROID_FAKEID=$ANDROID_FAKEID
}
otherwise {
    # There is no usable _FILE_OFFSET_BITS=64 support in Androids until API 21. And it's incomplete until at least API 24.
    # https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
    # Arcadia have API 16 for 32-bit Androids.
    _C_DEFINES_ANDROID_OTHERWISE=-D_FILE_OFFSET_BITS=64
}

_C_DEFINES_GNU_SOURCE=
when ($OS_LINUX == "yes" || $OS_ANDROID == "yes" || $OS_CYGWIN == "yes") {
    _C_DEFINES_GNU_SOURCE=-D_GNU_SOURCE
}

_C_DEFINES_CLANG_LINUX_X86_64=
when ($CLANG == "yes" && $OS_LINUX == "yes" && $ARCH_X86_64 == "yes") {
    _C_DEFINES_CLANG_LINUX_X86_64=-D_YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
}

_C_DEFINES_IOS=
when ($OS_IOS == "yes") {
    _C_DEFINES_IOS=-D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
}

_C_DEFINES_WITH_VALGRIND=
when ($WITH_VALGRIND == "yes") {
    _C_DEFINES_WITH_VALGRIND=-DWITH_VALGRIND=1
}

C_DEFINES =-DFAKEID=$CPP_FAKEID
C_DEFINES+=$_C_DEFINES_ANDROID
C_DEFINES+=\
    -DARCADIA_ROOT=${ARCADIA_ROOT} \
    -DARCADIA_BUILD_ROOT=${ARCADIA_BUILD_ROOT} \
    -D_THREAD_SAFE \
    -D_PTHREADS \
    -D_REENTRANT \
    -D_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES \
    -D_LARGEFILE_SOURCE \
    -D__STDC_CONSTANT_MACROS \
    -D__STDC_FORMAT_MACROS
C_DEFINES+=$_C_DEFINES_ANDROID_OTHERWISE
C_DEFINES+=$_C_DEFINES_GNU_SOURCE
C_DEFINES+=$_C_DEFINES_CLANG_LINUX_X86_64
C_DEFINES+=$_C_DEFINES_IOS
C_DEFINES+=$_C_DEFINES_WITH_VALGRIND
C_DEFINES+=$_C_DEFINES_NDEBUG

_C_FOPTIONS_INIT_ARRAY=
when ($CLANG == "yes" && $OS_LINUX == "yes") {
    # Use .init_array instead of .ctors (default for old clang versions)
    # See: https://maskray.me/blog/2021-11-07-init-ctors-init-array
    _C_FOPTIONS_INIT_ARRAY=-fuse-init-array
}

_C_FOPTIONS_COLOR=
_C_FOPTIONS_ALIGNED_ALLOCATION=
when ($CLANG == "yes") {
    # Set up output colorization
    _C_FOPTIONS_COLOR=-fcolor-diagnostics
    # Enable aligned allocation
    _C_FOPTIONS_ALIGNED_ALLOCATION=-faligned-allocation
}
elsewhen ($GCC == "yes") {
    # Set up output colorization
    _C_FOPTIONS_COLOR=-fdiagnostics-color=always
    # It looks like there is no way to enable aligned allocation in gcc
}

_C_FOPTIONS_MAPSMOBI_ARM=
when ($OS_IOS == "yes") {
    when ($MAPSMOBI_BUILD_TARGET == "yes" && $ARCH_ARM == "yes") {
        _C_FOPTIONS_MAPSMOBI_ARM=-fembed-bitcode
    }
}

_C_WARNINGS_CLANG=
_CXX_WARNINGS_CLANG=
when ($CLANG == "yes") {
    _CXX_WARNINGS_CLANG=\
        -Wimport-preprocessor-directive-pedantic \
        -Wno-undefined-var-template \
        -Wno-return-std-move \
        -Wno-defaulted-function-deleted \
        -Wno-pessimizing-move \
        -Wno-range-loop-construct \
        -Wno-deprecated-anon-enum-enum-conversion \
        -Wno-deprecated-enum-enum-conversion \
        -Wno-deprecated-enum-float-conversion \
        -Wno-ambiguous-reversed-operator \
        -Wno-deprecated-volatile

    # -Wno-unknown-warning-option
    # For nvcc to accept the above.
    _C_WARNINGS_CLANG=\
        -Wno-implicit-const-int-float-conversion \
        -Wno-unknown-warning-option
}

_C_FOPTIONS_GCC=
when ($GCC == "yes") {
    _C_FOPTIONS_GCC=-fno-delete-null-pointer-checks -fabi-version=8
}

_C_FOPTIONS_IOS=
when ($OS_IOS != "yes") {
    # Split all functions and data into separate sections for DCE and ICF linker passes
    # NOTE: iOS build uses -fembed-bitcode which conflicts with -ffunction-sections (only relevant for ELF targets)
    _C_FOPTIONS_IOS=-ffunction-sections -fdata-sections
}

_C_FOPTIONS_DEBUG=
when ($_BUILD_DEBUG == "yes") {
    _C_FOPTIONS_DEBUG=$FSTACK
}

_C_FLAGS_RELEASE=
_C_FOPTIONS_RELEASE=
_OPTIMIZE_RELEASE=
when ($_BUILD_RELEASE == "yes") {
    _C_FLAGS_RELEASE=$OPTIMIZE
    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
        }

        # Generate sections with address significance tables for ICF linker pass
        when($CLANG == "yes") {
            _C_FOPTIONS_RELEASE=-faddrsig
        }
    }
    otherwise {
        _OPTIMIZE_RELEASE=-O3
    }
}

_C_FOPTIONS_PROFILER=
when ($_BUILD_PROFILER_TYPE != "") {
    when ($_BUILD_PROFILER_TYPE in ["generic", "gprof"]) {
        _C_FOPTIONS_PROFILER=-fno-omit-frame-pointer
    }
}

_C_FOPTIONS =

# Enable C++ exceptions (and allow them to be throw through pure C code)
_C_FOPTIONS+=-fexceptions

# Enable standard-conforming behavior and generate duplicate symbol error in case of duplicated global constants.
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85678#c0
_C_FOPTIONS+=-fno-common

_C_FOPTIONS+=$_C_FOPTIONS_INIT_ARRAY
_C_FOPTIONS+=$_C_FOPTIONS_COLOR
_C_FOPTIONS+=$_C_FOPTIONS_ALIGNED_ALLOCATION
_C_FOPTIONS+=$_C_FOPTIONS_MAPSMOBI_ARM
_C_FOPTIONS+=$_C_FOPTIONS_DEBUG
_C_FOPTIONS+=$_C_FOPTIONS_RELEASE
_C_FOPTIONS+=$_C_FOPTIONS_PROFILER
_C_FOPTIONS+=$_C_FOPTIONS_GCC
_C_FOPTIONS+=$_C_FOPTIONS_IOS

# Enable default warnings subset
_C_WARNINGS =-Wall -Wextra

# Disable some warnings which will fail compilation at the time
_C_WARNINGS+=-Wno-parentheses

_C_WARNINGS+=$_C_WARNINGS_CLANG

# Issue a warning if certain overload is hidden due to inheritance
_CXX_WARNINGS =-Woverloaded-virtual

_CXX_WARNINGS+=$_CXX_WARNINGS_CLANG

_C_FLAGS_ARCH=
when ($ARCH_I386 == "yes") {
    _C_FLAGS_ARCH=-m32
}
when ($ARCH_X86_64 == "yes") {
    _C_FLAGS_ARCH=-m64
}

_C_FLAGS_FAST_DEBUG=
when ($_BUILD_FAST_DEBUG == "yes") {
    _C_FLAGS_FAST_DEBUG=-Og
}

_C_DEFINES_NDEBUG=-UNDEBUG
when ($_BUILD_WITH_NDEBUG == "yes") {
    _C_DEFINES_NDEBUG=-DNDEBUG
}

_C_FLAGS_PROFILER=
when ($_BUILD_PROFILER_TYPE == "gprof") {
    _C_FLAGS_PROFILER=-pg
}

_C_FLAGS=\
$CL_DEBUG_INFO $CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__ $_C_FLAGS_ARCH_OPT -pipe
_C_FLAGS+=$_C_FLAGS_ARCH
_C_FLAGS+=$_C_FLAGS_FAST_DEBUG
_C_FLAGS+=$_C_FLAGS_RELEASE
_C_FLAGS+=$_C_FLAGS_PROFILER

_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") {
    _CROSS_SUFFIX=
}

C_COMPILER=${quo:C_COMPILER_UNQUOTED}
OPTIMIZE=$_OPTIMIZE_RELEASE
FSTACK=-fstack-protector
DUMP_DEPS=
GCC_PREPROCESSOR_OPTS=$DUMP_DEPS $C_DEFINES
C_WARNING_OPTS=$_C_WARNINGS
CXX_WARNING_OPTS=$_CXX_WARNINGS

# 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
}

CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
CXXFLAGS+=$CFLAGS $_CXX_STD $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
CXX_COMPILER=${quo:CXX_COMPILER_UNQUOTED}
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
}
# 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 ($NO_COMPILER_WARNINGS == "yes") {
    C_WARNING_OPTS = -w
    CXX_WARNING_OPTS = -Wno-everything
}
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
    }
    YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T
}
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
    }
    YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T
}
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
    }
    YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B
}

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=${output;noauto;hide;suf=${OBJECT_SUF}.gcno:SRC}
CLANG_TIDY_OUTPUT_FILE=${output;noauto;suf=${OBJECT_SUF}.tidyjson:SRC}
YNDEXER_OUTPUT_FILE=${output;noauto;suf=${OBJECT_SUF}.ydx.pb2:SRC}

when ($DUMP_COMPILER_DEPS == "yes") {
    DUMP_DEPS=-MD ${output;hide;noauto;suf=${OBJ_SUF}.o.d:SRC}
}
elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
    DUMP_DEPS=-E -M -MF ${output;noauto;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") && $CLANG == "yes" && $_TC_VERSION_AT_LEAST_9 == "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"}
_CPP_ARGS=\
    $CLANG_TIDY_ARGS \
    $YNDEXER_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 \
    $SRCFLAGS \
    $_LANG_CFLAGS_VALUE \
    ${input:SRC} \
    $TOOLCHAIN_ENV \
    $YNDEXER_OUTPUT \
    && $_COMPILER_TIME_TRACE_POSTPROCESS \
    $_C_CPP_KV_STYLE

_C_ARGS=\
    $CLANG_TIDY_ARGS \
    $YNDEXER_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

### _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

_SRC_CPP_CMD=$_CPP_ARGS
_SRC_C_CMD=$_C_ARGS
_SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
_SRC_MASM_CMD=$_EMPTY_CMD

# fuzzing configuration
when ($CLANG == "yes") {
    when ($_TC_VERSION_AT_LEAST_12 == "yes") {
        LIBFUZZER_PATH=contrib/libs/libfuzzer12
    }
}