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} } } } }