aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-12-03 08:17:42 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-12-03 08:17:42 +0000
commit003b31a5bdd9d6044c663395cd47c8ae02bc0bb3 (patch)
tree3022d7410f28c43f25a12f83e2a71805c15f3345 /library/cpp
parent8bff90900d44219771668e8c37e67c9cbe68fc8e (diff)
parentb0c2229a8d320931b2a986503a39f0f805956f11 (diff)
downloadydb-003b31a5bdd9d6044c663395cd47c8ae02bc0bb3.tar.gz
Merge branch 'rightlib' into mergelibs-241203-0816
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/netliba/socket/creators.cpp2
-rw-r--r--library/cpp/sanitizer/address/static/ya.make2
-rw-r--r--library/cpp/sanitizer/memory/static/ya.make2
-rw-r--r--library/cpp/sanitizer/thread/static/ya.make2
-rw-r--r--library/cpp/testing/dump_clang_coverage/write_profile_data.cpp125
-rw-r--r--library/cpp/testing/dump_clang_coverage/ya.make13
6 files changed, 139 insertions, 7 deletions
diff --git a/library/cpp/netliba/socket/creators.cpp b/library/cpp/netliba/socket/creators.cpp
index 3821bf55b9..f9a3b9830c 100644
--- a/library/cpp/netliba/socket/creators.cpp
+++ b/library/cpp/netliba/socket/creators.cpp
@@ -61,7 +61,7 @@ namespace NNetlibaSocket {
*(ui8*)CMSG_DATA(cmsgTos) = tos;
#endif
- if (*(ui64*)myAddr.sin6_addr.s6_addr != 0u) {
+ if (((ui64*)myAddr.sin6_addr.s6_addr)[0] != 0u || ((ui64*)myAddr.sin6_addr.s6_addr)[1] != 0u) {
in6_pktinfo* pktInfo;
#ifdef _cygwin_
cmsghdr* cmsgAddr = CMSG_FIRSTHDR(header);
diff --git a/library/cpp/sanitizer/address/static/ya.make b/library/cpp/sanitizer/address/static/ya.make
index d8cf24a848..7210cbced9 100644
--- a/library/cpp/sanitizer/address/static/ya.make
+++ b/library/cpp/sanitizer/address/static/ya.make
@@ -1,7 +1,5 @@
LIBRARY()
-SUBSCRIBER(g:devtools-contrib)
-
NO_UTIL()
PEERDIR(
diff --git a/library/cpp/sanitizer/memory/static/ya.make b/library/cpp/sanitizer/memory/static/ya.make
index ab10fb9c88..0955ec62d8 100644
--- a/library/cpp/sanitizer/memory/static/ya.make
+++ b/library/cpp/sanitizer/memory/static/ya.make
@@ -1,7 +1,5 @@
LIBRARY()
-SUBSCRIBER(g:devtools-contrib)
-
NO_UTIL()
PEERDIR(
diff --git a/library/cpp/sanitizer/thread/static/ya.make b/library/cpp/sanitizer/thread/static/ya.make
index 0a09b0098c..7cbd7b9fd5 100644
--- a/library/cpp/sanitizer/thread/static/ya.make
+++ b/library/cpp/sanitizer/thread/static/ya.make
@@ -1,7 +1,5 @@
LIBRARY()
-SUBSCRIBER(g:devtools-contrib)
-
NO_UTIL()
PEERDIR(
diff --git a/library/cpp/testing/dump_clang_coverage/write_profile_data.cpp b/library/cpp/testing/dump_clang_coverage/write_profile_data.cpp
new file mode 100644
index 0000000000..8b13474cc8
--- /dev/null
+++ b/library/cpp/testing/dump_clang_coverage/write_profile_data.cpp
@@ -0,0 +1,125 @@
+#include <dlfcn.h>
+#include <linux/limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+extern "C" {
+ void __llvm_profile_initialize_file(void);
+ int __llvm_profile_write_file(void);
+ void __llvm_profile_set_filename(const char* filename_pattern);
+
+ // there might no llmv rt, for example for the targets from contrib
+ __attribute__((weak)) int __llvm_profile_write_file(void) {
+ return 0;
+ }
+ __attribute__((weak)) void __llvm_profile_initialize_file(void) {
+ }
+ __attribute__((weak)) void __llvm_profile_set_filename(const char*) {
+ }
+}
+
+namespace {
+ void dummy() {
+ }
+}
+
+bool getSoName(char* buff, size_t size) {
+ // returns so name for shared objects and exe_name for binaries
+ Dl_info dl_info = {0, 0, 0, 0};
+ if (dladdr((void*)(intptr_t)dummy, &dl_info) != 0) {
+ if (dl_info.dli_fname) {
+ const char* name = dl_info.dli_fname;
+ char real_path[PATH_MAX];
+ const char* resolved = realpath(name, real_path);
+ if (resolved != NULL)
+ name = real_path;
+ const char* lastSlash = strrchr(name, '/');
+ if (!!lastSlash) {
+ name = lastSlash + 1;
+ }
+ strncpy(buff, name, size);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool getExeName(char* buff, size_t size) {
+ ssize_t len = readlink("/proc/self/exe", buff, size);
+ if (len <= 0) {
+ return false;
+ }
+
+ buff[len] = '\0';
+ char* lastSlash = strrchr(buff, '/');
+ if (!!lastSlash) {
+ strncpy(buff, lastSlash + 1, size);
+ buff[(buff + len) - lastSlash] = '\0';
+ }
+ return true;
+}
+
+bool getSelfName(char* buff, size_t size) {
+#if defined(_musl_)
+ return getExeName(buff, size);
+#else
+ return getSoName(buff, size);
+#endif
+}
+
+void replaceFirst(char* data, size_t dsize, const char* pat, size_t psize, const char* repl, size_t rsize) {
+ char* patPtr = strstr(data, pat);
+ if (!patPtr) {
+ return;
+ }
+
+ char tmp[PATH_MAX] = {0};
+ char* tmpPtr = &tmp[0];
+
+ strcpy(tmpPtr, patPtr + psize);
+ strcpy(patPtr, repl);
+ strcpy(patPtr + rsize, tmpPtr);
+ data[dsize - psize + rsize] = '\0';
+}
+
+// Adds support of the specifier '%e' (executable filename (without path prefix)) to the LLVM_PROFILE_FILE
+void parseAndSetFilename() {
+ const char* profile_file = getenv("LLVM_PROFILE_FILE");
+ if (!profile_file)
+ return;
+
+ // __llvm_profile_set_filename doesn't copy name, so it must remain valid
+ static char pattern[PATH_MAX] = {0};
+ char* patternPtr = &pattern[0];
+
+ strncpy(patternPtr, profile_file, PATH_MAX - 1);
+
+ if (!!strstr(patternPtr, "%e")) {
+ char buff[PATH_MAX] = {0};
+ char* buffPtr = &buff[0];
+
+ if (getSelfName(buffPtr, PATH_MAX)) {
+ size_t patternSize = strlen(patternPtr);
+ size_t buffSize = strlen(buffPtr);
+
+ if (patternSize + buffSize >= PATH_MAX) {
+ abort();
+ }
+ replaceFirst(patternPtr, patternSize, "%e", 2, buffPtr, buffSize);
+ }
+ }
+
+ __llvm_profile_set_filename(patternPtr);
+}
+
+void __attribute__((constructor)) premain() {
+ parseAndSetFilename();
+ if (getenv("YA_COVERAGE_DUMP_PROFILE_AND_EXIT")) {
+ __llvm_profile_initialize_file();
+ int rc = __llvm_profile_write_file();
+ if (!rc && getenv("YA_COVERAGE_DUMP_PROFILE_EXIT_CODE"))
+ rc = atoi(getenv("YA_COVERAGE_DUMP_PROFILE_EXIT_CODE"));
+ exit(rc);
+ }
+}
diff --git a/library/cpp/testing/dump_clang_coverage/ya.make b/library/cpp/testing/dump_clang_coverage/ya.make
new file mode 100644
index 0000000000..26eb36048c
--- /dev/null
+++ b/library/cpp/testing/dump_clang_coverage/ya.make
@@ -0,0 +1,13 @@
+LIBRARY()
+
+NO_CLANG_COVERAGE()
+
+NO_RUNTIME()
+
+IF (OS_LINUX)
+ SRCS(
+ GLOBAL write_profile_data.cpp
+ )
+ENDIF()
+
+END()