ld.conf 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. _LD_FLAGS_1=
  2. _LD_FLAGS_2=
  3. when ($MUSL == "yes") {
  4. _LD_FLAGS_1=-Wl,--no-as-needed
  5. }
  6. elsewhen ($OS_LINUX == "yes") {
  7. _LD_FLAGS_1=-ldl -lrt -Wl,--no-as-needed
  8. when ($GCC == "yes") {
  9. _LD_FLAGS_2=-Wl,-Bstatic -latomic -Wl,-Bdynamic
  10. }
  11. }
  12. elsewhen ($OS_ANDROID == "yes") {
  13. _LD_FLAGS_1=-ldl -Wl,--no-as-needed
  14. }
  15. elsewhen ($OS_DARWIN == "yes") {
  16. _LD_FLAGS_1=-Wl,-no_deduplicate
  17. when ($CLANG != "yes") {
  18. _LD_FLAGS_2=-Wl,-no_compact_unwind
  19. }
  20. }
  21. _LD_FLAGS_IOS_MAPSMOBI_ARM=
  22. when ($OS_IOS == "yes" && $MAPSMOBI_BUILD_TARGET == "yes" && $ARCH_ARM) {
  23. _LD_FLAGS_IOS_MAPSMOBI_ARM=-fembed-bitcode -Wl,-bitcode_verify
  24. }
  25. _LD_FLAGS_PROFILER_TYPE=
  26. when ($_BUILD_PROFILER_TYPE == "gprof") {
  27. _LD_FLAGS_PROFILER_TYPE=-pg
  28. }
  29. _LD_FLAGS_COVERAGE=
  30. when ($_BUILD_COVERAGE == "yes") {
  31. _LD_FLAGS_COVERAGE=-fprofile-arcs -ftest-coverage
  32. }
  33. _LD_FLAGS =
  34. _LD_FLAGS+=$_LD_FLAGS_1
  35. _LD_FLAGS+=$_LD_FLAGS_2
  36. _LD_FLAGS+=$_LD_FLAGS_IOS_MAPSMOBI_ARM
  37. _LD_FLAGS+=$_LD_FLAGS_PROFILER_TYPE
  38. _LD_FLAGS+=$_LD_FLAGS_COVERAGE
  39. _LD_FLAGS+=$LD_SDK_VERSION
  40. LDFLAGS+=$USER_LDFLAGS $_LD_FLAGS
  41. LDFLAGS_GLOBAL+=
  42. _START_GROUP=
  43. _END_GROUP=
  44. START_WHOLE_ARCHIVE_VALUE=
  45. END_WHOLE_ARCHIVE_VALUE=
  46. LD_STRIP_FLAG=
  47. _SONAME_OPTION=
  48. _LD_SRCS_GLOBALS=--start-wa ${rootrel;ext=.a:SRCS_GLOBAL} --end-wa ${rootrel;ext=.o:SRCS_GLOBAL} ${rootrel;ext=.supp:SRCS_GLOBAL}
  49. when ($OS_LINUX == "yes" || $OS_ANDROID == "yes" || $OS_CYGWIN == "yes" || $OS_NONE == "yes") {
  50. _START_GROUP=-Wl,--start-group
  51. _END_GROUP=-Wl,--end-group
  52. START_WHOLE_ARCHIVE_VALUE=-Wl,--whole-archive
  53. END_WHOLE_ARCHIVE_VALUE=-Wl,--no-whole-archive
  54. LD_STRIP_FLAG=-s
  55. _SONAME_OPTION=-soname
  56. _LD_SRCS_GLOBALS=-Wl,--whole-archive ${rootrel;ext=.a:SRCS_GLOBAL} -Wl,--no-whole-archive ${rootrel;ext=.o:SRCS_GLOBAL} ${rootrel;ext=.supp:SRCS_GLOBAL}
  57. }
  58. when ($_LD_WHOLE_ARCHIVE == "yes") {
  59. }
  60. when ($OS_DARWIN == "yes" || $OS_IOS == "yes") {
  61. _SONAME_OPTION=-install_name
  62. }
  63. _LD_LINKER_OUTPUT=
  64. _LD_LINKER_OUTPUT_FLAG=--linker-output ${output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX$MODULE_VERSION.linker.txt:REALPRJNAME}
  65. # Enable section-level DCE (dead code elimination):
  66. # remove whole unused code and data sections
  67. # (needs `-ffunction-sections` and `-fdata-sections` to be useful)
  68. #
  69. # NOTE: CGO linker doesn't seem to support DCE, but shares common LDFLAGS
  70. _LD_DCE_FLAG_GC_SECTIONS=
  71. _LD_DCE_FLAG_PRINT_SECTIONS=
  72. when ($OS_DARWIN == "yes") {
  73. _LD_DCE_FLAG_GC_SECTIONS=-Wl,-dead_strip
  74. }
  75. elsewhen ($OS_LINUX == "yes" || $OS_ANDROID == "yes") {
  76. _LD_DCE_FLAG_GC_SECTIONS=-Wl,--gc-sections
  77. when ($LINKER_DCE_PRINT_SECTIONS == "yes") {
  78. _LD_DCE_FLAG_PRINT_SECTIONS=-Wl,--print-gc-sections
  79. _LD_LINKER_OUTPUT=$_LD_LINKER_OUTPUT_FLAG
  80. }
  81. }
  82. LD_DCE_FLAG =
  83. LD_DCE_FLAG+=$_LD_DCE_FLAG_GC_SECTIONS
  84. LD_DCE_FLAG+=$_LD_DCE_FLAG_PRINT_SECTIONS
  85. DCE_FLAG=
  86. _LD_ICF_FLAG=
  87. _LD_ICF_FLAG_PRINT_SECTIONS=
  88. when ($_DEFAULT_LINKER_ID == "lld") {
  89. # Enable ICF (identical code folding pass) in safe mode
  90. # https://research.google/pubs/pub36912/
  91. _LD_ICF_FLAG=-Wl,-icf=safe
  92. when ($LINKER_ICF_PRINT_SECTIONS == "yes") {
  93. _LD_ICF_FLAG_PRINT_SECTIONS=-Wl,--print-icf-sections
  94. _LD_LINKER_OUTPUT=$_LD_LINKER_OUTPUT_FLAG
  95. }
  96. }
  97. LD_ICF_FLAG =
  98. LD_ICF_FLAG+=$_LD_ICF_FLAG
  99. LD_ICF_FLAG+=$_LD_ICF_FLAG_PRINT_SECTIONS
  100. ICF_FLAG=
  101. STRIP_FLAG=
  102. C_LIBRARY_PATH=
  103. C_SYSTEM_LIBRARIES_INTERCEPT=
  104. _LD_THREAD_LIBRARY=
  105. when ($OS_LINUX == "yes" || $OS_DARWIN == "yes") {
  106. _LD_THREAD_LIBRARY=-lpthread
  107. }
  108. _LD_USE_STDLIB=
  109. when ($_BUILD_COVERAGE == "yes" || $GCOV_COVERAGE == "yes" || $CLANG_COVERAGE == "yes" || $_BUILD_SANITIZED == "yes") {
  110. _LD_USE_STDLIB=
  111. }
  112. elsewhen ($OS_ANDROID == "yes") {
  113. when ($_ANDROID_NDK_VERSION_LESS_THEN_23 == "yes") {
  114. # Preserve old behaviour: specify runtime libs manually
  115. _LD_USE_STDLIB=-nodefaultlibs
  116. }
  117. otherwise {
  118. # Use toolchain defaults to link with libunwind/clang_rt.builtins
  119. _LD_USE_STDLIB=-nostdlib++
  120. }
  121. }
  122. elsewhen ($OS_LINUX == "yes" || $OS_DARWIN == "yes" || $OS_IOS == "yes") {
  123. _LD_USE_STDLIB=-nodefaultlibs
  124. }
  125. _C_SYSTEM_LIBRARIES=$_LD_USE_STDLIB $_LD_THREAD_LIBRARY $_LD_SYS_LIB -lc
  126. when ($MUSL == "yes") {
  127. _C_SYSTEM_LIBRARIES=-nostdlib
  128. }
  129. C_SYSTEM_LIBRARIES=$_C_SYSTEM_LIBRARIES
  130. OBJADDE=
  131. LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG=
  132. when ($OS_LINUX == "yes" || $OS_ANDROID == "yes") {
  133. LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG=-rdynamic
  134. }
  135. NO_EXPORT_DYNAMIC_SYMBOLS=
  136. EXPORTS_VALUE=$LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG
  137. when ($EXPORTS_FILE) {
  138. EXPORTS_VALUE=$LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG -Wl,--version-script=${input:EXPORTS_FILE}
  139. }
  140. when ($NO_EXPORT_DYNAMIC_SYMBOLS == "yes") {
  141. EXPORTS_VALUE=
  142. }
  143. LINKER_SCRIPT_VALUE=${ext=.ld;pre=-T:SRCS_GLOBAL}
  144. _LINKER_TIME_TRACE_GRANULARITY=500
  145. when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
  146. _LINKER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
  147. }
  148. _LINKER_TIME_TRACE_FLAG=
  149. when (($TIME_TRACE == "yes" || $LINKER_TIME_TRACE == "yes") && $_DEFAULT_LINKER_ID == "lld") {
  150. _LINKER_TIME_TRACE_FLAG=\
  151. -Wl,--time-trace \
  152. -Wl,--time-trace-granularity=$_LINKER_TIME_TRACE_GRANULARITY \
  153. -Wl,--time-trace-file=${output;rootrel;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.time_trace.json:REALPRJNAME}
  154. }
  155. _EXE_FLAGS=\
  156. $C_FLAGS_PLATFORM \
  157. $BEFORE_PEERS \
  158. $_START_GROUP \
  159. ${rootrel:PEERS} \
  160. $_END_GROUP \
  161. $AFTER_PEERS \
  162. $EXPORTS_VALUE \
  163. $LINKER_SCRIPT_VALUE \
  164. $LDFLAGS \
  165. $LDFLAGS_GLOBAL \
  166. $OBJADDE \
  167. $OBJADDE_LIB \
  168. $C_LIBRARY_PATH \
  169. $C_SYSTEM_LIBRARIES_INTERCEPT \
  170. $C_SYSTEM_LIBRARIES \
  171. $STRIP_FLAG \
  172. $DCE_FLAG \
  173. $ICF_FLAG \
  174. $_LINKER_TIME_TRACE_FLAG
  175. _SONAME_FLAG=-Wl,$_SONAME_OPTION,$_SONAME
  176. _SHARED_FLAG=-shared
  177. _EXEC_SHARED_FLAG=
  178. when ($OS_LINUX == "yes") {
  179. _EXEC_SHARED_FLAG=-pie -fPIE -Wl,--unresolved-symbols=ignore-all -rdynamic
  180. }
  181. _LD_ENV_STYLE=${cwd:ARCADIA_BUILD_ROOT} $TOOLCHAIN_ENV ${kv;hide:"p LD"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}
  182. # Program
  183. GENERATE_MF_CMD=\
  184. $YMAKE_PYTHON ${input:"build/scripts/generate_mf.py"} ${input;hide:"build/scripts/process_command_files.py"} \
  185. --build-root $ARCADIA_BUILD_ROOT \
  186. --module-name $REALPRJNAME \
  187. -o ${output;rootrel;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.mf:REALPRJNAME} \
  188. -t $MODULE_TYPE \
  189. --ya-start-command-file \
  190. -Ya,lics $LICENSE_NAMES \
  191. -Ya,peers ${rootrel:PEERS} \
  192. -Ya,credits ${input:CREDITS_TEXTS_FILE} $CREDITS_FLAGS \
  193. --ya-end-command-file
  194. LINK_SCRIPT_EXE_FLAGS=
  195. REAL_LINK_EXE_CMDLINE =\
  196. $YMAKE_PYTHON ${input:"build/scripts/link_exe.py"} \
  197. --source-root $ARCADIA_ROOT
  198. REAL_LINK_EXE_CMDLINE+=$_LD_LINKER_OUTPUT
  199. REAL_LINK_EXE_CMDLINE+=\
  200. ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
  201. ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
  202. $_LD_ARCH_FLAG \
  203. $LINK_SCRIPT_EXE_FLAGS \
  204. $CXX_COMPILER \
  205. $_LD_SRCS_GLOBALS \
  206. $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
  207. $_EXE_FLAGS \
  208. $_LD_ENV_STYLE
  209. REAL_LINK_EXE_TIDY=\
  210. $YMAKE_PYTHON ${input:"build/scripts/clang_tidy_arch.py"} \
  211. --build-root $ARCADIA_BUILD_ROOT \
  212. --source-root $ARCADIA_ROOT \
  213. --output-file $TARGET \
  214. $AUTO_INPUT \
  215. $_LD_ENV_STYLE
  216. # Executable Shared Library
  217. REAL_LINK_EXEC_DYN_LIB_CMDLINE =\
  218. $YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
  219. --target $TARGET
  220. REAL_LINK_EXEC_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
  221. REAL_LINK_EXEC_DYN_LIB_CMDLINE+=\
  222. ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
  223. ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
  224. $_LD_ARCH_FLAG \
  225. $LINK_DYN_LIB_FLAGS \
  226. $CXX_COMPILER \
  227. $_LD_SRCS_GLOBALS \
  228. $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
  229. $_EXEC_SHARED_FLAG \
  230. $_SONAME_FLAG \
  231. $_EXE_FLAGS \
  232. $_LD_ENV_STYLE
  233. REAL_LINK_EXEC_DYN_LIB=$REAL_LINK_EXEC_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
  234. # Shared Library
  235. LINK_DYN_LIB_FLAGS=
  236. REAL_LINK_DYN_LIB_CMDLINE =\
  237. $YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
  238. --target $TARGET
  239. REAL_LINK_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
  240. REAL_LINK_DYN_LIB_CMDLINE+=\
  241. ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
  242. ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
  243. $_LD_ARCH_FLAG \
  244. $LINK_DYN_LIB_FLAGS \
  245. $CXX_COMPILER \
  246. $_LD_SRCS_GLOBALS \
  247. $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
  248. $_SHARED_FLAG \
  249. $_SONAME_FLAG \
  250. $_EXE_FLAGS \
  251. $_LD_ENV_STYLE
  252. REAL_LINK_DYN_LIB=$REAL_LINK_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
  253. _DWARF_COMMAND=
  254. when ($OS_DARWIN == "yes" && $NO_DEBUGINFO != "yes") {
  255. _DWARF_COMMAND=$DWARF_TOOL $TARGET -o ${output;pre=$MODULE_PREFIX$REALPRJNAME.dSYM/Contents/Resources/DWARF/$MODULE_PREFIX:REALPRJNAME} $_LD_ENV_STYLE
  256. }
  257. DWARF_COMMAND=$_DWARF_COMMAND
  258. _REAL_LINK_EXE=$REAL_LINK_EXE_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
  259. _LINK_EXE=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $REAL_LINK_EXE && $DWARF_COMMAND && $LINK_ADDITIONAL_SECTIONS_COMMAND && $PACK_IOS_CMD
  260. _LINK_DYN_LIB=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $REAL_LINK_DYN_LIB && $DWARF_COMMAND && $LINK_ADDITIONAL_SECTIONS_COMMAND
  261. when ($TIDY == "yes") {
  262. _REAL_LINK_EXE=$REAL_LINK_EXE_TIDY
  263. _LINK_EXE=$REAL_LINK_EXE
  264. _LINK_DYN_LIB=$REAL_LINK_EXE
  265. }
  266. REAL_LINK_EXE=$_REAL_LINK_EXE
  267. LINK_EXE=$_LINK_EXE
  268. LINK_DYN_LIB=$_LINK_DYN_LIB
  269. LINK_EXEC_DYN_LIB=\
  270. $GENERATE_MF && \
  271. $GENERATE_VCS_C_INFO_NODEP && \
  272. $REAL_LINK_EXEC_DYN_LIB && \
  273. $DWARF_COMMAND && \
  274. $LINK_ADDITIONAL_SECTIONS_COMMAND
  275. SWIG_DLL_JAR_CMD=\
  276. $GENERATE_MF && \
  277. $GENERATE_VCS_C_INFO_NODEP && \
  278. $REAL_SWIG_DLL_JAR_CMD && \
  279. $DWARF_COMMAND
  280. _LD_TAIL_LINK_LIB=$AUTO_INPUT ${kv;hide:"p AR"} $TOOLCHAIN_ENV ${kv;hide:"pc light-red"} ${kv;hide:"show_out"}
  281. _LD_ARCHIVER=$YMAKE_PYTHON ${input:"build/scripts/link_lib.py"} ${quo:AR_TOOL} $AR_TYPE $_LD_LLVM_AR_FORMAT $ARCADIA_BUILD_ROOT $_LD_AR_PLUGIN
  282. _LD_LIB_GENERATE_MF=$GENERATE_MF &&
  283. when ($TIDY == "yes") {
  284. _LD_ARCHIVER=$YMAKE_PYTHON ${input:"build/scripts/clang_tidy_arch.py"} --source-root $ARCADIA_ROOT --build-root $ARCADIA_BUILD_ROOT --output-file
  285. _LD_LIB_GENERATE_MF=
  286. }
  287. LINK_LIB=$_LD_LIB_GENERATE_MF $_LD_ARCHIVER $TARGET $_LD_TAIL_LINK_LIB
  288. GLOBAL_LINK_LIB=$_LD_ARCHIVER $GLOBAL_TARGET $_LD_TAIL_LINK_LIB
  289. # "Fat Object" : pre-linked global objects and static library with all dependencies
  290. _LD_LINK_FAT_PREFIX=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $YMAKE_PYTHON ${input:"build/scripts/link_fat_obj.py"} --build-root $ARCADIA_BUILD_ROOT
  291. _LD_LINK_FAT_SRCS_GLOBALS_WA=$_LD_SRCS_GLOBALS
  292. _LD_LINK_FAT_SRCS_GLOBALS_NO_WA=${rootrel;ext=.a:SRCS_GLOBAL} ${rootrel;ext=.o:SRCS_GLOBAL}
  293. _LD_LINK_FAT_SUFFIX1=$_LD_ARCH_FLAG \
  294. -Ya,input $AUTO_INPUT $VCS_C_OBJ \
  295. -Ya,global_srcs
  296. _LD_LINK_FAT_SUFFIX2=-Ya,peers $PEERS \
  297. -Ya,linker $CXX_COMPILER \
  298. $LDFLAGS_GLOBAL $C_FLAGS_PLATFORM $LD_SDK_VERSION \
  299. -Ya,archiver $_LD_ARCHIVER \
  300. $TOOLCHAIN_ENV ${kv;hide:"p LD"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}
  301. LINK_FAT_OBJECT=\
  302. $_LD_LINK_FAT_PREFIX \
  303. --obj=$TARGET --lib=${output:REALPRJNAME.a} \
  304. $_LD_LINK_FAT_SUFFIX1 \
  305. $_LD_LINK_FAT_SRCS_GLOBALS_WA \
  306. $_LD_LINK_FAT_SUFFIX2
  307. LINK_RECURSIVE_LIBRARY=\
  308. $_LD_LINK_FAT_PREFIX \
  309. --lib=$TARGET --with-own-obj --with-global-srcs \
  310. $_LD_LINK_FAT_SUFFIX1 \
  311. $_LD_LINK_FAT_SRCS_GLOBALS_NO_WA \
  312. $_LD_LINK_FAT_SUFFIX2
  313. LINK_FAT_OBJECT_LIBRARY=\
  314. $_LD_LINK_FAT_PREFIX \
  315. --lib=$TARGET $FAT_OBJECT_ARGS $FAT_OBJECT_OUTS \
  316. $_LD_LINK_FAT_SUFFIX1 \
  317. $_LD_LINK_FAT_SRCS_GLOBALS_NO_WA \
  318. $_LD_LINK_FAT_SUFFIX2
  319. LIBRT=-lrt
  320. MD5LIB=-lcrypt
  321. LIBRESOLV=
  322. when ($OS_LINUX || $OS_DARWIN || $OS_ANDROID) {
  323. LIBRESOLV=-lresolv
  324. }
  325. PROFFLAG=-pg