aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/linkers/ld.conf
blob: 90f548edbfbe9f9aa9c3b9ea3ab55a6871a055cd (plain) (blame)
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
_LD_FLAGS_1=
_LD_FLAGS_2=
when ($MUSL == "yes") {
    _LD_FLAGS_1=-Wl,--no-as-needed
}
elsewhen ($OS_LINUX == "yes") {
    _LD_FLAGS_1=-ldl -lrt -Wl,--no-as-needed
    when ($GCC == "yes") {
        _LD_FLAGS_2=-Wl,-Bstatic -latomic -Wl,-Bdynamic
    }
}
elsewhen ($OS_ANDROID == "yes") {
    _LD_FLAGS_1=-ldl -Wl,--no-as-needed
}
elsewhen ($OS_DARWIN == "yes") {
    _LD_FLAGS_1=-Wl,-no_deduplicate
    when ($CLANG != "yes") {
        _LD_FLAGS_2=-Wl,-no_compact_unwind
    }
}

_LD_FLAGS_IOS_MAPSMOBI_ARM=
when ($OS_IOS == "yes" && $MAPSMOBI_BUILD_TARGET == "yes" && $ARCH_ARM) {
    _LD_FLAGS_IOS_MAPSMOBI_ARM=-fembed-bitcode -Wl,-bitcode_verify
}

_LD_FLAGS_PROFILER_TYPE=
when ($_BUILD_PROFILER_TYPE == "gprof") {
    _LD_FLAGS_PROFILER_TYPE=-pg
}

_LD_FLAGS_COVERAGE=
when ($_BUILD_COVERAGE == "yes") {
    _LD_FLAGS_COVERAGE=-fprofile-arcs -ftest-coverage
}

_LD_FLAGS =
_LD_FLAGS+=$_LD_FLAGS_1
_LD_FLAGS+=$_LD_FLAGS_2
_LD_FLAGS+=$_LD_FLAGS_IOS_MAPSMOBI_ARM
_LD_FLAGS+=$_LD_FLAGS_PROFILER_TYPE
_LD_FLAGS+=$_LD_FLAGS_COVERAGE
_LD_FLAGS+=$LD_SDK_VERSION

LDFLAGS+=$USER_LDFLAGS $_LD_FLAGS
LDFLAGS_GLOBAL+=

_START_GROUP=
_END_GROUP=
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 ${rootrel;ext=.a:SRCS_GLOBAL} -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") {
    _LD_DCE_FLAG_GC_SECTIONS=-Wl,-dead_strip
}
elsewhen ($OS_LINUX == "yes" || $OS_ANDROID == "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=

STRIP_FLAG=

C_LIBRARY_PATH=
C_SYSTEM_LIBRARIES_INTERCEPT=

_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
}
C_SYSTEM_LIBRARIES=$_C_SYSTEM_LIBRARIES

OBJADDE=

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 \
        -Wl,--time-trace-granularity=$_LINKER_TIME_TRACE_GRANULARITY \
        -Wl,--time-trace-file=${output;rootrel;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.time_trace.json:REALPRJNAME}
}

_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 \
    $C_LIBRARY_PATH \
    $C_SYSTEM_LIBRARIES_INTERCEPT \
    $C_SYSTEM_LIBRARIES \
    $STRIP_FLAG \
    $DCE_FLAG \
    $ICF_FLAG \
    $_LINKER_TIME_TRACE_FLAG

_SONAME_FLAG=-Wl,$_SONAME_OPTION,$_SONAME
_SHARED_FLAG=-shared
_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 ${kv;hide:"p LD"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}

