123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- _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"} ${input;hide:"build/scripts/process_command_files.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
|