gnu_compiler.conf 8.9 KB

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