gnu_compiler.conf 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. _C_DEFINES_ANDROID=
  2. _C_DEFINES_ANDROID_OTHERWISE=
  3. when ($OS_ANDROID == "yes") {
  4. _C_DEFINES_ANDROID=-DANDROID_FAKEID=$ANDROID_FAKEID
  5. }
  6. otherwise {
  7. # There is no usable _FILE_OFFSET_BITS=64 support in Androids until API 21. And it's incomplete until at least API 24.
  8. # https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
  9. # Arcadia have API 16 for 32-bit Androids.
  10. _C_DEFINES_ANDROID_OTHERWISE=-D_FILE_OFFSET_BITS=64
  11. }
  12. _C_DEFINES_GNU_SOURCE=
  13. when ($OS_LINUX == "yes" || $OS_ANDROID == "yes" || $OS_CYGWIN == "yes") {
  14. _C_DEFINES_GNU_SOURCE=-D_GNU_SOURCE
  15. }
  16. _C_DEFINES_CLANG_LINUX_X86_64=
  17. when ($CLANG == "yes" && $OS_LINUX == "yes" && $ARCH_X86_64 == "yes") {
  18. _C_DEFINES_CLANG_LINUX_X86_64=-D_YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE
  19. }
  20. _C_DEFINES_IOS=
  21. when ($OS_IOS == "yes") {
  22. _C_DEFINES_IOS=-D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
  23. }
  24. _C_DEFINES_WITH_VALGRIND=
  25. when ($WITH_VALGRIND == "yes") {
  26. _C_DEFINES_WITH_VALGRIND=-DWITH_VALGRIND=1
  27. }
  28. C_DEFINES =-DFAKEID=$CPP_FAKEID
  29. C_DEFINES+=$_C_DEFINES_ANDROID
  30. C_DEFINES+=\
  31. -DARCADIA_ROOT=${ARCADIA_ROOT} \
  32. -DARCADIA_BUILD_ROOT=${ARCADIA_BUILD_ROOT} \
  33. -D_THREAD_SAFE \
  34. -D_PTHREADS \
  35. -D_REENTRANT \
  36. -D_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES \
  37. -D_LARGEFILE_SOURCE \
  38. -D__STDC_CONSTANT_MACROS \
  39. -D__STDC_FORMAT_MACROS
  40. C_DEFINES+=$_C_DEFINES_ANDROID_OTHERWISE
  41. C_DEFINES+=$_C_DEFINES_GNU_SOURCE
  42. C_DEFINES+=$_C_DEFINES_CLANG_LINUX_X86_64
  43. C_DEFINES+=$_C_DEFINES_IOS
  44. C_DEFINES+=$_C_DEFINES_WITH_VALGRIND
  45. C_DEFINES+=$_C_DEFINES_NDEBUG
  46. _C_FOPTIONS_INIT_ARRAY=
  47. when ($CLANG == "yes" && $OS_LINUX == "yes") {
  48. # Use .init_array instead of .ctors (default for old clang versions)
  49. # See: https://maskray.me/blog/2021-11-07-init-ctors-init-array
  50. _C_FOPTIONS_INIT_ARRAY=-fuse-init-array
  51. }
  52. _C_FOPTIONS_COLOR=
  53. _C_FOPTIONS_ALIGNED_ALLOCATION=
  54. when ($CLANG == "yes") {
  55. # Set up output colorization
  56. _C_FOPTIONS_COLOR=-fcolor-diagnostics
  57. # Enable aligned allocation
  58. _C_FOPTIONS_ALIGNED_ALLOCATION=-faligned-allocation
  59. }
  60. elsewhen ($GCC == "yes") {
  61. # Set up output colorization
  62. _C_FOPTIONS_COLOR=-fdiagnostics-color=always
  63. # It looks like there is no way to enable aligned allocation in gcc
  64. }
  65. _C_FOPTIONS_MAPSMOBI_ARM=
  66. when ($OS_IOS == "yes") {
  67. when ($MAPSMOBI_BUILD_TARGET == "yes" && $ARCH_ARM == "yes") {
  68. _C_FOPTIONS_MAPSMOBI_ARM=-fembed-bitcode
  69. }
  70. }
  71. _C_WARNINGS_CLANG=
  72. _CXX_WARNINGS_CLANG=
  73. when ($CLANG == "yes") {
  74. _CXX_WARNINGS_CLANG=\
  75. -Wimport-preprocessor-directive-pedantic \
  76. -Wno-ambiguous-reversed-operator \
  77. -Wno-defaulted-function-deleted \
  78. -Wno-deprecated-anon-enum-enum-conversion \
  79. -Wno-deprecated-enum-enum-conversion \
  80. -Wno-deprecated-enum-float-conversion \
  81. -Wno-deprecated-volatile \
  82. -Wno-pessimizing-move \
  83. -Wno-range-loop-construct \
  84. -Wno-return-std-move \
  85. -Wno-undefined-var-template
  86. # -Wno-unknown-warning-option
  87. # For nvcc to accept the above.
  88. _C_WARNINGS_CLANG=\
  89. -Wno-implicit-const-int-float-conversion \
  90. -Wno-unknown-warning-option
  91. }
  92. _C_FOPTIONS_GCC=
  93. when ($GCC == "yes") {
  94. _C_FOPTIONS_GCC=-fno-delete-null-pointer-checks -fabi-version=8
  95. }
  96. _C_FOPTIONS_IOS=
  97. when ($OS_IOS != "yes") {
  98. # Split all functions and data into separate sections for DCE and ICF linker passes
  99. # NOTE: iOS build uses -fembed-bitcode which conflicts with -ffunction-sections (only relevant for ELF targets)
  100. _C_FOPTIONS_IOS=-ffunction-sections -fdata-sections
  101. }
  102. _C_FOPTIONS_DEBUG=
  103. when ($_BUILD_DEBUG == "yes") {
  104. _C_FOPTIONS_DEBUG=$FSTACK
  105. }
  106. _C_FLAGS_RELEASE=
  107. _C_FOPTIONS_RELEASE=
  108. _OPTIMIZE_RELEASE=
  109. when ($_BUILD_RELEASE == "yes") {
  110. _C_FLAGS_RELEASE=$OPTIMIZE
  111. when ($_BUILD_SIZE_OPTIMIZED == "yes") {
  112. # -Oz is clang's more size-aggressive version of -Os
  113. # For ARM specifically, clang -Oz is on par with gcc -Os:
  114. # https://github.com/android/ndk/issues/133#issuecomment-365763507
  115. when($CLANG == "yes") {
  116. _OPTIMIZE_RELEASE=-Oz
  117. }
  118. otherwise {
  119. _OPTIMIZE_RELEASE=-Os
  120. }
  121. # Generate sections with address significance tables for ICF linker pass
  122. when($CLANG == "yes") {
  123. _C_FOPTIONS_RELEASE=-faddrsig
  124. }
  125. }
  126. otherwise {
  127. _OPTIMIZE_RELEASE=-O3
  128. }
  129. }
  130. _C_FOPTIONS_PROFILER=
  131. when ($_BUILD_PROFILER_TYPE != "") {
  132. when ($_BUILD_PROFILER_TYPE in ["generic", "gprof"]) {
  133. _C_FOPTIONS_PROFILER=-fno-omit-frame-pointer
  134. }
  135. }
  136. _C_FOPTIONS =
  137. # Enable C++ exceptions (and allow them to be throw through pure C code)
  138. _C_FOPTIONS+=-fexceptions
  139. # Enable standard-conforming behavior and generate duplicate symbol error in case of duplicated global constants.
  140. # See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85678#c0
  141. _C_FOPTIONS+=-fno-common
  142. _C_FOPTIONS+=$_C_FOPTIONS_INIT_ARRAY
  143. _C_FOPTIONS+=$_C_FOPTIONS_COLOR
  144. _C_FOPTIONS+=$_C_FOPTIONS_ALIGNED_ALLOCATION
  145. _C_FOPTIONS+=$_C_FOPTIONS_MAPSMOBI_ARM
  146. _C_FOPTIONS+=$_C_FOPTIONS_DEBUG
  147. _C_FOPTIONS+=$_C_FOPTIONS_RELEASE
  148. _C_FOPTIONS+=$_C_FOPTIONS_PROFILER
  149. _C_FOPTIONS+=$_C_FOPTIONS_GCC
  150. _C_FOPTIONS+=$_C_FOPTIONS_IOS
  151. # Enable default warnings subset
  152. _C_WARNINGS =-Wall -Wextra
  153. # Disable some warnings which will fail compilation at the time
  154. _C_WARNINGS+=-Wno-parentheses
  155. _C_WARNINGS+=$_C_WARNINGS_CLANG
  156. # Issue a warning if certain overload is hidden due to inheritance
  157. _CXX_WARNINGS =-Woverloaded-virtual
  158. _CXX_WARNINGS+=$_CXX_WARNINGS_CLANG
  159. _C_FLAGS_ARCH=
  160. when ($ARCH_I386 == "yes") {
  161. _C_FLAGS_ARCH=-m32
  162. }
  163. when ($ARCH_X86_64 == "yes") {
  164. _C_FLAGS_ARCH=-m64
  165. }
  166. _C_FLAGS_FAST_DEBUG=
  167. when ($_BUILD_FAST_DEBUG == "yes") {
  168. _C_FLAGS_FAST_DEBUG=-Og
  169. }
  170. _C_DEFINES_NDEBUG=-UNDEBUG
  171. when ($_BUILD_WITH_NDEBUG == "yes") {
  172. _C_DEFINES_NDEBUG=-DNDEBUG
  173. }
  174. _C_FLAGS_PROFILER=
  175. when ($_BUILD_PROFILER_TYPE == "gprof") {
  176. _C_FLAGS_PROFILER=-pg
  177. }
  178. _C_FLAGS=\
  179. $CL_DEBUG_INFO $CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__ $_C_FLAGS_ARCH_OPT -pipe
  180. _C_FLAGS+=$_C_FLAGS_ARCH
  181. _C_FLAGS+=$_C_FLAGS_FAST_DEBUG
  182. _C_FLAGS+=$_C_FLAGS_RELEASE
  183. _C_FLAGS+=$_C_FLAGS_PROFILER
  184. _SFDL_FLAGS=-E -C -x c++
  185. when ($CLANG == "yes") {
  186. _SFDL_FLAGS+=-Qunused-arguments
  187. }
  188. _DEBUG_INFO_FLAGS=-g
  189. when ($OS_LINUX == "yes") {
  190. _DEBUG_INFO_FLAGS=-g -ggnu-pubnames
  191. }
  192. _CROSS_SUFFIX=.pic
  193. when ($FORCE_NO_PIC == "yes") {
  194. _CROSS_SUFFIX=
  195. }
  196. C_COMPILER=${quo:C_COMPILER_UNQUOTED}
  197. OPTIMIZE=$_OPTIMIZE_RELEASE
  198. FSTACK=-fstack-protector
  199. DUMP_DEPS=
  200. GCC_PREPROCESSOR_OPTS=$DUMP_DEPS $C_DEFINES
  201. C_WARNING_OPTS=$_C_WARNINGS
  202. CXX_WARNING_OPTS=$_CXX_WARNINGS
  203. # PIE is only valid for executables, while PIC implies a shared library
  204. # `-pie` with a shared library is either ignored or fails to link
  205. when ($PIC == "yes") {
  206. CFLAGS+=-fPIC
  207. LDFLAGS+=-fPIC
  208. }
  209. elsewhen ($PIE == "yes") {
  210. CFLAGS+=-fPIE
  211. LDFLAGS+=-fPIE -pie
  212. }
  213. CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
  214. CXXFLAGS+=$CFLAGS $_CXX_STD $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
  215. CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
  216. CXX_COMPILER=${quo:CXX_COMPILER_UNQUOTED}
  217. NOGCCSTACKCHECK=yes
  218. SFDL_FLAG=$_SFDL_FLAGS -o $SFDL_TMP_OUT
  219. WERROR_FLAG=-Werror
  220. DEBUG_INFO_FLAGS=$_DEBUG_INFO_FLAGS
  221. when ($NO_WSHADOW == "yes") {
  222. C_WARNING_OPTS += -Wno-shadow
  223. }
  224. # Though -w is intended to switch off all the warnings,
  225. # it does not switch at least -Wregister and -Wreserved-user-defined-literal under clang.
  226. #
  227. # Use -Wno-everything to force warning suppression.
  228. when ($NO_COMPILER_WARNINGS == "yes") {
  229. C_WARNING_OPTS = -w
  230. CXX_WARNING_OPTS = -Wno-everything
  231. }
  232. when ($NO_OPTIMIZE == "yes") {
  233. OPTIMIZE = -O0
  234. }
  235. when ($SAVE_TEMPS == "yes") {
  236. CXXFLAGS += -save-temps
  237. }
  238. when ($NOGCCSTACKCHECK != "yes") {
  239. FSTACK += -fstack-check
  240. }
  241. when ($FORCE_CONSISTENT_DEBUG == "yes") {
  242. when ($CLANG == "yes") {
  243. 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
  244. }
  245. otherwise {
  246. CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
  247. }
  248. YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T
  249. }
  250. elsewhen ($CONSISTENT_DEBUG == "yes") {
  251. when ($CLANG == "yes") {
  252. 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
  253. }
  254. otherwise {
  255. 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
  256. }
  257. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T
  258. }
  259. elsewhen ($CONSISTENT_DEBUG_LIGHT == "yes") {
  260. when ($CLANG == "yes") {
  261. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -Xclang -fdebug-compilation-dir -Xclang /tmp
  262. }
  263. otherwise {
  264. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B
  265. }
  266. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B
  267. }
  268. when ($FORCE_CONSISTENT_BUILD == "yes") {
  269. 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)/=
  270. }
  271. elsewhen ($CONSISTENT_BUILD == "yes") {
  272. 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)/=
  273. }
  274. _CFLAGS_ARCH_I386=
  275. when ($ARCH_I386 == "yes" && $ARCH_I686 != "yes") {
  276. _CFLAGS_ARCH_I386=-march=pentiumpro -mtune=pentiumpro
  277. }
  278. CFLAGS+=$_CFLAGS_ARCH_I386
  279. BC_CFLAGS+=$CFLAGS
  280. BC_CXXFLAGS+=$CXXFLAGS
  281. C_DEFINES+=-D__LONG_LONG_SUPPORTED
  282. OBJ_CROSS_SUF=$OBJ_SUF$_CROSS_SUFFIX
  283. OBJECT_SUF=$OBJ_SUF$_CROSS_SUFFIX.o
  284. GCC_COMPILE_FLAGS=$EXTRA_C_FLAGS -c -o $_COMPILE_OUTPUTS ${pre=-I:_C__INCLUDE}
  285. EXTRA_COVERAGE_OUTPUT=${output;noauto;hide;suf=${OBJECT_SUF}.gcno:SRC}
  286. CLANG_TIDY_OUTPUT_FILE=${output;noauto;suf=${OBJECT_SUF}.tidyjson:SRC}
  287. YNDEXER_OUTPUT_FILE=${output;noauto;suf=${OBJECT_SUF}${COMPILE_OUT_SUFFIX}.ydx.pb2:SRC}
  288. when ($DUMP_COMPILER_DEPS == "yes") {
  289. DUMP_DEPS=-MD ${output;hide;noauto;suf=${OBJ_SUF}.o.d:SRC}
  290. }
  291. elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
  292. DUMP_DEPS=-E -M -MF ${output;noauto;suf=${OBJ_SUF}.o.d:SRC}
  293. }
  294. _COMPILER_TIME_TRACE_GRANULARITY=500
  295. when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
  296. _COMPILER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
  297. }
  298. _COMPILER_TIME_TRACE_FLAGS=
  299. _COMPILER_TIME_TRACE_POSTPROCESS=
  300. when (($TIME_TRACE == "yes" || $COMPILER_TIME_TRACE == "yes") && $CLANG == "yes" && $_TC_VERSION_AT_LEAST_9 == "yes") {
  301. _COMPILER_TIME_TRACE_FLAGS=-ftime-trace -ftime-trace-granularity=$_COMPILER_TIME_TRACE_GRANULARITY
  302. _COMPILER_TIME_TRACE_POSTPROCESS=$YMAKE_PYTHON ${input:"build/scripts/find_time_trace.py"} $_COMPILE_OUTPUTS $_COMPILE_TIME_TRACE_OUTPUTS
  303. }
  304. _C_CPP_KV_STYLE=${hide;kv:"p CC"} ${hide;kv:"pc green"}
  305. _CPP_ARGS=\
  306. $CLANG_TIDY_ARGS \
  307. $YNDEXER_ARGS \
  308. $CXX_COMPILER \
  309. $C_FLAGS_PLATFORM \
  310. $GCC_COMPILE_FLAGS \
  311. $CXXFLAGS \
  312. $CL_MACRO_INFO \
  313. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  314. $_COMPILER_TIME_TRACE_FLAGS \
  315. $EXTRA_OUTPUT \
  316. $SRCFLAGS \
  317. $_LANG_CFLAGS_VALUE \
  318. ${input:SRC} \
  319. $TOOLCHAIN_ENV \
  320. $YNDEXER_OUTPUT \
  321. && $_COMPILER_TIME_TRACE_POSTPROCESS \
  322. $_C_CPP_KV_STYLE
  323. _C_ARGS=\
  324. $CLANG_TIDY_ARGS \
  325. $YNDEXER_ARGS \
  326. $C_COMPILER \
  327. $C_FLAGS_PLATFORM \
  328. $GCC_COMPILE_FLAGS \
  329. $CFLAGS \
  330. $CL_MACRO_INFO \
  331. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  332. $_COMPILER_TIME_TRACE_FLAGS \
  333. $CONLYFLAGS \
  334. $EXTRA_OUTPUT \
  335. $SRCFLAGS \
  336. ${input:SRC} \
  337. $TOOLCHAIN_ENV \
  338. $YNDEXER_OUTPUT \
  339. $_C_CPP_KV_STYLE
  340. ### _SRC_C_NODEPS_CMD is obtained from _C_ARGS by filtering the following elements:
  341. ### ${input:SRC}
  342. ### $CL_MACRO_INFO
  343. ### $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__
  344. ### $CLANG_TIDY_ARGS
  345. ### $EXTRA_OUTPUT
  346. ### $EXTRA_COVERAGE_OUTPUT
  347. ### $SRCFLAGS
  348. ### $YNDEXER_ARGS
  349. ### $YNDEXER_OUTPUT
  350. ###
  351. ### $GCC_COMPILE_FLAGS is substituted for $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC}
  352. _SRC_C_NODEPS_CMD=\
  353. $C_COMPILER \
  354. $C_FLAGS_PLATFORM \
  355. $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC} \
  356. $CFLAGS \
  357. $CONLYFLAGS \
  358. $TOOLCHAIN_ENV \
  359. $_C_CPP_KV_STYLE
  360. _SRC_CPP_CMD=$_CPP_ARGS
  361. _SRC_C_CMD=$_C_ARGS
  362. _SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
  363. _SRC_MASM_CMD=$_EMPTY_CMD
  364. # fuzzing configuration
  365. when ($CLANG == "yes") {
  366. when ($_TC_VERSION_AT_LEAST_12 == "yes") {
  367. LIBFUZZER_PATH=contrib/libs/libfuzzer12
  368. }
  369. }