gnu_compiler.conf 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. }
  68. when ($ARCH_WASM64 == "yes") {
  69. CFLAGS+=-D_LIBCPP_HAS_MUSL_LIBC
  70. }
  71. when ($ARCH_WASM32 == "yes") {
  72. CFLAGS+=-D_musl_
  73. }
  74. CFLAGS+=$_C_FLAGS $DEBUG_INFO_FLAGS $_C_FOPTIONS $C_WARNING_OPTS $GCC_PREPROCESSOR_OPTS $USER_CFLAGS $USER_CFLAGS_GLOBAL
  75. CXXFLAGS+=$CFLAGS $_STD_CXX $CXX_WARNING_OPTS $USER_CXXFLAGS $USER_CXXFLAGS_GLOBAL
  76. CONLYFLAGS+=$USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL
  77. NOGCCSTACKCHECK=yes
  78. SFDL_FLAG=$_SFDL_FLAGS -o $SFDL_TMP_OUT
  79. WERROR_FLAG=-Werror
  80. DEBUG_INFO_FLAGS=$_DEBUG_INFO_FLAGS
  81. when ($NO_WSHADOW == "yes") {
  82. C_WARNING_OPTS += -Wno-shadow
  83. }
  84. when ($NO_COMPILER_WARNINGS == "yes") {
  85. # Though -w is intended to switch off all the warnings,
  86. # it does not switch at least -Wregister and -Wreserved-user-defined-literal under clang.
  87. #
  88. # Use -Wno-everything to force warning suppression.
  89. when ($CLANG == "yes") {
  90. C_WARNING_OPTS = -Wno-everything
  91. CXX_WARNING_OPTS = -Wno-everything
  92. }
  93. # On gcc -Wno-everything is not supported, so we use -w
  94. # see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  95. elsewhen ($GCC == "yes") {
  96. C_WARNING_OPTS = -w
  97. CXX_WARNING_OPTS = -w
  98. }
  99. }
  100. when ($NO_OPTIMIZE == "yes") {
  101. OPTIMIZE = -O0
  102. }
  103. when ($SAVE_TEMPS == "yes") {
  104. CXXFLAGS += -save-temps
  105. }
  106. when ($NOGCCSTACKCHECK != "yes") {
  107. FSTACK += -fstack-check
  108. }
  109. when ($FORCE_CONSISTENT_DEBUG == "yes") {
  110. when ($CLANG == "yes") {
  111. 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
  112. }
  113. otherwise {
  114. CL_DEBUG_INFO=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -fdebug-prefix-map=${ARCADIA_ROOT}=/-S -fdebug-prefix-map=$(TOOL_ROOT)=/-T
  115. when ($ARCH_XTENSA == "yes") {
  116. CL_DEBUG_INFO=
  117. }
  118. }
  119. YASM_DEBUG_INFO=--replace=${ARCADIA_BUILD_ROOT}=/-B --replace=${ARCADIA_ROOT}=/-S --replace=$(TOOL_ROOT)=/-T ${env:"YASM_TEST_SUITE=1"}
  120. }
  121. elsewhen ($CONSISTENT_DEBUG == "yes") {
  122. when ($CLANG == "yes") {
  123. 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
  124. }
  125. otherwise {
  126. 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
  127. when ($ARCH_XTENSA == "yes") {
  128. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  129. }
  130. }
  131. 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"}
  132. }
  133. elsewhen ($CONSISTENT_DEBUG_LIGHT == "yes") {
  134. when ($CLANG == "yes") {
  135. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B -Xclang -fdebug-compilation-dir -Xclang /tmp
  136. }
  137. otherwise {
  138. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=-fdebug-prefix-map=${ARCADIA_BUILD_ROOT}=/-B
  139. when ($ARCH_XTENSA == "yes") {
  140. CL_DEBUG_INFO_DISABLE_CACHE__NO_UID__=
  141. }
  142. }
  143. YASM_DEBUG_INFO_DISABLE_CACHE__NO_UID__=--replace=${ARCADIA_BUILD_ROOT}=/-B ${env:"YASM_TEST_SUITE=1"}
  144. }
  145. when ($FORCE_CONSISTENT_BUILD == "yes") {
  146. 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)/=
  147. }
  148. elsewhen ($CONSISTENT_BUILD == "yes") {
  149. 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)/=
  150. }
  151. _CFLAGS_ARCH_I386=
  152. when ($ARCH_I386 == "yes" && $ARCH_I686 != "yes") {
  153. _CFLAGS_ARCH_I386=-march=pentiumpro -mtune=pentiumpro
  154. }
  155. CFLAGS+=$_CFLAGS_ARCH_I386
  156. BC_CFLAGS+=$CFLAGS
  157. BC_CXXFLAGS+=$CXXFLAGS
  158. C_DEFINES+=-D__LONG_LONG_SUPPORTED
  159. OBJ_CROSS_SUF=$OBJ_SUF$_CROSS_SUFFIX
  160. OBJECT_SUF=$OBJ_SUF$_CROSS_SUFFIX.o
  161. GCC_COMPILE_FLAGS=$EXTRA_C_FLAGS -c -o $_COMPILE_OUTPUTS ${pre=-I:_C__INCLUDE}
  162. EXTRA_COVERAGE_OUTPUT=${hide;noauto;output;suf=${OBJECT_SUF}.gcno:SRC}
  163. CLANG_TIDY_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}.tidyjson:SRC}
  164. YNDEXER_OUTPUT_FILE=${noauto;output;suf=${OBJECT_SUF}${COMPILE_OUT_SUFFIX}.ydx.pb2:SRC}
  165. when ($DUMP_COMPILER_DEPS == "yes") {
  166. DUMP_DEPS=-MD ${hide;noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  167. }
  168. elsewhen ($DUMP_COMPILER_DEPS_FAST == "yes") {
  169. DUMP_DEPS=-E -M -MF ${noauto;output;suf=${OBJ_SUF}.o.d:SRC}
  170. }
  171. _COMPILER_TIME_TRACE_GRANULARITY=500
  172. when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
  173. _COMPILER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
  174. }
  175. _COMPILER_TIME_TRACE_FLAGS=
  176. _COMPILER_TIME_TRACE_POSTPROCESS=
  177. when (($TIME_TRACE == "yes" || $COMPILER_TIME_TRACE == "yes") && $_HAS_TIME_TRACE == "yes") {
  178. _COMPILER_TIME_TRACE_FLAGS=-ftime-trace -ftime-trace-granularity=$_COMPILER_TIME_TRACE_GRANULARITY
  179. _COMPILER_TIME_TRACE_POSTPROCESS=$YMAKE_PYTHON ${input:"build/scripts/find_time_trace.py"} $_COMPILE_OUTPUTS $_COMPILE_TIME_TRACE_OUTPUTS
  180. }
  181. _C_CPP_KV_STYLE=${hide;kv:"p CC"} ${hide;kv:"pc green"}
  182. _C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC}
  183. _C_CPP_KV_STYLE_P=p CC
  184. _C_CPP_KV_STYLE_PC=pc green
  185. _CPP_ARGS_NEW=\
  186. $CLANG_STATIC_ANALYZER_OPTIONS_NEW && \
  187. $CLANG_TIDY_ARGS \
  188. $YNDEXER_ARGS \
  189. $RETRY_ARGS \
  190. $CXX_COMPILER \
  191. $C_FLAGS_PLATFORM \
  192. $GCC_COMPILE_FLAGS \
  193. $CXXFLAGS \
  194. $CL_MACRO_INFO \
  195. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  196. $_COMPILER_TIME_TRACE_FLAGS \
  197. $EXTRA_OUTPUT \
  198. $SRCFLAGS \
  199. $_LANG_CFLAGS_VALUE_NEW \
  200. ${input:SRC} \
  201. $TOOLCHAIN_ENV \
  202. $YNDEXER_OUTPUT \
  203. && $_COMPILER_TIME_TRACE_POSTPROCESS \
  204. $_C_CPP_KV_STYLE_NEW
  205. _C_ARGS_NEW=\
  206. $CLANG_TIDY_ARGS \
  207. $YNDEXER_ARGS \
  208. $RETRY_ARGS \
  209. $C_COMPILER \
  210. $C_FLAGS_PLATFORM \
  211. $GCC_COMPILE_FLAGS \
  212. $CFLAGS \
  213. $CL_MACRO_INFO \
  214. $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \
  215. $_COMPILER_TIME_TRACE_FLAGS \
  216. $CONLYFLAGS \
  217. $EXTRA_OUTPUT \
  218. $SRCFLAGS \
  219. ${input:SRC} \
  220. $TOOLCHAIN_ENV \
  221. $YNDEXER_OUTPUT \
  222. $_C_CPP_KV_STYLE_NEW \
  223. $SCU_NAME_KV_NEW
  224. ### _SRC_C_NODEPS_CMD is obtained from _C_ARGS by filtering the following elements:
  225. ### ${input:SRC}
  226. ### $CL_MACRO_INFO
  227. ### $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__
  228. ### $CLANG_TIDY_ARGS
  229. ### $EXTRA_OUTPUT
  230. ### $EXTRA_COVERAGE_OUTPUT
  231. ### $SRCFLAGS
  232. ### $YNDEXER_ARGS
  233. ### $YNDEXER_OUTPUT
  234. ###
  235. ### $GCC_COMPILE_FLAGS is substituted for $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC}
  236. _SRC_C_NODEPS_CMD=\
  237. $C_COMPILER \
  238. $C_FLAGS_PLATFORM \
  239. $EXTRA_C_FLAGS -c -o ${OUTFILE} ${SRC} ${pre=-I:INC} \
  240. $CFLAGS \
  241. $CONLYFLAGS \
  242. $TOOLCHAIN_ENV \
  243. $_C_CPP_KV_STYLE
  244. _FORCE_CPP_FLAGS=-x c++
  245. _SRC_CPP_CMD_NEW=$_CPP_ARGS_NEW
  246. _SRC_C_CMD_NEW=$_C_ARGS_NEW
  247. _SRC_M_CMD=$SRC_c($SRC $SRCFLAGS)
  248. _SRC_MASM_CMD=$_EMPTY_CMD