diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-04 22:11:33 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-04 22:11:33 +0000 |
commit | dad1defd96f21c31ea21e4d4b6f969641fe368f8 (patch) | |
tree | 8296a52897371e591d0cef49bf6fa240975d7feb | |
parent | 316d58822dada9440bd06ecfc758dcc2364d617c (diff) | |
download | src-dad1defd96f21c31ea21e4d4b6f969641fe368f8.tar.gz src-dad1defd96f21c31ea21e4d4b6f969641fe368f8.zip |
Vendor import of compiler-rt trunk r291012:vendor/compiler-rt/compiler-rt-trunk-r291015vendor/compiler-rt/compiler-rt-trunk-r291012
Notes
Notes:
svn path=/vendor/compiler-rt/dist/; revision=311319
svn path=/vendor/compiler-rt/compiler-rt-trunk-r291012/dist/; revision=311332; tag=vendor/compiler-rt/compiler-rt-trunk-r291015
-rw-r--r-- | CMakeLists.txt | 11 | ||||
-rw-r--r-- | lib/xray/xray_inmemory_log.cc | 21 | ||||
-rw-r--r-- | test/xray/TestCases/Linux/argv0-log-file-name.cc | 14 |
3 files changed, 40 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b1591e8a4b5..e8326f04b810 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,6 +225,17 @@ append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) # Warnings to turn off for all libraries, not just sanitizers. append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS) +if (CMAKE_LINKER MATCHES "link.exe$") + # Silence MSVC linker warnings caused by empty object files. The + # sanitizer libraries intentionally use ifdefs that result in empty + # files, rather than skipping these files in the build system. + # Ideally, we would pass this flag only for the libraries that need + # it, but CMake doesn't seem to have a way to set linker flags for + # individual static libraries, so we enable the suppression flag for + # the whole compiler-rt project. + append("/IGNORE:4221" CMAKE_STATIC_LINKER_FLAGS) +endif() + add_subdirectory(include) set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx) diff --git a/lib/xray/xray_inmemory_log.cc b/lib/xray/xray_inmemory_log.cc index 7ec56f486707..adcb21671cbc 100644 --- a/lib/xray/xray_inmemory_log.cc +++ b/lib/xray/xray_inmemory_log.cc @@ -112,14 +112,23 @@ static int __xray_OpenLogFile() XRAY_NEVER_INSTRUMENT { // Open a temporary file once for the log. static char TmpFilename[256] = {}; static char TmpWildcardPattern[] = "XXXXXX"; - auto E = internal_strncat(TmpFilename, flags()->xray_logfile_base, - sizeof(TmpFilename) - 10); - if (static_cast<size_t>((E + 6) - TmpFilename) > (sizeof(TmpFilename) - 1)) { - Report("XRay log file base too long: %s\n", flags()->xray_logfile_base); + auto Argv = GetArgv(); + const char *Progname = Argv[0] == nullptr ? "(unknown)" : Argv[0]; + const char *LastSlash = internal_strrchr(Progname, '/'); + + if (LastSlash != nullptr) + Progname = LastSlash + 1; + + const int HalfLength = sizeof(TmpFilename) / 2 - sizeof(TmpWildcardPattern); + int NeededLength = internal_snprintf(TmpFilename, sizeof(TmpFilename), + "%.*s%.*s.%s", + HalfLength, flags()->xray_logfile_base, + HalfLength, Progname, + TmpWildcardPattern); + if (NeededLength > int(sizeof(TmpFilename))) { + Report("XRay log file name too long (%d): %s\n", NeededLength, TmpFilename); return -1; } - internal_strncat(TmpFilename, TmpWildcardPattern, - sizeof(TmpWildcardPattern) - 1); int Fd = mkstemp(TmpFilename); if (Fd == -1) { Report("XRay: Failed opening temporary file '%s'; not logging events.\n", diff --git a/test/xray/TestCases/Linux/argv0-log-file-name.cc b/test/xray/TestCases/Linux/argv0-log-file-name.cc new file mode 100644 index 000000000000..1765ce9b5ba1 --- /dev/null +++ b/test/xray/TestCases/Linux/argv0-log-file-name.cc @@ -0,0 +1,14 @@ +// Check to make sure argv[0] is contained within the (randomised) XRay log file +// name. + +// RUN: %clangxx_xray -std=c++11 %s -o %t +// RUN: %run %t > xray.log.file.name 2>&1 +// RUN: ls | FileCheck xray.log.file.name +// RUN: rm xray-log.* xray.log.file.name + +#include <cstdio> +#include <libgen.h> + +[[clang::xray_always_instrument]] int main(int argc, char *argv[]) { + printf("// CHECK: xray-log.%s.{{.*}}\n", basename(argv[0])); +} |