aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authormikhnenko <mikhnenko@yandex-team.com>2023-07-20 10:12:30 +0300
committermikhnenko <mikhnenko@yandex-team.com>2023-07-20 10:12:30 +0300
commit1b2504dbde60c815023eb3151505ebd955b0b8dc (patch)
tree023e9ce52fd51d1f024dc3f48d3f433cbd8f0ac6 /build
parent9e49f01dad6a12a8bb3604e13784747e841f5759 (diff)
downloadydb-1b2504dbde60c815023eb3151505ebd955b0b8dc.tar.gz
Use profile from sources
Diffstat (limited to 'build')
-rw-r--r--build/conf/linkers/ld.conf35
-rw-r--r--build/scripts/clang_profile.py45
-rw-r--r--build/scripts/ya.make1
-rw-r--r--build/ymake.core.conf13
4 files changed, 90 insertions, 4 deletions
diff --git a/build/conf/linkers/ld.conf b/build/conf/linkers/ld.conf
index 2ec22beff0..44d8a1a07c 100644
--- a/build/conf/linkers/ld.conf
+++ b/build/conf/linkers/ld.conf
@@ -191,8 +191,9 @@ 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+=\
+
+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 \
@@ -212,6 +213,17 @@ REAL_LINK_EXE_TIDY=\
$AUTO_INPUT \
$_LD_ENV_STYLE
+PROFILE_RUNTIME_ARGS_END=end_of_args
+COPY_PROFILE_RUNTIME=\
+ $YMAKE_PYTHON3 ${input:"build/scripts/clang_profile.py"} \
+ --arch $TARGET_PLATFORM \
+ --build-root $ARCADIA_BUILD_ROOT \
+ --need-profile-runtime $NEED_PROFILE_RUNTIME \
+ $PROFILE_RUNTIME_ARGS_END
+COPY_PROFILE_RUNTIME+=\
+ ${rootrel:PEERS} \
+ $LDFLAGS
+
# Executable Shared Library
REAL_LINK_EXEC_DYN_LIB_CMDLINE =\
@@ -271,8 +283,23 @@ otherwise {
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
+_LINK_EXE=
+_LINK_EXE+=$GENERATE_MF
+_LINK_EXE+=&& $GENERATE_VCS_C_INFO_NODEP
+_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_DYN_LIB=
+_LINK_DYN_LIB+=$GENERATE_MF
+_LINK_DYN_LIB+=&& $GENERATE_VCS_C_INFO_NODEP
+_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
+
when ($TIDY == "yes") {
_REAL_LINK_EXE=$REAL_LINK_EXE_TIDY
_LINK_EXE=$REAL_LINK_EXE
diff --git a/build/scripts/clang_profile.py b/build/scripts/clang_profile.py
new file mode 100644
index 0000000000..a47149d835
--- /dev/null
+++ b/build/scripts/clang_profile.py
@@ -0,0 +1,45 @@
+import fnmatch
+import shutil
+import optparse
+import os
+
+import process_command_files as pcf
+
+def copy_clang_rt_profile(cmd, build_root, arch):
+ profile_path = None
+ resource_dir_path = None
+
+ for flag in cmd:
+ if fnmatch.fnmatch(flag, 'contrib/libs/clang14-rt/lib/profile/libclang_rt.profile-*.a'):
+ profile_path = flag
+ if flag.startswith('-resource-dir='):
+ resource_dir_path = flag[len('-resource-dir='):]
+
+ lib_profile = os.path.join(build_root, profile_path)
+ profile_name = os.path.basename(lib_profile)
+
+ if arch == 'DARWIN':
+ dst_dir = os.path.join(build_root, resource_dir_path, 'lib/darwin')
+
+ if arch == 'LINUX':
+ dst_dir = os.path.join(build_root, resource_dir_path, 'lib/linux')
+
+ os.makedirs(dst_dir, exist_ok=True)
+ shutil.copy(lib_profile, os.path.join(dst_dir, profile_name))
+
+
+def parse_args():
+ parser = optparse.OptionParser()
+ parser.disable_interspersed_args()
+ parser.add_option('--build-root')
+ parser.add_option('--arch')
+ parser.add_option('--need-profile-runtime')
+ return parser.parse_args()
+
+
+if __name__ == '__main__':
+ opts, args = parse_args()
+ args = pcf.skip_markers(args)
+
+ if opts.need_profile_runtime != "no":
+ copy_clang_rt_profile(args, opts.build_root, opts.arch)
diff --git a/build/scripts/ya.make b/build/scripts/ya.make
index b63874a784..4c5dc9144e 100644
--- a/build/scripts/ya.make
+++ b/build/scripts/ya.make
@@ -102,6 +102,7 @@ ELSEIF(PY3)
TEST_SRCS(
build_info_gen.py
+ clang_profile.py
)
ENDIF()
diff --git a/build/ymake.core.conf b/build/ymake.core.conf
index d3468bbbc4..0de9e1c149 100644
--- a/build/ymake.core.conf
+++ b/build/ymake.core.conf
@@ -1132,6 +1132,14 @@ when ($ALLOCATOR == "LF") {
SANITIZE_HEADERS=yes
SANITIZER_CFLAGS=
+# tag:profile
+NEED_PROFILE_RUNTIME=no
+when ($BUILD_TYPE == "PROFILE" || $BUILD_TYPE == "COVERAGE" || ($CLANG_COVERAGE && $CLANG_COVERAGE != "no")) {
+ when($CLANG && ($TARGET_PLATFORM == "LINUX" || $TARGET_PLATFORM == "DARWIN")) {
+ NEED_PROFILE_RUNTIME=yes
+ }
+}
+
# tag:proto tag:grpc
_GRPC_ENABLED=no
@@ -1770,6 +1778,11 @@ module _LINK_UNIT: _BASE_UNIT {
LINK_SCRIPT_EXE_FLAGS += --dynamic-cuda
}
+ when ($NEED_PROFILE_RUNTIME && $NEED_PROFILE_RUNTIME != "no") {
+ LDFLAGS+=-resource-dir=contrib/libs/clang-rt
+ PEERDIR+=contrib/libs/clang14-rt/lib/profile
+ }
+
ENABLE(COMMON_LINK_SETTINGS)
CHECK_PROVIDES()
}