2019-08-14 10:47:11 +02:00
|
|
|
//===-- sanitizer_symbolizer_posix_libcdep.cpp ----------------------------===//
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
2013-11-04 22:33:31 +01:00
|
|
|
// run-time libraries.
|
|
|
|
// POSIX-specific implementation of symbolizer parts.
|
2012-11-12 16:53:47 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_platform.h"
|
|
|
|
#if SANITIZER_POSIX
|
|
|
|
#include "sanitizer_allocator_internal.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "sanitizer_common.h"
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
#include "sanitizer_file.h"
|
2014-05-22 09:09:21 +02:00
|
|
|
#include "sanitizer_flags.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_internal_defs.h"
|
|
|
|
#include "sanitizer_linux.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "sanitizer_placement_new.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_posix.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "sanitizer_procmaps.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_symbolizer_internal.h"
|
2013-12-05 10:18:38 +01:00
|
|
|
#include "sanitizer_symbolizer_libbacktrace.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_symbolizer_mac.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#include <dlfcn.h> // for dlsym()
|
2013-11-04 22:33:31 +01:00
|
|
|
#include <errno.h>
|
2016-11-08 23:04:09 +01:00
|
|
|
#include <stdint.h>
|
2013-11-04 22:33:31 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
// C++ demangling function, as required by Itanium C++ ABI. This is weak,
|
|
|
|
// because we do not require a C++ ABI library to be linked to a program
|
|
|
|
// using sanitizers; if it's not present, we'll just use the mangled name.
|
|
|
|
namespace __cxxabiv1 {
|
|
|
|
extern "C" SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
char *__cxa_demangle(const char *mangled, char *buffer,
|
|
|
|
size_t *length, int *status);
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
namespace __sanitizer {
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// Attempts to demangle the name via __cxa_demangle from __cxxabiv1.
|
2015-10-21 09:32:45 +02:00
|
|
|
const char *DemangleCXXABI(const char *name) {
|
2013-11-04 22:33:31 +01:00
|
|
|
// FIXME: __cxa_demangle aggressively insists on allocating memory.
|
|
|
|
// There's not much we can do about that, short of providing our
|
|
|
|
// own demangler (libc++abi's implementation could be adapted so that
|
|
|
|
// it does not allocate). For now, we just call it anyway, and we leak
|
|
|
|
// the returned value.
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (&__cxxabiv1::__cxa_demangle)
|
2013-11-04 22:33:31 +01:00
|
|
|
if (const char *demangled_name =
|
|
|
|
__cxxabiv1::__cxa_demangle(name, 0, 0, 0))
|
|
|
|
return demangled_name;
|
|
|
|
|
|
|
|
return name;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
// As of now, there are no headers for the Swift runtime. Once they are
|
|
|
|
// present, we will weakly link since we do not require Swift runtime to be
|
|
|
|
// linked.
|
|
|
|
typedef char *(*swift_demangle_ft)(const char *mangledName,
|
|
|
|
size_t mangledNameLength, char *outputBuffer,
|
|
|
|
size_t *outputBufferSize, uint32_t flags);
|
|
|
|
static swift_demangle_ft swift_demangle_f;
|
|
|
|
|
|
|
|
// This must not happen lazily at symbolication time, because dlsym uses
|
|
|
|
// malloc and thread-local storage, which is not a good thing to do during
|
|
|
|
// symbolication.
|
|
|
|
static void InitializeSwiftDemangler() {
|
|
|
|
swift_demangle_f = (swift_demangle_ft)dlsym(RTLD_DEFAULT, "swift_demangle");
|
2018-10-31 12:14:23 +01:00
|
|
|
(void)dlerror(); // Cleanup error message in case of failure
|
2016-11-08 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attempts to demangle a Swift name. The demangler will return nullptr if a
|
|
|
|
// non-Swift name is passed in.
|
|
|
|
const char *DemangleSwift(const char *name) {
|
|
|
|
if (swift_demangle_f)
|
|
|
|
return swift_demangle_f(name, internal_strlen(name), 0, 0, 0);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *DemangleSwiftAndCXX(const char *name) {
|
|
|
|
if (!name) return nullptr;
|
|
|
|
if (const char *swift_demangled_name = DemangleSwift(name))
|
|
|
|
return swift_demangled_name;
|
|
|
|
return DemangleCXXABI(name);
|
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
static bool CreateTwoHighNumberedPipes(int *infd_, int *outfd_) {
|
|
|
|
int *infd = NULL;
|
|
|
|
int *outfd = NULL;
|
|
|
|
// The client program may close its stdin and/or stdout and/or stderr
|
|
|
|
// thus allowing socketpair to reuse file descriptors 0, 1 or 2.
|
|
|
|
// In this case the communication between the forked processes may be
|
|
|
|
// broken if either the parent or the child tries to close or duplicate
|
|
|
|
// these descriptors. The loop below produces two pairs of file
|
|
|
|
// descriptors, each greater than 2 (stderr).
|
|
|
|
int sock_pair[5][2];
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
if (pipe(sock_pair[i]) == -1) {
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
internal_close(sock_pair[j][0]);
|
|
|
|
internal_close(sock_pair[j][1]);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else if (sock_pair[i][0] > 2 && sock_pair[i][1] > 2) {
|
|
|
|
if (infd == NULL) {
|
|
|
|
infd = sock_pair[i];
|
|
|
|
} else {
|
|
|
|
outfd = sock_pair[i];
|
|
|
|
for (int j = 0; j < i; j++) {
|
|
|
|
if (sock_pair[j] == infd) continue;
|
|
|
|
internal_close(sock_pair[j][0]);
|
|
|
|
internal_close(sock_pair[j][1]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK(infd);
|
|
|
|
CHECK(outfd);
|
|
|
|
infd_[0] = infd[0];
|
|
|
|
infd_[1] = infd[1];
|
|
|
|
outfd_[0] = outfd[0];
|
|
|
|
outfd_[1] = outfd[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
bool SymbolizerProcess::StartSymbolizerSubprocess() {
|
|
|
|
if (!FileExists(path_)) {
|
|
|
|
if (!reported_invalid_path_) {
|
|
|
|
Report("WARNING: invalid path to external symbolizer!\n");
|
|
|
|
reported_invalid_path_ = true;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
return false;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
const char *argv[kArgVMax];
|
|
|
|
GetArgV(path_, argv);
|
|
|
|
pid_t pid;
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
|
2020-06-01 21:15:18 +02:00
|
|
|
// Report how symbolizer is being launched for debugging purposes.
|
|
|
|
if (Verbosity() >= 3) {
|
|
|
|
// Only use `Report` for first line so subsequent prints don't get prefixed
|
|
|
|
// with current PID.
|
|
|
|
Report("Launching Symbolizer process: ");
|
|
|
|
for (unsigned index = 0; index < kArgVMax && argv[index]; ++index)
|
|
|
|
Printf("%s ", argv[index]);
|
|
|
|
Printf("\n");
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
if (use_posix_spawn_) {
|
2015-10-21 09:32:45 +02:00
|
|
|
#if SANITIZER_MAC
|
2020-06-01 21:15:18 +02:00
|
|
|
fd_t fd = internal_spawn(argv, const_cast<const char **>(GetEnvP()), &pid);
|
2019-11-05 14:54:57 +01:00
|
|
|
if (fd == kInvalidFd) {
|
|
|
|
Report("WARNING: failed to spawn external symbolizer (errno: %d)\n",
|
2015-10-21 09:32:45 +02:00
|
|
|
errno);
|
2014-05-22 09:09:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
input_fd_ = fd;
|
2019-11-05 14:54:57 +01:00
|
|
|
output_fd_ = fd;
|
2015-10-21 09:32:45 +02:00
|
|
|
#else // SANITIZER_MAC
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
#endif // SANITIZER_MAC
|
|
|
|
} else {
|
2019-11-05 14:54:57 +01:00
|
|
|
fd_t infd[2] = {}, outfd[2] = {};
|
|
|
|
if (!CreateTwoHighNumberedPipes(infd, outfd)) {
|
|
|
|
Report("WARNING: Can't create a socket pair to start "
|
|
|
|
"external symbolizer (errno: %d)\n", errno);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-01 21:15:18 +02:00
|
|
|
pid = StartSubprocess(path_, argv, GetEnvP(), /* stdin */ outfd[0],
|
2016-11-08 23:04:09 +01:00
|
|
|
/* stdout */ infd[1]);
|
|
|
|
if (pid < 0) {
|
2014-05-22 09:09:21 +02:00
|
|
|
internal_close(infd[0]);
|
|
|
|
internal_close(outfd[1]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_fd_ = infd[0];
|
|
|
|
output_fd_ = outfd[1];
|
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
CHECK_GT(pid, 0);
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
// Check that symbolizer subprocess started successfully.
|
|
|
|
SleepForMillis(kSymbolizerStartupTimeMillis);
|
2016-11-08 23:04:09 +01:00
|
|
|
if (!IsProcessRunning(pid)) {
|
2015-10-21 09:32:45 +02:00
|
|
|
// Either waitpid failed, or child has already exited.
|
|
|
|
Report("WARNING: external symbolizer didn't start up correctly!\n");
|
|
|
|
return false;
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2020-11-13 17:03:23 +01:00
|
|
|
class Addr2LineProcess final : public SymbolizerProcess {
|
2014-05-22 09:09:21 +02:00
|
|
|
public:
|
|
|
|
Addr2LineProcess(const char *path, const char *module_name)
|
|
|
|
: SymbolizerProcess(path), module_name_(internal_strdup(module_name)) {}
|
|
|
|
|
|
|
|
const char *module_name() const { return module_name_; }
|
|
|
|
|
|
|
|
private:
|
2015-10-21 09:32:45 +02:00
|
|
|
void GetArgV(const char *path_to_binary,
|
|
|
|
const char *(&argv)[kArgVMax]) const override {
|
|
|
|
int i = 0;
|
|
|
|
argv[i++] = path_to_binary;
|
|
|
|
argv[i++] = "-iCfe";
|
|
|
|
argv[i++] = module_name_;
|
|
|
|
argv[i++] = nullptr;
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
bool ReachedEndOfOutput(const char *buffer, uptr length) const override;
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
bool ReadFromSymbolizer(char *buffer, uptr max_length) override {
|
|
|
|
if (!SymbolizerProcess::ReadFromSymbolizer(buffer, max_length))
|
|
|
|
return false;
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
// The returned buffer is empty when output is valid, but exceeds
|
|
|
|
// max_length.
|
|
|
|
if (*buffer == '\0')
|
|
|
|
return true;
|
2015-10-21 09:32:45 +02:00
|
|
|
// We should cut out output_terminator_ at the end of given buffer,
|
|
|
|
// appended by addr2line to mark the end of its meaningful output.
|
|
|
|
// We cannot scan buffer from it's beginning, because it is legal for it
|
|
|
|
// to start with output_terminator_ in case given offset is invalid. So,
|
|
|
|
// scanning from second character.
|
|
|
|
char *garbage = internal_strstr(buffer + 1, output_terminator_);
|
|
|
|
// This should never be NULL since buffer must end up with
|
|
|
|
// output_terminator_.
|
|
|
|
CHECK(garbage);
|
|
|
|
// Trim the buffer.
|
|
|
|
garbage[0] = '\0';
|
|
|
|
return true;
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *module_name_; // Owned, leaked.
|
2015-10-21 09:32:45 +02:00
|
|
|
static const char output_terminator_[];
|
2014-05-22 09:09:21 +02:00
|
|
|
};
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
const char Addr2LineProcess::output_terminator_[] = "??\n??:0\n";
|
|
|
|
|
|
|
|
bool Addr2LineProcess::ReachedEndOfOutput(const char *buffer,
|
|
|
|
uptr length) const {
|
|
|
|
const size_t kTerminatorLen = sizeof(output_terminator_) - 1;
|
|
|
|
// Skip, if we read just kTerminatorLen bytes, because Addr2Line output
|
|
|
|
// should consist at least of two pairs of lines:
|
|
|
|
// 1. First one, corresponding to given offset to be symbolized
|
|
|
|
// (may be equal to output_terminator_, if offset is not valid).
|
|
|
|
// 2. Second one for output_terminator_, itself to mark the end of output.
|
|
|
|
if (length <= kTerminatorLen) return false;
|
|
|
|
// Addr2Line output should end up with output_terminator_.
|
|
|
|
return !internal_memcmp(buffer + length - kTerminatorLen,
|
|
|
|
output_terminator_, kTerminatorLen);
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:03:23 +01:00
|
|
|
class Addr2LinePool final : public SymbolizerTool {
|
2014-05-22 09:09:21 +02:00
|
|
|
public:
|
|
|
|
explicit Addr2LinePool(const char *addr2line_path,
|
|
|
|
LowLevelAllocator *allocator)
|
2018-10-31 12:14:23 +01:00
|
|
|
: addr2line_path_(addr2line_path), allocator_(allocator) {
|
|
|
|
addr2line_pool_.reserve(16);
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override {
|
|
|
|
if (const char *buf =
|
|
|
|
SendCommand(stack->info.module, stack->info.module_offset)) {
|
|
|
|
ParseSymbolizePCOutput(buf, stack);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolizeData(uptr addr, DataInfo *info) override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *SendCommand(const char *module_name, uptr module_offset) {
|
2014-05-22 09:09:21 +02:00
|
|
|
Addr2LineProcess *addr2line = 0;
|
|
|
|
for (uptr i = 0; i < addr2line_pool_.size(); ++i) {
|
|
|
|
if (0 ==
|
|
|
|
internal_strcmp(module_name, addr2line_pool_[i]->module_name())) {
|
|
|
|
addr2line = addr2line_pool_[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!addr2line) {
|
|
|
|
addr2line =
|
|
|
|
new(*allocator_) Addr2LineProcess(addr2line_path_, module_name);
|
|
|
|
addr2line_pool_.push_back(addr2line);
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
CHECK_EQ(0, internal_strcmp(module_name, addr2line->module_name()));
|
|
|
|
char buffer[kBufferSize];
|
|
|
|
internal_snprintf(buffer, kBufferSize, "0x%zx\n0x%zx\n",
|
|
|
|
module_offset, dummy_address_);
|
|
|
|
return addr2line->SendCommand(buffer);
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
static const uptr kBufferSize = 64;
|
2014-05-22 09:09:21 +02:00
|
|
|
const char *addr2line_path_;
|
|
|
|
LowLevelAllocator *allocator_;
|
|
|
|
InternalMmapVector<Addr2LineProcess*> addr2line_pool_;
|
2015-10-21 09:32:45 +02:00
|
|
|
static const uptr dummy_address_ =
|
|
|
|
FIRST_32_SECOND_64(UINT32_MAX, UINT64_MAX);
|
2012-11-12 16:53:47 +01:00
|
|
|
};
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
#if SANITIZER_SUPPORTS_WEAK_HOOKS
|
|
|
|
extern "C" {
|
2020-10-16 10:03:04 +02:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE bool
|
|
|
|
__sanitizer_symbolize_code(const char *ModuleName, u64 ModuleOffset,
|
|
|
|
char *Buffer, int MaxLength,
|
|
|
|
bool SymbolizeInlineFrames);
|
2013-11-04 22:33:31 +01:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
2013-02-13 11:46:01 +01:00
|
|
|
bool __sanitizer_symbolize_data(const char *ModuleName, u64 ModuleOffset,
|
|
|
|
char *Buffer, int MaxLength);
|
2013-11-04 22:33:31 +01:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
void __sanitizer_symbolize_flush();
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
int __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
|
|
|
|
int MaxLength);
|
2013-02-13 11:46:01 +01:00
|
|
|
} // extern "C"
|
|
|
|
|
2020-11-13 17:03:23 +01:00
|
|
|
class InternalSymbolizer final : public SymbolizerTool {
|
2013-02-13 11:46:01 +01:00
|
|
|
public:
|
2013-12-05 10:18:38 +01:00
|
|
|
static InternalSymbolizer *get(LowLevelAllocator *alloc) {
|
2013-02-13 11:46:01 +01:00
|
|
|
if (__sanitizer_symbolize_code != 0 &&
|
|
|
|
__sanitizer_symbolize_data != 0) {
|
2013-12-05 10:18:38 +01:00
|
|
|
return new(*alloc) InternalSymbolizer();
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override {
|
|
|
|
bool result = __sanitizer_symbolize_code(
|
2020-10-16 10:03:04 +02:00
|
|
|
stack->info.module, stack->info.module_offset, buffer_, kBufferSize,
|
|
|
|
common_flags()->symbolize_inline_frames);
|
2015-10-21 09:32:45 +02:00
|
|
|
if (result) ParseSymbolizePCOutput(buffer_, stack);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SymbolizeData(uptr addr, DataInfo *info) override {
|
|
|
|
bool result = __sanitizer_symbolize_data(info->module, info->module_offset,
|
|
|
|
buffer_, kBufferSize);
|
|
|
|
if (result) {
|
|
|
|
ParseSymbolizeDataOutput(buffer_, info);
|
|
|
|
info->start += (addr - info->module_offset); // Add the base address.
|
|
|
|
}
|
|
|
|
return result;
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
void Flush() override {
|
2013-11-04 22:33:31 +01:00
|
|
|
if (__sanitizer_symbolize_flush)
|
|
|
|
__sanitizer_symbolize_flush();
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
const char *Demangle(const char *name) override {
|
2013-11-04 22:33:31 +01:00
|
|
|
if (__sanitizer_symbolize_demangle) {
|
|
|
|
for (uptr res_length = 1024;
|
|
|
|
res_length <= InternalSizeClassMap::kMaxSize;) {
|
|
|
|
char *res_buff = static_cast<char*>(InternalAlloc(res_length));
|
|
|
|
uptr req_length =
|
|
|
|
__sanitizer_symbolize_demangle(name, res_buff, res_length);
|
|
|
|
if (req_length > res_length) {
|
|
|
|
res_length = req_length + 1;
|
|
|
|
InternalFree(res_buff);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return res_buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
private:
|
|
|
|
InternalSymbolizer() { }
|
|
|
|
|
|
|
|
static const int kBufferSize = 16 * 1024;
|
|
|
|
char buffer_[kBufferSize];
|
|
|
|
};
|
|
|
|
#else // SANITIZER_SUPPORTS_WEAK_HOOKS
|
|
|
|
|
2020-11-13 17:03:23 +01:00
|
|
|
class InternalSymbolizer final : public SymbolizerTool {
|
2013-02-13 11:46:01 +01:00
|
|
|
public:
|
2013-12-05 10:18:38 +01:00
|
|
|
static InternalSymbolizer *get(LowLevelAllocator *alloc) { return 0; }
|
2013-02-13 11:46:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SANITIZER_SUPPORTS_WEAK_HOOKS
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
const char *Symbolizer::PlatformDemangle(const char *name) {
|
2016-11-08 23:04:09 +01:00
|
|
|
return DemangleSwiftAndCXX(name);
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
static SymbolizerTool *ChooseExternalSymbolizer(LowLevelAllocator *allocator) {
|
|
|
|
const char *path = common_flags()->external_symbolizer_path;
|
2021-05-12 14:37:22 +02:00
|
|
|
|
|
|
|
if (path && internal_strchr(path, '%')) {
|
|
|
|
char *new_path = (char *)InternalAlloc(kMaxPathLength);
|
|
|
|
SubstituteForFlagValue(path, new_path, kMaxPathLength);
|
|
|
|
path = new_path;
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
const char *binary_name = path ? StripModuleName(path) : "";
|
2021-05-12 14:37:22 +02:00
|
|
|
static const char kLLVMSymbolizerPrefix[] = "llvm-symbolizer";
|
2015-10-21 09:32:45 +02:00
|
|
|
if (path && path[0] == '\0') {
|
|
|
|
VReport(2, "External symbolizer is explicitly disabled.\n");
|
|
|
|
return nullptr;
|
2021-05-12 14:37:22 +02:00
|
|
|
} else if (!internal_strncmp(binary_name, kLLVMSymbolizerPrefix,
|
|
|
|
internal_strlen(kLLVMSymbolizerPrefix))) {
|
2015-10-21 09:32:45 +02:00
|
|
|
VReport(2, "Using llvm-symbolizer at user-specified path: %s\n", path);
|
|
|
|
return new(*allocator) LLVMSymbolizer(path, allocator);
|
|
|
|
} else if (!internal_strcmp(binary_name, "atos")) {
|
|
|
|
#if SANITIZER_MAC
|
|
|
|
VReport(2, "Using atos at user-specified path: %s\n", path);
|
|
|
|
return new(*allocator) AtosSymbolizer(path, allocator);
|
|
|
|
#else // SANITIZER_MAC
|
|
|
|
Report("ERROR: Using `atos` is only supported on Darwin.\n");
|
|
|
|
Die();
|
|
|
|
#endif // SANITIZER_MAC
|
|
|
|
} else if (!internal_strcmp(binary_name, "addr2line")) {
|
|
|
|
VReport(2, "Using addr2line at user-specified path: %s\n", path);
|
|
|
|
return new(*allocator) Addr2LinePool(path, allocator);
|
|
|
|
} else if (path) {
|
|
|
|
Report("ERROR: External symbolizer path is set to '%s' which isn't "
|
|
|
|
"a known symbolizer. Please set the path to the llvm-symbolizer "
|
|
|
|
"binary or other known tool.\n", path);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise symbolizer program is unknown, let's search $PATH
|
|
|
|
CHECK(path == nullptr);
|
|
|
|
#if SANITIZER_MAC
|
|
|
|
if (const char *found_path = FindPathToBinary("atos")) {
|
|
|
|
VReport(2, "Using atos found at: %s\n", found_path);
|
|
|
|
return new(*allocator) AtosSymbolizer(found_path, allocator);
|
|
|
|
}
|
|
|
|
#endif // SANITIZER_MAC
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (const char *found_path = FindPathToBinary("llvm-symbolizer")) {
|
|
|
|
VReport(2, "Using llvm-symbolizer found at: %s\n", found_path);
|
|
|
|
return new(*allocator) LLVMSymbolizer(found_path, allocator);
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
if (common_flags()->allow_addr2line) {
|
|
|
|
if (const char *found_path = FindPathToBinary("addr2line")) {
|
|
|
|
VReport(2, "Using addr2line found at: %s\n", found_path);
|
|
|
|
return new(*allocator) Addr2LinePool(found_path, allocator);
|
2013-12-05 10:18:38 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
static void ChooseSymbolizerTools(IntrusiveList<SymbolizerTool> *list,
|
|
|
|
LowLevelAllocator *allocator) {
|
|
|
|
if (!common_flags()->symbolize) {
|
|
|
|
VReport(2, "Symbolizer is disabled.\n");
|
|
|
|
return;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (IsAllocatorOutOfMemory()) {
|
2016-11-08 23:04:09 +01:00
|
|
|
VReport(2, "Cannot use internal symbolizer: out of memory\n");
|
|
|
|
} else if (SymbolizerTool *tool = InternalSymbolizer::get(allocator)) {
|
2015-10-21 09:32:45 +02:00
|
|
|
VReport(2, "Using internal symbolizer.\n");
|
|
|
|
list->push_back(tool);
|
|
|
|
return;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
if (SymbolizerTool *tool = LibbacktraceSymbolizer::get(allocator)) {
|
|
|
|
VReport(2, "Using libbacktrace symbolizer.\n");
|
|
|
|
list->push_back(tool);
|
|
|
|
return;
|
2013-01-23 12:41:33 +01:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
if (SymbolizerTool *tool = ChooseExternalSymbolizer(allocator)) {
|
|
|
|
list->push_back(tool);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#if SANITIZER_MAC
|
|
|
|
VReport(2, "Using dladdr symbolizer.\n");
|
|
|
|
list->push_back(new(*allocator) DlAddrSymbolizer());
|
|
|
|
#endif // SANITIZER_MAC
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
Symbolizer *Symbolizer::PlatformInit() {
|
2015-10-21 09:32:45 +02:00
|
|
|
IntrusiveList<SymbolizerTool> list;
|
|
|
|
list.clear();
|
|
|
|
ChooseSymbolizerTools(&list, &symbolizer_allocator_);
|
|
|
|
return new(symbolizer_allocator_) Symbolizer(list);
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
void Symbolizer::LateInitialize() {
|
2020-06-01 21:15:18 +02:00
|
|
|
Symbolizer::GetOrInit()->LateInitializeTools();
|
2016-11-08 23:04:09 +01:00
|
|
|
InitializeSwiftDemangler();
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
} // namespace __sanitizer
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
#endif // SANITIZER_POSIX
|