1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
LDFLAGS+=$USER_LDFLAGS $_LD_FLAGS
_START_GROUP=
_END_GROUP=
BEFORE_PEERS=
AFTER_PEERS=
START_WHOLE_ARCHIVE_VALUE=
END_WHOLE_ARCHIVE_VALUE=
LD_STRIP_FLAG=
_SONAME_OPTION=
_LD_SRCS_GLOBALS=--start-wa ${rootrel;ext=.a:SRCS_GLOBAL} --end-wa ${rootrel;ext=.o:SRCS_GLOBAL} ${rootrel;ext=.supp:SRCS_GLOBAL}
when ($OS_LINUX == "yes" || $OS_ANDROID == "yes" || $OS_CYGWIN == "yes" || $OS_NONE == "yes") {
_START_GROUP=-Wl,--start-group
_END_GROUP=-Wl,--end-group
START_WHOLE_ARCHIVE_VALUE=-Wl,--whole-archive
END_WHOLE_ARCHIVE_VALUE=-Wl,--no-whole-archive
LD_STRIP_FLAG=-s
_SONAME_OPTION=-soname
_LD_SRCS_GLOBALS=-Wl,--whole-archive --ya-start-command-file ${rootrel;ext=.a:SRCS_GLOBAL} --ya-end-command-file -Wl,--no-whole-archive ${rootrel;ext=.o:SRCS_GLOBAL} ${rootrel;ext=.supp:SRCS_GLOBAL}
}
when ($_LD_WHOLE_ARCHIVE == "yes") {
}
when ($OS_DARWIN == "yes" || $OS_IOS == "yes") {
_SONAME_OPTION=-install_name
}
_LD_LINKER_OUTPUT=
_LD_LINKER_OUTPUT_FLAG=--linker-output ${output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX$MODULE_VERSION.linker.txt:REALPRJNAME}
# Enable section-level DCE (dead code elimination):
# remove whole unused code and data sections
# (needs `-ffunction-sections` and `-fdata-sections` to be useful)
#
# NOTE: CGO linker doesn't seem to support DCE, but shares common LDFLAGS
_LD_DCE_FLAG_GC_SECTIONS=
_LD_DCE_FLAG_PRINT_SECTIONS=
when ($OS_DARWIN == "yes" || $OS_IOS == "yes" || $OS_IOSSIM == "yes") {
_LD_DCE_FLAG_GC_SECTIONS=-Wl,-dead_strip
}
elsewhen ($OS_LINUX == "yes" || $OS_ANDROID == "yes" || $OS_NONE == "yes") {
_LD_DCE_FLAG_GC_SECTIONS=-Wl,--gc-sections
when ($LINKER_DCE_PRINT_SECTIONS == "yes") {
_LD_DCE_FLAG_PRINT_SECTIONS=-Wl,--print-gc-sections
_LD_LINKER_OUTPUT=$_LD_LINKER_OUTPUT_FLAG
}
}
LD_DCE_FLAG =
LD_DCE_FLAG+=$_LD_DCE_FLAG_GC_SECTIONS
LD_DCE_FLAG+=$_LD_DCE_FLAG_PRINT_SECTIONS
DCE_FLAG=
_LD_ICF_FLAG=
_LD_ICF_FLAG_PRINT_SECTIONS=
when ($_DEFAULT_LINKER_ID == "lld") {
# Enable ICF (identical code folding pass) in safe mode
# https://research.google/pubs/pub36912/
_LD_ICF_FLAG=-Wl,--icf=safe
when ($LINKER_ICF_PRINT_SECTIONS == "yes") {
_LD_ICF_FLAG_PRINT_SECTIONS=-Wl,--print-icf-sections
_LD_LINKER_OUTPUT=$_LD_LINKER_OUTPUT_FLAG
}
}
LD_ICF_FLAG =
LD_ICF_FLAG+=$_LD_ICF_FLAG
LD_ICF_FLAG+=$_LD_ICF_FLAG_PRINT_SECTIONS
ICF_FLAG=
_LD_NO_PIE_FLAG=
when ($_LINKER_ID == "lld" && $PIE != "yes" && ($PIC != "yes" || $PIC_NO_PIE == "yes")) {
when ($OS_LINUX == "yes") {
_LD_NO_PIE_FLAG=-Wl,-no-pie
}
}
STRIP_FLAG=
C_LIBRARY_PATH=
C_SYSTEM_LIBRARIES_INTERCEPT=
when ($USEMPROF == "yes" || $USE_MPROF == "yes") {
C_SYSTEM_LIBRARIES_INTERCEPT+=-ldmalloc
}
_LD_THREAD_LIBRARY=
when ($OS_LINUX == "yes" || $OS_DARWIN == "yes") {
_LD_THREAD_LIBRARY=-lpthread
}
_LD_USE_STDLIB=
when ($_BUILD_COVERAGE == "yes" || $GCOV_COVERAGE == "yes" || $CLANG_COVERAGE == "yes" || $_BUILD_SANITIZED == "yes") {
_LD_USE_STDLIB=
}
elsewhen ($OS_ANDROID == "yes") {
when ($_ANDROID_NDK_VERSION_LESS_THEN_23 == "yes") {
# Preserve old behaviour: specify runtime libs manually
_LD_USE_STDLIB=-nodefaultlibs
}
otherwise {
# Use toolchain defaults to link with libunwind/clang_rt.builtins
_LD_USE_STDLIB=-nostdlib++
}
}
elsewhen ($OS_LINUX == "yes" || $OS_DARWIN == "yes" || $OS_IOS == "yes") {
_LD_USE_STDLIB=-nodefaultlibs
}
_C_SYSTEM_LIBRARIES=$_LD_USE_STDLIB $_LD_THREAD_LIBRARY $_LD_SYS_LIB -lc
when ($MUSL == "yes") {
_C_SYSTEM_LIBRARIES=-nostdlib
}
when ($OS_EMSCRIPTEN == "yes") {
_C_SYSTEM_LIBRARIES=-nostdlib
}
C_SYSTEM_LIBRARIES=$_C_SYSTEM_LIBRARIES
LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG=
when ($OS_LINUX == "yes" || $OS_ANDROID == "yes") {
LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG=-rdynamic
}
NO_EXPORT_DYNAMIC_SYMBOLS=
EXPORTS_VALUE=$LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG
when ($EXPORTS_FILE) {
EXPORTS_VALUE=$LD_EXPORT_ALL_DYNAMIC_SYMBOLS_FLAG -Wl,--version-script=${input:EXPORTS_FILE}
}
when ($NO_EXPORT_DYNAMIC_SYMBOLS == "yes") {
EXPORTS_VALUE=
}
LINKER_SCRIPT_VALUE=${ext=.ld;pre=-T:SRCS_GLOBAL}
_LINKER_TIME_TRACE_GRANULARITY=500
when ($TIME_TRACE_GRANULARITY && $TIME_TRACE_GRANULARITY != "") {
_LINKER_TIME_TRACE_GRANULARITY=$TIME_TRACE_GRANULARITY
}
_LINKER_TIME_TRACE_FLAG=
when (($TIME_TRACE == "yes" || $LINKER_TIME_TRACE == "yes") && $_DEFAULT_LINKER_ID == "lld") {
_LINKER_TIME_TRACE_FLAG=\
-Wl,--time-trace=${rootrel;output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.time_trace.json:REALPRJNAME} \
-Wl,--time-trace-granularity=$_LINKER_TIME_TRACE_GRANULARITY
}
_EXE_FLAGS=\
$C_FLAGS_PLATFORM \
$BEFORE_PEERS \
$_START_GROUP \
${rootrel:PEERS} \
$_END_GROUP \
$AFTER_PEERS \
$EXPORTS_VALUE \
$LINKER_SCRIPT_VALUE \
$LDFLAGS \
$LDFLAGS_GLOBAL \
$OBJADDE \
$OBJADDE_LIB \
$OBJADDE_LIB_GLOBAL \
$C_LIBRARY_PATH \
$C_SYSTEM_LIBRARIES_INTERCEPT \
$C_SYSTEM_LIBRARIES \
$STRIP_FLAG \
$DCE_FLAG \
$ICF_FLAG \
$_LD_NO_PIE_FLAG \
$_LINKER_TIME_TRACE_FLAG
_SONAME_FLAG=-Wl,$_SONAME_OPTION,$_SONAME
when ($OS_EMSCRIPTEN == "yes") {
_SONAME_FLAG=
}
_SHARED_FLAG=-shared
when ($OS_EMSCRIPTEN == "yes") {
_SHARED_FLAG=-Wl,-shared -Wl,--no-entry -Wl,--export-all -Wl,--import-memory -Wl,--import-undefined
}
_EXEC_SHARED_FLAG=
when ($OS_LINUX == "yes") {
_EXEC_SHARED_FLAG=-pie -fPIE -Wl,--unresolved-symbols=ignore-all -rdynamic
}
_LD_ENV_STYLE=${cwd:ARCADIA_BUILD_ROOT} $TOOLCHAIN_ENV ${hide;kv:"p LD"} ${hide;kv:"pc light-blue"} ${hide;kv:"show_out"}
_ROOT_FLAGS=--source-root $ARCADIA_ROOT --build-root $(BUILD_ROOT)
# Program
GENERATE_MF_CMD=\
$YMAKE_PYTHON ${input:"build/scripts/generate_mf.py"} ${hide;input:"build/scripts/process_command_files.py"} \
--build-root $ARCADIA_BUILD_ROOT \
--module-name $REALPRJNAME \
-o ${rootrel;output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.mf:REALPRJNAME} \
-t $MODULE_TYPE \
--ya-start-command-file \
-Ya,lics $LICENSE_NAMES \
-Ya,peers ${rootrel:PEERS} \
-Ya,credits ${input:CREDITS_TEXTS_FILE} $CREDITS_FLAGS \
--ya-end-command-file
_LINK_SCRIPT_IMPORTS=\
${hide;input:"build/scripts/fix_py2_protobuf.py"} \
${hide;input:"build/scripts/thinlto_cache.py"} \
$_PROCESS_WHOLE_ARCHIVE_SCRIPT
LINK_SCRIPT_EXE_FLAGS=
REAL_LINK_EXE_CMDLINE =\
$YMAKE_PYTHON ${input:"build/scripts/link_exe.py"} \
REAL_LINK_EXE_CMDLINE+=--clang-ver $CLANG_VER
REAL_LINK_EXE_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_EXE_CMDLINE+=\
$_ROOT_FLAGS \
${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
$_LD_ARCH_FLAG \
$LINK_SCRIPT_EXE_FLAGS \
$_THINLTO_CACHE_FLAGS \
$CXX_COMPILER_OLD \
$_LD_SRCS_GLOBALS \
$VCS_C_OBJ $_EXTRA_OBJS $AUTO_INPUT -o $TARGET \
$_EXE_FLAGS \
$_LINK_SCRIPT_IMPORTS \
$_LD_ENV_STYLE
REAL_LINK_EXE_TIDY=\
$YMAKE_PYTHON ${input:"build/scripts/clang_tidy_arch.py"} \
--output-file $TARGET \
$_ROOT_FLAGS \
$AUTO_INPUT \
${ext=.tidyjson:SRCS_GLOBAL} \
$_LD_ENV_STYLE
# Executable Shared Library
REAL_LINK_EXEC_DYN_LIB_CMDLINE =\
$YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
${hide;input:"build/scripts/link_exe.py"} \
--target $TARGET
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=\
$_ROOT_FLAGS \
${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
$_LD_ARCH_FLAG \
$LINK_DYN_LIB_FLAGS \
$_THINLTO_CACHE_FLAGS \
$CXX_COMPILER_OLD \
$_LD_SRCS_GLOBALS \
$VCS_C_OBJ $_EXTRA_OBJS $AUTO_INPUT -o $TARGET \
$_EXEC_SHARED_FLAG \
$_SONAME_FLAG \
$_EXE_FLAGS \
$_LINK_SCRIPT_IMPORTS \
$_LD_ENV_STYLE
REAL_LINK_EXEC_DYN_LIB=$REAL_LINK_EXEC_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
# Shared Library
LINK_DYN_LIB_FLAGS=
REAL_LINK_DYN_LIB_CMDLINE =\
$YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
${hide;input:"build/scripts/link_exe.py"} \
--target $TARGET
REAL_LINK_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_DYN_LIB_CMDLINE+=\
${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
$_ROOT_FLAGS \
$_LD_ARCH_FLAG \
$LINK_DYN_LIB_FLAGS \
$_THINLTO_CACHE_FLAGS \
$CXX_COMPILER_OLD \
$_LD_SRCS_GLOBALS \
$VCS_C_OBJ $_EXTRA_OBJS $AUTO_INPUT -o $TARGET \
$_SHARED_FLAG \
$_SONAME_FLAG \
$_EXE_FLAGS \
$_LINK_SCRIPT_IMPORTS \
$_LD_ENV_STYLE
REAL_LINK_DYN_LIB=$REAL_LINK_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
_DWARF_COMMAND=
when (($OS_DARWIN == "yes" || $OS_IOS || $OS_IOSSIM) && $NO_DEBUGINFO != "yes" && $SPLIT_DWARF_VALUE != "no" && $NO_SPLIT_DWARF != "yes") {
_DWARF_COMMAND=$DWARF_TOOL $TARGET -o ${output;pre=$MODULE_PREFIX$REALPRJNAME.dSYM/Contents/Resources/DWARF/$MODULE_PREFIX:REALPRJNAME} $_LD_ENV_STYLE
}
elsewhen ($OS_DARWIN == "yes" && $NO_DEBUGINFO != "yes") {
_EXE_FLAGS+=$DEBUG_INFO_FLAGS
}
otherwise {
_DWARF_COMMAND=
}
DWARF_COMMAND=$_DWARF_COMMAND
_REAL_LINK_EXE=$REAL_LINK_EXE_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
_EXTRA_OBJS=
_GENERATE_EXTRA_OBJS=
_EXTRA_LINK_CMD=
_LINK_EXE=
_LINK_EXE+=$GENERATE_MF
_LINK_EXE+=&& $GENERATE_VCS_C_INFO_NODEP
_LINK_EXE+=&& $_GENERATE_EXTRA_OBJS
_LINK_EXE+=&& $COPY_PROFILE_RUNTIME
_LINK_EXE+=&& $REAL_LINK_EXE
_LINK_EXE+=&& $DWARF_COMMAND
_LINK_EXE+=&& $LINK_ADDITIONAL_SECTIONS_COMMAND
_LINK_EXE+=&& $PACK_IOS_CMD
_LINK_EXE+=&& $_EXTRA_LINK_CMD
_LINK_DYN_LIB=
_LINK_DYN_LIB+=$GENERATE_MF
_LINK_DYN_LIB+=&& $GENERATE_VCS_C_INFO_NODEP
_LINK_DYN_LIB+=&& $_GENERATE_EXTRA_OBJS
_LINK_DYN_LIB+=&& $COPY_PROFILE_RUNTIME
_LINK_DYN_LIB+=&& $REAL_LINK_DYN_LIB
_LINK_DYN_LIB+=&& $DWARF_COMMAND
_LINK_DYN_LIB+=&& $LINK_ADDITIONAL_SECTIONS_COMMAND
_LINK_DYN_LIB+=&& $_EXTRA_LINK_CMD
when ($TIDY == "yes") {
_REAL_LINK_EXE=$REAL_LINK_EXE_TIDY
_LINK_EXE=$REAL_LINK_EXE
_LINK_DYN_LIB=$REAL_LINK_EXE
}
REAL_LINK_EXE=$_REAL_LINK_EXE
LINK_EXE=$_LINK_EXE
LINK_DYN_LIB=$_LINK_DYN_LIB
LINK_EXEC_DYN_LIB=\
$GENERATE_MF && \
$GENERATE_VCS_C_INFO_NODEP && \
$_GENERATE_EXTRA_OBJS && \
$REAL_LINK_EXEC_DYN_LIB && \
$DWARF_COMMAND && \
$LINK_ADDITIONAL_SECTIONS_COMMAND
SWIG_DLL_JAR_CMD=\
$GENERATE_MF && \
$GENERATE_VCS_C_INFO_NODEP && \
$REAL_SWIG_DLL_JAR_CMD && \
$DWARF_COMMAND
_LD_LINK_LIB_EXTRA_INPUT=
_LD_TAIL_LINK_LIB=$AUTO_INPUT $_LD_LINK_LIB_EXTRA_INPUT ${hide;kv:"p AR"} $TOOLCHAIN_ENV ${hide;kv:"pc light-red"} ${hide;kv:"show_out"}
_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
_LD_LIB_GENERATE_MF=$GENERATE_MF &&
when ($TIDY == "yes") {
_LD_ARCHIVER=$YMAKE_PYTHON ${input:"build/scripts/clang_tidy_arch.py"} --source-root $ARCADIA_ROOT --build-root $ARCADIA_BUILD_ROOT --output-file
_LD_LIB_GENERATE_MF=
}
LINK_LIB=$_LD_LIB_GENERATE_MF $_LD_ARCHIVER $TARGET $_LD_TAIL_LINK_LIB
GLOBAL_LINK_LIB=$_LD_ARCHIVER $GLOBAL_TARGET $_LD_TAIL_LINK_LIB
# "Fat Object" : pre-linked global objects and static library with all dependencies
_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 $_PROCESS_WHOLE_ARCHIVE_SCRIPT
_LD_LINK_FAT_SRCS_GLOBALS_WA=$_LD_SRCS_GLOBALS
_LD_LINK_FAT_SRCS_GLOBALS_NO_WA=${rootrel;ext=.a:SRCS_GLOBAL} ${rootrel;ext=.o:SRCS_GLOBAL}
macro _FAT_OBJECT_ARGS_BASE(Flag, Lib) {
.CMD=$Flag=$Lib
}
# FIXME: pre=lib here is weird legacy
_FAT_OBJECT_ARGS=--obj=${output;pre=lib;suf=.o:REALPRJNAME}
_LD_LINK_FAT_SRCS_GLOBALS=$_LD_LINK_FAT_SRCS_GLOBALS_WA
macro PACK_GLOBALS_IN_LIBRARY() {
SET(_FAT_OBJECT_ARGS $_FAT_OBJECT_ARGS_BASE(--globals-lib, \${output;pre=$MODULE_PREFIX;suf=.globals.a:REALPRJNAME}))
}
when ($OS_ANDROID == "yes") {
_FAT_OBJECT_ARGS=
_LD_LINK_FAT_SRCS_GLOBALS=$_LD_LINK_FAT_SRCS_GLOBALS_NO_WA
}
_LD_LINK_FAT_SUFFIX1=$_LD_ARCH_FLAG \
-Ya,input $AUTO_INPUT $VCS_C_OBJ \
-Ya,global_srcs
_LD_LINK_FAT_SUFFIX2=-Ya,peers $PEERS \
-Ya,linker $CXX_COMPILER_OLD \
$LDFLAGS_GLOBAL $C_FLAGS_PLATFORM $LD_SDK_VERSION \
-Ya,archiver $_LD_ARCHIVER \
$TOOLCHAIN_ENV ${hide;kv:"p LD"} ${hide;kv:"pc light-blue"} ${hide;kv:"show_out"}
LINK_FAT_OBJECT=\
$_LD_LINK_FAT_PREFIX \
--lib=$TARGET $_FAT_OBJECT_ARGS \
$_LD_LINK_FAT_SUFFIX1 \
$_LD_LINK_FAT_SRCS_GLOBALS \
$_LD_LINK_FAT_SUFFIX2
LINK_RECURSIVE_LIBRARY=\
$_LD_LINK_FAT_PREFIX \
--lib=$TARGET --with-own-obj --with-global-srcs \
$_LD_LINK_FAT_SUFFIX1 \
$_LD_LINK_FAT_SRCS_GLOBALS_NO_WA \
$_LD_LINK_FAT_SUFFIX2
LIBRT=-lrt
LIBRESOLV=
when ($OS_LINUX || $OS_DARWIN || $OS_ANDROID) {
LIBRESOLV=-lresolv
}
PROFFLAG=-pg
_THINLTO_CACHE_FLAGS=
macro THINLTO_CACHE(file) {
DEFAULT(THINLTO_CACHE use)
SET(_THINLTO_FILE $file)
when ($CLANG && $USE_THINLTO == "yes") {
select ($THINLTO_CACHE) {
"gen" ? {
_THINLTO_CACHE_FLAGS=--thinlto-cache-write --thinlto-cache=${output;pre=out-:_THINLTO_FILE}
}
"use" ? {
_THINLTO_CACHE_FLAGS=--thinlto-cache=${input:_THINLTO_FILE}
}
}
}
}
|