5d3805fca3
* 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
151 lines
5.1 KiB
C++
151 lines
5.1 KiB
C++
//===-- sanitizer_symbolizer_internal.h -------------------------*- C++ -*-===//
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Header for internal classes and functions to be used by implementations of
|
|
// symbolizers.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef SANITIZER_SYMBOLIZER_INTERNAL_H
|
|
#define SANITIZER_SYMBOLIZER_INTERNAL_H
|
|
|
|
#include "sanitizer_symbolizer.h"
|
|
#include "sanitizer_file.h"
|
|
|
|
namespace __sanitizer {
|
|
|
|
// Parsing helpers, 'str' is searched for delimiter(s) and a string or uptr
|
|
// is extracted. When extracting a string, a newly allocated (using
|
|
// InternalAlloc) and null-terminataed buffer is returned. They return a pointer
|
|
// to the next characted after the found delimiter.
|
|
const char *ExtractToken(const char *str, const char *delims, char **result);
|
|
const char *ExtractInt(const char *str, const char *delims, int *result);
|
|
const char *ExtractUptr(const char *str, const char *delims, uptr *result);
|
|
const char *ExtractTokenUpToDelimiter(const char *str, const char *delimiter,
|
|
char **result);
|
|
|
|
const char *DemangleSwiftAndCXX(const char *name);
|
|
|
|
// SymbolizerTool is an interface that is implemented by individual "tools"
|
|
// that can perform symbolication (external llvm-symbolizer, libbacktrace,
|
|
// Windows DbgHelp symbolizer, etc.).
|
|
class SymbolizerTool {
|
|
public:
|
|
// The main |Symbolizer| class implements a "fallback chain" of symbolizer
|
|
// tools. In a request to symbolize an address, if one tool returns false,
|
|
// the next tool in the chain will be tried.
|
|
SymbolizerTool *next;
|
|
|
|
SymbolizerTool() : next(nullptr) { }
|
|
|
|
// Can't declare pure virtual functions in sanitizer runtimes:
|
|
// __cxa_pure_virtual might be unavailable.
|
|
|
|
// The |stack| parameter is inout. It is pre-filled with the address,
|
|
// module base and module offset values and is to be used to construct
|
|
// other stack frames.
|
|
virtual bool SymbolizePC(uptr addr, SymbolizedStack *stack) {
|
|
UNIMPLEMENTED();
|
|
}
|
|
|
|
// The |info| parameter is inout. It is pre-filled with the module base
|
|
// and module offset values.
|
|
virtual bool SymbolizeData(uptr addr, DataInfo *info) {
|
|
UNIMPLEMENTED();
|
|
}
|
|
|
|
virtual void Flush() {}
|
|
|
|
// Return nullptr to fallback to the default platform-specific demangler.
|
|
virtual const char *Demangle(const char *name) {
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
// SymbolizerProcess encapsulates communication between the tool and
|
|
// external symbolizer program, running in a different subprocess.
|
|
// SymbolizerProcess may not be used from two threads simultaneously.
|
|
class SymbolizerProcess {
|
|
public:
|
|
explicit SymbolizerProcess(const char *path, bool use_forkpty = false);
|
|
const char *SendCommand(const char *command);
|
|
|
|
protected:
|
|
virtual bool ReachedEndOfOutput(const char *buffer, uptr length) const {
|
|
UNIMPLEMENTED();
|
|
}
|
|
|
|
/// The maximum number of arguments required to invoke a tool process.
|
|
enum { kArgVMax = 6 };
|
|
|
|
/// Fill in an argv array to invoke the child process.
|
|
virtual void GetArgV(const char *path_to_binary,
|
|
const char *(&argv)[kArgVMax]) const {
|
|
UNIMPLEMENTED();
|
|
}
|
|
|
|
virtual bool ReadFromSymbolizer(char *buffer, uptr max_length);
|
|
|
|
private:
|
|
bool Restart();
|
|
const char *SendCommandImpl(const char *command);
|
|
bool WriteToSymbolizer(const char *buffer, uptr length);
|
|
bool StartSymbolizerSubprocess();
|
|
|
|
const char *path_;
|
|
fd_t input_fd_;
|
|
fd_t output_fd_;
|
|
|
|
static const uptr kBufferSize = 16 * 1024;
|
|
char buffer_[kBufferSize];
|
|
|
|
static const uptr kMaxTimesRestarted = 5;
|
|
static const int kSymbolizerStartupTimeMillis = 10;
|
|
uptr times_restarted_;
|
|
bool failed_to_start_;
|
|
bool reported_invalid_path_;
|
|
bool use_forkpty_;
|
|
};
|
|
|
|
class LLVMSymbolizerProcess;
|
|
|
|
// This tool invokes llvm-symbolizer in a subprocess. It should be as portable
|
|
// as the llvm-symbolizer tool is.
|
|
class LLVMSymbolizer : public SymbolizerTool {
|
|
public:
|
|
explicit LLVMSymbolizer(const char *path, LowLevelAllocator *allocator);
|
|
|
|
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override;
|
|
|
|
bool SymbolizeData(uptr addr, DataInfo *info) override;
|
|
|
|
private:
|
|
const char *FormatAndSendCommand(bool is_data, const char *module_name,
|
|
uptr module_offset, ModuleArch arch);
|
|
|
|
LLVMSymbolizerProcess *symbolizer_process_;
|
|
static const uptr kBufferSize = 16 * 1024;
|
|
char buffer_[kBufferSize];
|
|
};
|
|
|
|
// Parses one or more two-line strings in the following format:
|
|
// <function_name>
|
|
// <file_name>:<line_number>[:<column_number>]
|
|
// Used by LLVMSymbolizer, Addr2LinePool and InternalSymbolizer, since all of
|
|
// them use the same output format. Returns true if any useful debug
|
|
// information was found.
|
|
void ParseSymbolizePCOutput(const char *str, SymbolizedStack *res);
|
|
|
|
// Parses a two-line string in the following format:
|
|
// <symbol_name>
|
|
// <start_address> <size>
|
|
// Used by LLVMSymbolizer and InternalSymbolizer.
|
|
void ParseSymbolizeDataOutput(const char *str, DataInfo *info);
|
|
|
|
} // namespace __sanitizer
|
|
|
|
#endif // SANITIZER_SYMBOLIZER_INTERNAL_H
|