gnu_compiler.conf 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. _STD_CXX=-std=$_STD_CXX_VERSION
  2. _OPTIMIZE_RELEASE=
  3. when ($_BUILD_RELEASE == "yes") {
  4. when ($_BUILD_SIZE_OPTIMIZED == "yes") {
  5. # -Oz is clang's more size-aggressive version of -Os
  6. # For ARM specifically, clang -Oz is on par with gcc -Os:
  7. # https://github.com/android/ndk/issues/133#issuecomment-365763507
  8. when($CLANG == "yes") {
  9. _OPTIMIZE_RELEASE=-Oz
  10. }
  11. otherwise {
  12. _OPTIMIZE_RELEASE=-Os
  13. }
  14. }
  15. otherwise {
  16. _OPTIMIZE_RELEASE=-O3
  17. }
  18. }
  19. _SFDL_FLAGS=-E -C -x c++
  20. when ($CLANG == "yes") {
  21. _SFDL_FLAGS+=-Qunused-arguments
  22. }
  23. _DEBUG_INFO_FLAGS=-g
  24. when ($OS_LINUX == "yes") {
  25. _DEBUG_INFO_FLAGS=-g -ggnu-pubnames
  26. # Clang's more accurate debug info for sampling-PGO purposes. PGO only makes sense in release builds
  27. when ($CLANG == "yes" && $_BUILD_RELEASE == "yes") {
  28. _DEBUG_INFO_FLAGS+=-fdebug-info-for-profiling
  29. }
  30. }
  31. _CROSS_SUFFIX=.pic
  32. when ($FORCE_NO_PIC == "yes") {
  33. when ($TOOL_BUILD_MODE == "yes" && $PIC == "yes") {
  34. # FIXME(spreis): This is temporary fix until more appropriate control over pic-like-in-tools mode will come
  35. }
  36. otherwise {
  37. _CROSS_SUFFIX=
  38. }
  39. }
  40. OPTIMIZE=$_OPTIMIZE_RELEASE
  41. FSTACK=-fstack-protector
  42. DUMP_DEPS=
  43. GCC_PREPROCESSOR_OPTS=$DUMP_DEPS $C_DEFINES
  44. # PIE is only valid for executables, while PIC implies a shared library
  45. # `-pie` with a shared library is either ignored or fails to link
  46. when ($PIC == "yes") {
  47. CFLAGS+=-fPIC
  48. LDFLAGS+=-fPIC
  49. }
  50. elsewhen ($PIE == "yes") {
  51. CFLAGS+=-fPIE
  52. LDFLAGS+=-fPIE -pie
  53. }
  54. when ($CLANG == "yes" && $ARCH_AARCH64 == "yes") {
  55. # Clang generates outline atomics if libgcc version is >= 9.3.1
  56. # See https://github.com/llvm/llvm-project/commit/c5e7e649d537067dec7111f3de1430d0fc8a4d11
  57. CFLAGS+=-mno-outline-atomics
  58. }
  59. when ($CLANG16 == "yes") {
  60. 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
  61. }
  62. when ($CLANG18 == "yes") {
  63. 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
  64. CFLAGS+=-Wno-deprecated-this-capture -Wno-c++11-narrowing-const-reference -Wno-missing-field-initializers \
  65. -Wno-packed-non-pod -Wno-format -Wno-vla-cxx-extension -Wno-invalid-offsetof -Wno-exceptions \
  66. -Wno-include-angled-in-module-purview -Wno-unused-parameter
  67. when ($MAPSMOBI_BUILD_TARGET == "yes") {
  68. CFLAGS+=-Wno-deprecated-declarations
  69. }
  70. }
  71. when ($MSAN_TRACK_ORIGIN == "yes") {
  72. CFLAGS+=-fsanitize-memory-track-origins=2
  73. }
  74. when ($ARCH_XTENSA == "yes") {
  75. FSTACK=
  76. }
  77. when ($OS_EMSCRIPTEN == "yes") {
  78. FSTACK=-fno-stack-protector
  79. CFLAGS+=-D__EMSCRIPTEN__
  80. }
  81. when ($ARCH_WASM64 == "yes") {
  82. CFLAGS+=-D_LIBCPP_HAS_MUSL_LIBC
  83. }
  84. when ($ARCH_WASM32 == "yes") {
  85. CFLAGS+=-D_musl_
  86. }
  87. CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
  88. CXXFLAGS+=$CFLAGS $_STD_CXX $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
  89. CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
  90. NOGCCSTACKCHECK=yes
  91. SFDL_FLAG=$_SFDL_FLAGS -o $SFDL_TMP_OUT
  92. WERROR_FLAG=-Werror
  93. DEBUG_INFO_FLAGS=$_DEBUG_INFO_FLAGS
  94. when ($NO_WSHADOW == "yes") {
  95. C_WARNING_OPTS += -Wno-shadow
  96. }
  97. when ($NO_COMPILER_WARNINGS == "yes") {
  98. # Though -w is intended to switch off all the warnings,
  99. # it does not switch at least -Wregister and -Wreserved-user-defined-literal under clang.
  100. #
  101. # Use -Wno-everything to force warning suppression.
  102. when ($CLANG == "yes") {
  103. C_WARNING_OPTS = -Wno-everything
  104. CXX_WARNING_OPTS = -Wno-everything
  105. }
  106. # On gcc -Wno-everything is not supported, so we use -w
  107. # see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  108. elsewhen ($GCC == "yes") {
  109. C_WARNING_OPTS = -w
  110. CXX_WARNING_OPTS = -w
  111. }
  112. }
  113. when ($NO_OPTIMIZE == "yes") {
  114. OPTIMIZE = -O0
  115. }
  116. when ($SAVE_TEMPS == "yes") {
  117. CXXFLAGS += -save-temps
  118. }
  119. when ($NOGCCSTACKCHECK != "yes") {
  120. FSTACK += -fstack-check
  121. }
  122. when ($FORCE_CONSISTENT_DEBUG == "yes") {
  123. when ($CLANG == "yes") {
  124. 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
  125. }
  126. otherwise {
  127. CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
  128. when ($ARCH_XTENSA == "yes") {
  129. CL_DEBUG_INFO=
  130. }
  131. }
  132. YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
  133. }
  134. elsewhen ($CONSISTENT_DEBUG == "yes") {
  135. when ($CLANG == "yes") {
  136. 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
  137. }
  138. otherwise {
  139. 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
  140. when ($ARCH_XTENSA == "yes") {
  141. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  142. }
  143. }
  144. 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"}
  145. }
  146. elsewhen ($CONSISTENT_DEBUG_LIGHT == "yes") {
  147. when ($CLANG == "yes") {
  148. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -Xclang -fdebug-compilation-dir -Xclang /tmp
  149. }
  150. otherwise {
  151. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B
  152. when ($ARCH_XTENSA == "yes") {
  153. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  154. }
  155. }
  156. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B ${env:"YASM_TEST_SUITE=1"}
  157. }
  158. when ($FORCE_CONSISTENT_BUILD == "yes") {
  159. 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)/=
  160. }
  161. elsewhen ($CONSISTENT_BUILD == "yes") {
  162. 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)/=
  163. }
  164. _CFLAGS_ARCH_I386=
  165. when ($ARCH_I386 == "yes" && $ARCH_I686 != "yes") {
  166. _CFLAGS_ARCH_I386=-march=pentiumpro -mtune=pentiumpro
  167. }
  168. CFLAGS+=$_CFLAGS_ARCH_I386
  169. BC_CFLAGS+=$CFLAGS
  170. BC_CXXFLAGS+=$CXXFLAGS
  171. C_DEFINES+=-D__LONG_LONG_SUPPORTED
  172. OBJ_CROSS_SUF=$OBJ_SUF$_CROSS_SUFFIX
  173. OBJECT_SUF=$OBJ_SUF$_CROSS_SUFFIX.o
  174. GCC_COMPILE_FLAGS=$EXTRA_C_FLAGS -c -o $_COMPILE_OUTPUTS ${pre=-I:_C__INCLUDE}
  175. EXTRA_COVERAGE_OUTPUT=${hide;noauto;output;suf=${OBJECT_SUF}.gcno:SRC}
  176. CLANG_TIDY_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}.tidyjson:SRC}
  177. YNDEXER_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}${COMPILE_OUT_SUFFIX}.ydx.pb2:SRC}
  178. when ($DUMP_COMPILER_DEPS == "yes") {
  179. DUMP_DEPS=-MD ${hide;noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  180. }
  181. elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
  182. DUMP_DEPS=-E -M -MF ${noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  183. }
  184. _COMPILER_TIME_TRACE_GRANULARITY=500
  185. when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
  186. _COMPILER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
  187. }
  188. _COMPILER_TIME_TRACE_FLAGS=
  189. _COMPILER_TIME_TRACE_POSTPROCESS=
  190. when (($TIME_TRACE == "yes" || $COMPILER_TIME_TRACE == "yes") && $_HAS_TIME_TRACE == "yes") {
  191. _COMPILER_TIME_TRACE_FLAGS=-ftime-trace -ftime-trace-granularity=$_COMPILER_TIME_TRACE_GRANULARITY
  192. _COMPILER_TIME_TRACE_POSTPROCESS=$YMAKE_PYTHON ${input:"build/scripts/find_time_trace.py"} $_COMPILE_OUTPUTS $_COMPILE_TIME_TRACE_OUTPUTS
  193. }
  194. _C_CPP_KV_STYLE=${hide;kv:"p CC"} ${hide;kv:"pc green"}
  195. _C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC}
  196. _C_CPP_KV_STYLE_P=p CC
  197. _C_CPP_KV_STYLE_PC=pc green
  198. _C_CPP_WRAPPER=$YMAKE_PYTHON3 ${input:"build/scripts/wrapcc.py"} ${input:SRC}
  199. when ($CLANG_TIDY_ARGS || $RETRY_ARGS || $YNDEXER_ARGS || $OPENSOURCE == "yes" || $RAW_COMPILE_CPP_CMD == "yes" ) {
  200. _C_CPP_WRAPPER=
  201. }
  202. _CPP_ARGS_NEW=\
  203. $CLANG_STATIC_ANALYZER_OPTIONS_NEW && \
  204. $CLANG_TIDY_ARGS \
  205. $YNDEXER_ARGS \
  206. $RETRY_ARGS \
  207. $_C_CPP_WRAPPER \
  208. $CXX_COMPILER \
  209. $C_FLAGS_PLATFORM \
  210. $GCC_COMPILE_FLAGS \
  211. $CXXFLAGS \
  212. $CL_MACRO_INFO \
  213. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  214. $_COMPILER_TIME_TRACE_FLAGS \
  215. $EXTRA_OUTPUT \
  216. $SRCFLAGS \
  217. $_LANG_CFLAGS_VALUE_NEW \
  218. ${input:SRC} \
  219. $TOOLCHAIN_ENV \
  220. $YNDEXER_OUTPUT \
  221. && $_COMPILER_TIME_TRACE_POSTPROCESS \
  222. $_C_CPP_KV_STYLE_NEW
  223. _C_ARGS_NEW=\
  224. $CLANG_TIDY_ARGS \
  225. $YNDEXER_ARGS \
  226. $RETRY_ARGS \
  227. $_C_CPP_WRAPPER \
  228. $C_COMPILER \
  229. $C_FLAGS_PLATFORM \
  230. $GCC_COMPILE_FLAGS \
  231. $CFLAGS \
  232. $CL_MACRO_INFO \
  233. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  234. $_COMPILER_TIME_TRACE_FLAGS \
  235. $CONLYFLAGS \
  236. $EXTRA_OUTPUT \
  237. $SRCFLAGS \
  238. ${input:SRC} \
  239. $TOOLCHAIN_ENV \
  240. $YNDEXER_OUTPUT \
  241. $_C_CPP_KV_STYLE_NEW \
  242. $SCU_NAME_KV_NEW
  243. ### _SRC_C_NODEPS_CMD is obtained from _C_ARGS by filtering the following elements:
  244. ### ${input:SRC}
  245. ### $CL_MACRO_INFO
  246. ### $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__
  247. ### $CLANG_TIDY_ARGS
  248. ### $EXTRA_OUTPUT
  249. ### $EXTRA_COVERAGE_OUTPUT
  250. ### $SRCFLAGS
  251. ### $YNDEXER_ARGS
  252. ### $YNDEXER_OUTPUT
  253. ###
  254. ### $GCC_COMPILE_FLAGS is substituted for $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC}
  255. _SRC_C_NODEPS_CMD=\
  256. $C_COMPILER \
  257. $C_FLAGS_PLATFORM \
  258. $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC} \
  259. $CFLAGS \
  260. $CONLYFLAGS \
  261. $TOOLCHAIN_ENV \
  262. $_C_CPP_KV_STYLE
  263. _FORCE_CPP_FLAGS=-x c++
  264. _SRC_CPP_CMD_NEW=$_CPP_ARGS_NEW
  265. _SRC_C_CMD_NEW=$_C_ARGS_NEW
  266. _SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
  267. _SRC_MASM_CMD=$_EMPTY_CMD