# Program
GENERATE_MF_CMD=\
    $YMAKE_PYTHON ${input:"build/scripts/generate_mf.py"} \
    --build-root $ARCADIA_BUILD_ROOT \
    --module-name $REALPRJNAME \
    -o ${output;rootrel;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_EXE_FLAGS=

REAL_LINK_EXE_CMDLINE =\
    $YMAKE_PYTHON ${input:"build/scripts/link_exe.py"} \
    --source-root $ARCADIA_ROOT
    REAL_LINK_EXE_CMDLINE+=$_LD_LINKER_OUTPUT
    REAL_LINK_EXE_CMDLINE+=\
    ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
    ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
    $_LD_ARCH_FLAG \
    $LINK_SCRIPT_EXE_FLAGS \
    $CXX_COMPILER \
    $_LD_SRCS_GLOBALS \
    $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
    $_EXE_FLAGS \
    $_LD_ENV_STYLE

REAL_LINK_EXE_TIDY=\
    $YMAKE_PYTHON ${input:"build/scripts/clang_tidy_arch.py"} \
    --build-root $ARCADIA_BUILD_ROOT \
    --source-root $ARCADIA_ROOT \
    --output-file $TARGET \
    $AUTO_INPUT \
    $_LD_ENV_STYLE

# Executable Shared Library

REAL_LINK_EXEC_DYN_LIB_CMDLINE =\
    $YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
    --target $TARGET
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=\
    ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
    ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
    $_LD_ARCH_FLAG \
    $LINK_DYN_LIB_FLAGS \
    $CXX_COMPILER \
    $_LD_SRCS_GLOBALS \
    $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
    $_EXEC_SHARED_FLAG \
    $_SONAME_FLAG \
    $_EXE_FLAGS \
    $_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"} \
    --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} \
    $_LD_ARCH_FLAG \
    $LINK_DYN_LIB_FLAGS \
    $CXX_COMPILER \
    $_LD_SRCS_GLOBALS \
    $VCS_C_OBJ $AUTO_INPUT -o $TARGET \
    $_SHARED_FLAG \
    $_SONAME_FLAG \
    $_EXE_FLAGS \
    $_LD_ENV_STYLE

REAL_LINK_DYN_LIB=$REAL_LINK_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)

_DWARF_COMMAND=
when ($OS_DARWIN == "yes" && $NO_DEBUGINFO != "yes") {
    _DWARF_COMMAND=$DWARF_TOOL $TARGET -o ${output;pre=$MODULE_PREFIX$REALPRJNAME.dSYM/Contents/Resources/DWARF/$MODULE_PREFIX:REALPRJNAME} $_LD_ENV_STYLE
}
DWARF_COMMAND=$_DWARF_COMMAND

_REAL_LINK_EXE=$REAL_LINK_EXE_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)
_LINK_EXE=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $REAL_LINK_EXE && $DWARF_COMMAND && $LINK_ADDITIONAL_SECTIONS_COMMAND && $PACK_IOS_CMD
_LINK_DYN_LIB=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $REAL_LINK_DYN_LIB && $DWARF_COMMAND && $LINK_ADDITIONAL_SECTIONS_COMMAND
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 && \
    $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_TAIL_LINK_LIB=$AUTO_INPUT ${kv;hide:"p AR"} $TOOLCHAIN_ENV ${kv;hide:"pc light-red"} ${kv;hide:"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
_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}

_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 \
    $LDFLAGS_GLOBAL $C_FLAGS_PLATFORM $LD_SDK_VERSION \
    -Ya,archiver $_LD_ARCHIVER \
    $TOOLCHAIN_ENV ${kv;hide:"p LD"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}

LINK_FAT_OBJECT=\
    $_LD_LINK_FAT_PREFIX \
    --obj=$TARGET --lib=${output:REALPRJNAME.a} \
    $_LD_LINK_FAT_SUFFIX1 \
    $_LD_LINK_FAT_SRCS_GLOBALS_WA \
    $_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

LINK_FAT_OBJECT_LIBRARY=\
    $_LD_LINK_FAT_PREFIX \
    --lib=$TARGET $FAT_OBJECT_ARGS $FAT_OBJECT_OUTS \
    $_LD_LINK_FAT_SUFFIX1 \
    $_LD_LINK_FAT_SRCS_GLOBALS_NO_WA \
    $_LD_LINK_FAT_SUFFIX2

LIBRT=-lrt
MD5LIB=-lcrypt
LIBRESOLV=
when ($OS_LINUX || $OS_DARWIN || $OS_ANDROID) {
    LIBRESOLV=-lresolv
}
PROFFLAG=-pg