From 3a1720af1d7f43edc5b214cde0be11bfb94d077e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 23 Oct 2019 17:52:22 +0000 Subject: Vendor import of stripped compiler-rt trunk r375505, the last commit before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505 --- .../symbolizer/sanitizer_symbolize.cc | 80 --------- .../symbolizer/sanitizer_symbolize.cpp | 80 +++++++++ .../symbolizer/sanitizer_wrappers.cc | 198 --------------------- .../symbolizer/sanitizer_wrappers.cpp | 198 +++++++++++++++++++++ .../symbolizer/scripts/build_symbolizer.sh | 34 +++- .../symbolizer/scripts/global_symbols.txt | 7 + 6 files changed, 310 insertions(+), 287 deletions(-) delete mode 100644 lib/sanitizer_common/symbolizer/sanitizer_symbolize.cc create mode 100644 lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp delete mode 100644 lib/sanitizer_common/symbolizer/sanitizer_wrappers.cc create mode 100644 lib/sanitizer_common/symbolizer/sanitizer_wrappers.cpp (limited to 'lib/sanitizer_common/symbolizer') diff --git a/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cc b/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cc deleted file mode 100644 index 8150b7a09a0e4..0000000000000 --- a/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cc +++ /dev/null @@ -1,80 +0,0 @@ -//===-- sanitizer_symbolize.cc ----------------------------------*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// Implementation of weak hooks from sanitizer_symbolizer_posix_libcdep.cc. -// -//===----------------------------------------------------------------------===// - -#include -#include - -#include "llvm/DebugInfo/Symbolize/DIPrinter.h" -#include "llvm/DebugInfo/Symbolize/Symbolize.h" - -static llvm::symbolize::LLVMSymbolizer *getDefaultSymbolizer() { - static llvm::symbolize::LLVMSymbolizer *DefaultSymbolizer = - new llvm::symbolize::LLVMSymbolizer(); - return DefaultSymbolizer; -} - -namespace __sanitizer { -int internal_snprintf(char *buffer, unsigned long length, const char *format, - ...); -} // namespace __sanitizer - -extern "C" { - -typedef uint64_t u64; - -bool __sanitizer_symbolize_code(const char *ModuleName, uint64_t ModuleOffset, - char *Buffer, int MaxLength) { - std::string Result; - { - llvm::raw_string_ostream OS(Result); - llvm::symbolize::DIPrinter Printer(OS); - // TODO: it is neccessary to set proper SectionIndex here. - // object::SectionedAddress::UndefSection works for only absolute addresses. - auto ResOrErr = getDefaultSymbolizer()->symbolizeInlinedCode( - ModuleName, - {ModuleOffset, llvm::object::SectionedAddress::UndefSection}); - Printer << (ResOrErr ? ResOrErr.get() : llvm::DIInliningInfo()); - } - return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", - Result.c_str()) < MaxLength; -} - -bool __sanitizer_symbolize_data(const char *ModuleName, uint64_t ModuleOffset, - char *Buffer, int MaxLength) { - std::string Result; - { - llvm::raw_string_ostream OS(Result); - llvm::symbolize::DIPrinter Printer(OS); - // TODO: it is neccessary to set proper SectionIndex here. - // object::SectionedAddress::UndefSection works for only absolute addresses. - auto ResOrErr = getDefaultSymbolizer()->symbolizeData( - ModuleName, - {ModuleOffset, llvm::object::SectionedAddress::UndefSection}); - Printer << (ResOrErr ? ResOrErr.get() : llvm::DIGlobal()); - } - return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", - Result.c_str()) < MaxLength; -} - -void __sanitizer_symbolize_flush() { getDefaultSymbolizer()->flush(); } - -int __sanitizer_symbolize_demangle(const char *Name, char *Buffer, - int MaxLength) { - std::string Result = - llvm::symbolize::LLVMSymbolizer::DemangleName(Name, nullptr); - return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", - Result.c_str()) < MaxLength - ? static_cast(Result.size() + 1) - : 0; -} - -} // extern "C" diff --git a/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp b/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp new file mode 100644 index 0000000000000..ba285bc1e8844 --- /dev/null +++ b/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp @@ -0,0 +1,80 @@ +//===-- sanitizer_symbolize.cpp ---------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// Implementation of weak hooks from sanitizer_symbolizer_posix_libcdep.cpp. +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "llvm/DebugInfo/Symbolize/DIPrinter.h" +#include "llvm/DebugInfo/Symbolize/Symbolize.h" + +static llvm::symbolize::LLVMSymbolizer *getDefaultSymbolizer() { + static llvm::symbolize::LLVMSymbolizer *DefaultSymbolizer = + new llvm::symbolize::LLVMSymbolizer(); + return DefaultSymbolizer; +} + +namespace __sanitizer { +int internal_snprintf(char *buffer, unsigned long length, const char *format, + ...); +} // namespace __sanitizer + +extern "C" { + +typedef uint64_t u64; + +bool __sanitizer_symbolize_code(const char *ModuleName, uint64_t ModuleOffset, + char *Buffer, int MaxLength) { + std::string Result; + { + llvm::raw_string_ostream OS(Result); + llvm::symbolize::DIPrinter Printer(OS); + // TODO: it is neccessary to set proper SectionIndex here. + // object::SectionedAddress::UndefSection works for only absolute addresses. + auto ResOrErr = getDefaultSymbolizer()->symbolizeInlinedCode( + ModuleName, + {ModuleOffset, llvm::object::SectionedAddress::UndefSection}); + Printer << (ResOrErr ? ResOrErr.get() : llvm::DIInliningInfo()); + } + return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", + Result.c_str()) < MaxLength; +} + +bool __sanitizer_symbolize_data(const char *ModuleName, uint64_t ModuleOffset, + char *Buffer, int MaxLength) { + std::string Result; + { + llvm::raw_string_ostream OS(Result); + llvm::symbolize::DIPrinter Printer(OS); + // TODO: it is neccessary to set proper SectionIndex here. + // object::SectionedAddress::UndefSection works for only absolute addresses. + auto ResOrErr = getDefaultSymbolizer()->symbolizeData( + ModuleName, + {ModuleOffset, llvm::object::SectionedAddress::UndefSection}); + Printer << (ResOrErr ? ResOrErr.get() : llvm::DIGlobal()); + } + return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", + Result.c_str()) < MaxLength; +} + +void __sanitizer_symbolize_flush() { getDefaultSymbolizer()->flush(); } + +int __sanitizer_symbolize_demangle(const char *Name, char *Buffer, + int MaxLength) { + std::string Result = + llvm::symbolize::LLVMSymbolizer::DemangleName(Name, nullptr); + return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s", + Result.c_str()) < MaxLength + ? static_cast(Result.size() + 1) + : 0; +} + +} // extern "C" diff --git a/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cc b/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cc deleted file mode 100644 index c85ebe5e2e294..0000000000000 --- a/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cc +++ /dev/null @@ -1,198 +0,0 @@ -//===-- sanitizer_wrappers.cc -----------------------------------*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// Redirect some functions to sanitizer interceptors. -// -//===----------------------------------------------------------------------===// - -#include -#include -#include -#include -#include -#include - -#include - -// Need to match ../sanitizer_common/sanitizer_internal_defs.h -#if defined(ARCH_PPC) -#define OFF_T unsigned long -#else -#define OFF_T unsigned long long -#endif - -namespace __sanitizer { -unsigned long internal_open(const char *filename, int flags); -unsigned long internal_open(const char *filename, int flags, unsigned mode); -unsigned long internal_close(int fd); -unsigned long internal_stat(const char *path, void *buf); -unsigned long internal_lstat(const char *path, void *buf); -unsigned long internal_fstat(int fd, void *buf); -size_t internal_strlen(const char *s); -unsigned long internal_mmap(void *addr, unsigned long length, int prot, - int flags, int fd, OFF_T offset); -void *internal_memcpy(void *dest, const void *src, unsigned long n); -// Used to propagate errno. -bool internal_iserror(unsigned long retval, int *rverrno = 0); -} // namespace __sanitizer - -namespace { - -template -struct GetTypes; - -template -struct GetTypes { - using Result = R; - template - struct Arg { - using Type = typename std::tuple_element>::type; - }; -}; - -#define LLVM_SYMBOLIZER_GET_FUNC(Function) \ - ((__interceptor_##Function) \ - ? (__interceptor_##Function) \ - : reinterpret_cast(dlsym(RTLD_NEXT, #Function))) - -#define LLVM_SYMBOLIZER_INTERCEPTOR1(Function, ...) \ - GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type) __attribute__((weak)); \ - GetTypes<__VA_ARGS__>::Result Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type arg0) { \ - return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0); \ - } - -#define LLVM_SYMBOLIZER_INTERCEPTOR2(Function, ...) \ - GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type) __attribute__((weak)); \ - GetTypes<__VA_ARGS__>::Result Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type arg1) { \ - return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1); \ - } - -#define LLVM_SYMBOLIZER_INTERCEPTOR3(Function, ...) \ - GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type, \ - GetTypes<__VA_ARGS__>::Arg<2>::Type) __attribute__((weak)); \ - GetTypes<__VA_ARGS__>::Result Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type arg1, \ - GetTypes<__VA_ARGS__>::Arg<2>::Type arg2) { \ - return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1, arg2); \ - } - -#define LLVM_SYMBOLIZER_INTERCEPTOR4(Function, ...) \ - GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type, \ - GetTypes<__VA_ARGS__>::Arg<2>::Type, \ - GetTypes<__VA_ARGS__>::Arg<3>::Type) __attribute__((weak)); \ - GetTypes<__VA_ARGS__>::Result Function( \ - GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ - GetTypes<__VA_ARGS__>::Arg<1>::Type arg1, \ - GetTypes<__VA_ARGS__>::Arg<2>::Type arg2, \ - GetTypes<__VA_ARGS__>::Arg<3>::Type arg3) { \ - return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1, arg2, arg3); \ - } - -} // namespace - -// C-style interface around internal sanitizer libc functions. -extern "C" { - -#define RETURN_OR_SET_ERRNO(T, res) \ - int rverrno; \ - if (__sanitizer::internal_iserror(res, &rverrno)) { \ - errno = rverrno; \ - return (T)-1; \ - } \ - return (T)res; - -int open(const char *filename, int flags, ...) { - unsigned long res; - if (flags | O_CREAT) { - va_list va; - va_start(va, flags); - unsigned mode = va_arg(va, unsigned); - va_end(va); - res = __sanitizer::internal_open(filename, flags, mode); - } else { - res = __sanitizer::internal_open(filename, flags); - } - RETURN_OR_SET_ERRNO(int, res); -} - -int close(int fd) { - unsigned long res = __sanitizer::internal_close(fd); - RETURN_OR_SET_ERRNO(int, res); -} - -#define STAT(func, arg, buf) \ - unsigned long res = __sanitizer::internal_##func(arg, buf); \ - RETURN_OR_SET_ERRNO(int, res); - -int stat(const char *path, struct stat *buf) { STAT(stat, path, buf); } - -int lstat(const char *path, struct stat *buf) { STAT(lstat, path, buf); } - -int fstat(int fd, struct stat *buf) { STAT(fstat, fd, buf); } - -// Redirect versioned stat functions to the __sanitizer::internal() as well. -int __xstat(int version, const char *path, struct stat *buf) { - STAT(stat, path, buf); -} - -int __lxstat(int version, const char *path, struct stat *buf) { - STAT(lstat, path, buf); -} - -int __fxstat(int version, int fd, struct stat *buf) { STAT(fstat, fd, buf); } - -size_t strlen(const char *s) { return __sanitizer::internal_strlen(s); } - -void *mmap(void *addr, size_t length, int prot, int flags, int fd, - off_t offset) { - unsigned long res = __sanitizer::internal_mmap( - addr, (unsigned long)length, prot, flags, fd, (unsigned long long)offset); - RETURN_OR_SET_ERRNO(void *, res); -} - -LLVM_SYMBOLIZER_INTERCEPTOR3(read, ssize_t(int, void *, size_t)) -LLVM_SYMBOLIZER_INTERCEPTOR4(pread, ssize_t(int, void *, size_t, off_t)) -LLVM_SYMBOLIZER_INTERCEPTOR4(pread64, ssize_t(int, void *, size_t, off64_t)) -LLVM_SYMBOLIZER_INTERCEPTOR2(realpath, char *(const char *, char *)) - -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_cond_broadcast, int(pthread_cond_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_cond_wait, - int(pthread_cond_t *, pthread_mutex_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_lock, int(pthread_mutex_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_unlock, int(pthread_mutex_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_destroy, int(pthread_mutex_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_mutex_init, - int(pthread_mutex_t *, - const pthread_mutexattr_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutexattr_destroy, - int(pthread_mutexattr_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutexattr_init, int(pthread_mutexattr_t *)) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_mutexattr_settype, - int(pthread_mutexattr_t *, int)) -LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_getspecific, void *(pthread_key_t)) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_key_create, - int(pthread_key_t *, void (*)(void *))) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_once, - int(pthread_once_t *, void (*)(void))) -LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_setspecific, - int(pthread_key_t, const void *)) -LLVM_SYMBOLIZER_INTERCEPTOR3(pthread_sigmask, - int(int, const sigset_t *, sigset_t *)) - -} // extern "C" diff --git a/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cpp b/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cpp new file mode 100644 index 0000000000000..ac351d3a8362e --- /dev/null +++ b/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cpp @@ -0,0 +1,198 @@ +//===-- sanitizer_wrappers.cpp ----------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// Redirect some functions to sanitizer interceptors. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include +#include + +#include + +// Need to match ../sanitizer_common/sanitizer_internal_defs.h +#if defined(ARCH_PPC) +#define OFF_T unsigned long +#else +#define OFF_T unsigned long long +#endif + +namespace __sanitizer { +unsigned long internal_open(const char *filename, int flags); +unsigned long internal_open(const char *filename, int flags, unsigned mode); +unsigned long internal_close(int fd); +unsigned long internal_stat(const char *path, void *buf); +unsigned long internal_lstat(const char *path, void *buf); +unsigned long internal_fstat(int fd, void *buf); +size_t internal_strlen(const char *s); +unsigned long internal_mmap(void *addr, unsigned long length, int prot, + int flags, int fd, OFF_T offset); +void *internal_memcpy(void *dest, const void *src, unsigned long n); +// Used to propagate errno. +bool internal_iserror(unsigned long retval, int *rverrno = 0); +} // namespace __sanitizer + +namespace { + +template +struct GetTypes; + +template +struct GetTypes { + using Result = R; + template + struct Arg { + using Type = typename std::tuple_element>::type; + }; +}; + +#define LLVM_SYMBOLIZER_GET_FUNC(Function) \ + ((__interceptor_##Function) \ + ? (__interceptor_##Function) \ + : reinterpret_cast(dlsym(RTLD_NEXT, #Function))) + +#define LLVM_SYMBOLIZER_INTERCEPTOR1(Function, ...) \ + GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type) __attribute__((weak)); \ + GetTypes<__VA_ARGS__>::Result Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type arg0) { \ + return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0); \ + } + +#define LLVM_SYMBOLIZER_INTERCEPTOR2(Function, ...) \ + GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type) __attribute__((weak)); \ + GetTypes<__VA_ARGS__>::Result Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type arg1) { \ + return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1); \ + } + +#define LLVM_SYMBOLIZER_INTERCEPTOR3(Function, ...) \ + GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type, \ + GetTypes<__VA_ARGS__>::Arg<2>::Type) __attribute__((weak)); \ + GetTypes<__VA_ARGS__>::Result Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type arg1, \ + GetTypes<__VA_ARGS__>::Arg<2>::Type arg2) { \ + return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1, arg2); \ + } + +#define LLVM_SYMBOLIZER_INTERCEPTOR4(Function, ...) \ + GetTypes<__VA_ARGS__>::Result __interceptor_##Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type, \ + GetTypes<__VA_ARGS__>::Arg<2>::Type, \ + GetTypes<__VA_ARGS__>::Arg<3>::Type) __attribute__((weak)); \ + GetTypes<__VA_ARGS__>::Result Function( \ + GetTypes<__VA_ARGS__>::Arg<0>::Type arg0, \ + GetTypes<__VA_ARGS__>::Arg<1>::Type arg1, \ + GetTypes<__VA_ARGS__>::Arg<2>::Type arg2, \ + GetTypes<__VA_ARGS__>::Arg<3>::Type arg3) { \ + return LLVM_SYMBOLIZER_GET_FUNC(Function)(arg0, arg1, arg2, arg3); \ + } + +} // namespace + +// C-style interface around internal sanitizer libc functions. +extern "C" { + +#define RETURN_OR_SET_ERRNO(T, res) \ + int rverrno; \ + if (__sanitizer::internal_iserror(res, &rverrno)) { \ + errno = rverrno; \ + return (T)-1; \ + } \ + return (T)res; + +int open(const char *filename, int flags, ...) { + unsigned long res; + if (flags | O_CREAT) { + va_list va; + va_start(va, flags); + unsigned mode = va_arg(va, unsigned); + va_end(va); + res = __sanitizer::internal_open(filename, flags, mode); + } else { + res = __sanitizer::internal_open(filename, flags); + } + RETURN_OR_SET_ERRNO(int, res); +} + +int close(int fd) { + unsigned long res = __sanitizer::internal_close(fd); + RETURN_OR_SET_ERRNO(int, res); +} + +#define STAT(func, arg, buf) \ + unsigned long res = __sanitizer::internal_##func(arg, buf); \ + RETURN_OR_SET_ERRNO(int, res); + +int stat(const char *path, struct stat *buf) { STAT(stat, path, buf); } + +int lstat(const char *path, struct stat *buf) { STAT(lstat, path, buf); } + +int fstat(int fd, struct stat *buf) { STAT(fstat, fd, buf); } + +// Redirect versioned stat functions to the __sanitizer::internal() as well. +int __xstat(int version, const char *path, struct stat *buf) { + STAT(stat, path, buf); +} + +int __lxstat(int version, const char *path, struct stat *buf) { + STAT(lstat, path, buf); +} + +int __fxstat(int version, int fd, struct stat *buf) { STAT(fstat, fd, buf); } + +size_t strlen(const char *s) { return __sanitizer::internal_strlen(s); } + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) { + unsigned long res = __sanitizer::internal_mmap( + addr, (unsigned long)length, prot, flags, fd, (unsigned long long)offset); + RETURN_OR_SET_ERRNO(void *, res); +} + +LLVM_SYMBOLIZER_INTERCEPTOR3(read, ssize_t(int, void *, size_t)) +LLVM_SYMBOLIZER_INTERCEPTOR4(pread, ssize_t(int, void *, size_t, off_t)) +LLVM_SYMBOLIZER_INTERCEPTOR4(pread64, ssize_t(int, void *, size_t, off64_t)) +LLVM_SYMBOLIZER_INTERCEPTOR2(realpath, char *(const char *, char *)) + +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_cond_broadcast, int(pthread_cond_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_cond_wait, + int(pthread_cond_t *, pthread_mutex_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_lock, int(pthread_mutex_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_unlock, int(pthread_mutex_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutex_destroy, int(pthread_mutex_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_mutex_init, + int(pthread_mutex_t *, + const pthread_mutexattr_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutexattr_destroy, + int(pthread_mutexattr_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_mutexattr_init, int(pthread_mutexattr_t *)) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_mutexattr_settype, + int(pthread_mutexattr_t *, int)) +LLVM_SYMBOLIZER_INTERCEPTOR1(pthread_getspecific, void *(pthread_key_t)) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_key_create, + int(pthread_key_t *, void (*)(void *))) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_once, + int(pthread_once_t *, void (*)(void))) +LLVM_SYMBOLIZER_INTERCEPTOR2(pthread_setspecific, + int(pthread_key_t, const void *)) +LLVM_SYMBOLIZER_INTERCEPTOR3(pthread_sigmask, + int(int, const sigset_t *, sigset_t *)) + +} // extern "C" diff --git a/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh b/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh index 0c3917c6b17b1..be79f1df64ba3 100755 --- a/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh +++ b/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh @@ -25,15 +25,25 @@ # object file with only our entry points exposed. However, this does not work at # present, see PR30750. -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +set -x +set -e +set -u + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) SRC_DIR=$(readlink -f $SCRIPT_DIR/..) TARGE_DIR=$(readlink -f $1) - -LLVM_SRC="${LLVM_SRC:-$SCRIPT_DIR/../../../../../..}" +COMPILER_RT_SRC=$(readlink -f ${SCRIPT_DIR}/../../../..) +LLVM_SRC=${LLVM_SRC:-${COMPILER_RT_SRC}/../llvm} LLVM_SRC=$(readlink -f $LLVM_SRC) +if [[ ! -d "${LLVM_SRC}/../llvm" ]] ; then + LLVM_SRC=$(readlink -f ${COMPILER_RT_SRC}/../../../llvm) +fi +LIBCXX_SRC=$(readlink -f ${COMPILER_RT_SRC}/../libcxx) +LIBCXXABI_SRC=$(readlink -f ${COMPILER_RT_SRC}/../libcxxabi) -if [[ ! -d "${LLVM_SRC}/projects/libcxxabi" || - ! -d "${LLVM_SRC}/projects/libcxx" ]]; then +if [[ ! -d "${LLVM_SRC}/../llvm" || + ! -d "${LIBCXX_SRC}" || + ! -d "${LIBCXXABI_SRC}" ]]; then echo "Missing or incomplete LLVM_SRC" exit 1 fi @@ -88,8 +98,13 @@ make -j${J} libz.a if [[ ! -d ${LIBCXX_BUILD} ]]; then mkdir -p ${LIBCXX_BUILD} cd ${LIBCXX_BUILD} - LIBCXX_FLAGS="${FLAGS} -Wno-macro-redefined -I${LLVM_SRC}/projects/libcxxabi/include" + LIBCXX_FLAGS="${FLAGS} -Wno-macro-redefined -I${LIBCXX_SRC}/include" + PROJECTS= + if [[ ! -d $LLVM_SRC/projects/libcxxabi ]] ; then + PROJECTS="-DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi'" + fi cmake -GNinja \ + ${PROJECTS} \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER=$CC \ -DCMAKE_CXX_COMPILER=$CXX \ @@ -127,7 +142,7 @@ if [[ ! -d ${LLVM_BUILD} ]]; then $LLVM_SRC fi cd ${LLVM_BUILD} -ninja LLVMSymbolize LLVMObject LLVMBinaryFormat LLVMDebugInfoDWARF LLVMSupport LLVMDebugInfoPDB LLVMMC LLVMDemangle +ninja LLVMSymbolize LLVMObject LLVMBinaryFormat LLVMDebugInfoDWARF LLVMSupport LLVMDebugInfoPDB LLVMMC LLVMDemangle LLVMTextAPI cd ${BUILD_DIR} rm -rf ${SYMBOLIZER_BUILD} @@ -135,8 +150,8 @@ mkdir ${SYMBOLIZER_BUILD} cd ${SYMBOLIZER_BUILD} echo "Compiling..." -SYMBOLIZER_FLAGS="$LLVM_FLAGS -I${LLVM_SRC}/include -I${LLVM_BUILD}/include -std=c++11" -$CXX $SYMBOLIZER_FLAGS ${SRC_DIR}/sanitizer_symbolize.cc ${SRC_DIR}/sanitizer_wrappers.cc -c +SYMBOLIZER_FLAGS="$LLVM_FLAGS -I${LLVM_SRC}/include -I${LLVM_BUILD}/include -std=c++14" +$CXX $SYMBOLIZER_FLAGS ${SRC_DIR}/sanitizer_symbolize.cpp ${SRC_DIR}/sanitizer_wrappers.cpp -c $AR rc symbolizer.a sanitizer_symbolize.o sanitizer_wrappers.o SYMBOLIZER_API_LIST=__sanitizer_symbolize_code,__sanitizer_symbolize_data,__sanitizer_symbolize_flush,__sanitizer_symbolize_demangle @@ -152,6 +167,7 @@ $SCRIPT_DIR/ar_to_bc.sh $LIBCXX_BUILD/lib/libc++.a \ $LLVM_BUILD/lib/libLLVMDebugInfoPDB.a \ $LLVM_BUILD/lib/libLLVMDemangle.a \ $LLVM_BUILD/lib/libLLVMMC.a \ + $LLVM_BUILD/lib/libLLVMTextAPI.a \ $ZLIB_BUILD/libz.a \ symbolizer.a \ all.bc diff --git a/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt b/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt index 2a0f76b80ef4c..fa42e2a019651 100644 --- a/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt +++ b/lib/sanitizer_common/symbolizer/scripts/global_symbols.txt @@ -19,8 +19,13 @@ __interceptor_pthread_cond_broadcast w __interceptor_pthread_cond_wait w __interceptor_pthread_getspecific w __interceptor_pthread_key_create w +__interceptor_pthread_mutex_destroy w +__interceptor_pthread_mutex_init w __interceptor_pthread_mutex_lock w __interceptor_pthread_mutex_unlock w +__interceptor_pthread_mutexattr_destroy w +__interceptor_pthread_mutexattr_init w +__interceptor_pthread_mutexattr_settype w __interceptor_pthread_once w __interceptor_pthread_setspecific w __interceptor_read w @@ -70,9 +75,11 @@ getpid U getrlimit U gettimeofday U ioctl U +isalnum U isalpha U isatty U islower U +isspace U isprint U isupper U isxdigit U -- cgit v1.2.3