[compiler-rt] r350101 - [asan] Support running without /proc.
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 27 17:11:06 PST 2018
This seems to have broken our macOS builders with the following error:
FAILED:
/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/lib/clang/8.0.0/lib/darwin/libclang_rt.stats_osx_dynamic.dylib
: &&
/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/./bin/clang++
--target=x86_64-apple-darwin17.7.0 -stdlib=libc++ -fPIC
-fvisibility-inlines-hidden -Werror=date-time
-Werror=unguarded-availability-new -std=c++11 -Wall -Wextra
-Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -Wimplicit-fallthrough
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -Wall
-std=c++11 -Wno-unused-parameter -O3 -arch i386 -arch x86_64 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
-dynamiclib -Wl,-headerpad_max_install_names -stdlib=libc++
-stdlib=libc++ -lc++ -lc++abi -fapplication-extension
-mmacosx-version-min=10.9 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
-nodefaultlibs -Wl,-U,___asan_default_options
-Wl,-U,___asan_default_suppressions -Wl,-U,___asan_on_error
-Wl,-U,___asan_set_shadow_00 -Wl,-U,___asan_set_shadow_f1
-Wl,-U,___asan_set_shadow_f2 -Wl,-U,___asan_set_shadow_f3
-Wl,-U,___asan_set_shadow_f4 -Wl,-U,___asan_set_shadow_f5
-Wl,-U,___asan_set_shadow_f6 -Wl,-U,___asan_set_shadow_f7
-Wl,-U,___asan_set_shadow_f8 -Wl,-U,___ubsan_default_options
-Wl,-U,___sanitizer_free_hook -Wl,-U,___sanitizer_malloc_hook
-Wl,-U,___sanitizer_report_error_summary
-Wl,-U,___sanitizer_sandbox_on_notify -Wl,-U,___sanitizer_symbolize_code
-Wl,-U,___sanitizer_symbolize_data -Wl,-U,___sanitizer_symbolize_demangle
-Wl,-U,___sanitizer_symbolize_flush -o
/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/lib/clang/8.0.0/lib/darwin/libclang_rt.stats_osx_dynamic.dylib
-install_name @rpath/libclang_rt.stats_osx_dynamic.dylib
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_allocator.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_common.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_deadlock_detector1.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_deadlock_detector2.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_errno.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_file.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_flags.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_flag_parser.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_fuchsia.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_libc.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_libignore.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_linux.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_linux_s390.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_mac.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_netbsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_openbsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_persistent_allocator.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_freebsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_linux.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_netbsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_openbsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_posix.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_platform_limits_solaris.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_posix.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_printf.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_procmaps_common.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_procmaps_bsd.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_procmaps_linux.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_procmaps_mac.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_procmaps_solaris.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_rtems.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_solaris.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_stoptheworld_mac.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_suppressions.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_tls_get_addr.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_thread_registry.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_win.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.osx.dir/sanitizer_termination.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_common_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_allocator_checks.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_linux_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_mac_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_posix_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.osx.dir/sanitizer_stoptheworld_linux_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_allocator_report.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_stackdepot.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_stacktrace.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_stacktrace_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_stacktrace_printer.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_stacktrace_sparc.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_libbacktrace.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_mac.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_markup.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_posix_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_report.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_symbolizer_win.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_unwind_linux_libcdep.cc.o
compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.osx.dir/sanitizer_unwind_win.cc.o
compiler-rt/lib/stats/CMakeFiles/clang_rt.stats_osx_dynamic.dir/stats.cc.o
-Wl,-rpath, at loader_path/../lib
-Wl,-rpath,/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/./lib
-lc && cd
/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/lib/clang/8.0.0/lib/darwin
&& codesign --sign -
/b/s/w/ir/kitchen-workdir/recipe_cleanup/clangpTi8IB/llvm_build_dir/lib/clang/8.0.0/lib/darwin/libclang_rt.stats_osx_dynamic.dylib
Undefined symbols for architecture i386:
"__sanitizer::MemoryMappingLayout::IsAvailable()", referenced from:
__sanitizer::MemoryRangeIsAvailable(unsigned long, unsigned long) in
sanitizer_posix.cc.o
ld: symbol(s) not found for architecture i386
clang-8: error: linker command failed with exit code 1 (use -v to see
invocation)
On Thu, Dec 27, 2018 at 1:35 PM Evgeniy Stepanov via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: eugenis
> Date: Thu Dec 27 13:31:52 2018
> New Revision: 350101
>
> URL: http://llvm.org/viewvc/llvm-project?rev=350101&view=rev
> Log:
> [asan] Support running without /proc.
>
> Summary:
> This patch lets ASan run when /proc is not accessible (ex. not mounted
> yet). It includes a special test-only flag that emulates this condition
> in an unpriviledged process.
>
> This only matters on Linux, where /proc is necessary to enumerate
> virtual memory mappings.
>
> Reviewers: pcc, vitalybuka
>
> Subscribers: kubamracek, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D55874
>
> Modified:
> compiler-rt/trunk/lib/asan/asan_linux.cc
> compiler-rt/trunk/lib/asan/asan_thread.cc
> compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
> compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc
>
> Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_linux.cc Thu Dec 27 13:31:52 2018
> @@ -210,6 +210,8 @@ void AsanCheckIncompatibleRT() {
> }
> } else {
> if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
> + if (!MemoryMappingLayout::IsAvailable())
> + return;
> // Ensure that dynamic runtime is not present. We should detect it
> // as early as possible, otherwise ASan interceptors could bind to
> // the functions in dynamic ASan runtime instead of the functions in
>
> Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
> +++ compiler-rt/trunk/lib/asan/asan_thread.cc Thu Dec 27 13:31:52 2018
> @@ -18,6 +18,7 @@
> #include "asan_thread.h"
> #include "asan_mapping.h"
> #include "sanitizer_common/sanitizer_common.h"
> +#include "sanitizer_common/sanitizer_file.h"
> #include "sanitizer_common/sanitizer_placement_new.h"
> #include "sanitizer_common/sanitizer_stackdepot.h"
> #include "sanitizer_common/sanitizer_tls_get_addr.h"
> @@ -223,9 +224,11 @@ void AsanThread::Init(const InitOptions
> atomic_store(&stack_switching_, false, memory_order_release);
> CHECK_EQ(this->stack_size(), 0U);
> SetThreadStackAndTls(options);
> - CHECK_GT(this->stack_size(), 0U);
> - CHECK(AddrIsInMem(stack_bottom_));
> - CHECK(AddrIsInMem(stack_top_ - 1));
> + if (stack_top_ != stack_bottom_) {
> + CHECK_GT(this->stack_size(), 0U);
> + CHECK(AddrIsInMem(stack_bottom_));
> + CHECK(AddrIsInMem(stack_top_ - 1));
> + }
> ClearShadowForThreadStackAndTLS();
> fake_stack_ = nullptr;
> if (__asan_option_detect_stack_use_after_return)
> @@ -287,22 +290,29 @@ AsanThread *CreateMainThread() {
> // OS-specific implementations that need more information passed through.
> void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
> DCHECK_EQ(options, nullptr);
> - uptr tls_size = 0;
> - uptr stack_size = 0;
> - GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size,
> &tls_begin_,
> - &tls_size);
> - stack_top_ = stack_bottom_ + stack_size;
> - tls_end_ = tls_begin_ + tls_size;
> - dtls_ = DTLS_Get();
> + // If this process is "init" (pid 1), /proc may not be mounted yet.
> + if (!start_routine_ && !MemoryMappingLayout::IsAvailable()) {
> + stack_top_ = stack_bottom_ = 0;
> + tls_begin_ = tls_end_ = 0;
> + } else {
> + uptr tls_size = 0;
> + uptr stack_size = 0;
> + GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size,
> &tls_begin_,
> + &tls_size);
> + stack_top_ = stack_bottom_ + stack_size;
> + tls_end_ = tls_begin_ + tls_size;
> + dtls_ = DTLS_Get();
>
> - int local;
> - CHECK(AddrIsInStack((uptr)&local));
> + int local;
> + CHECK(AddrIsInStack((uptr)&local));
> + }
> }
>
> #endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
>
> void AsanThread::ClearShadowForThreadStackAndTLS() {
> - PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
> + if (stack_top_ != stack_bottom_)
> + PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
> if (tls_begin_ != tls_end_) {
> uptr tls_begin_aligned = RoundDownTo(tls_begin_, SHADOW_GRANULARITY);
> uptr tls_end_aligned = RoundUpTo(tls_end_, SHADOW_GRANULARITY);
> @@ -314,6 +324,9 @@ void AsanThread::ClearShadowForThreadSta
>
> bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
> StackFrameAccess *access) {
> + if (stack_top_ == stack_bottom_)
> + return false;
> +
> uptr bottom = 0;
> if (AddrIsInStack(addr)) {
> bottom = stack_bottom();
>
> Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
> +++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Thu Dec 27 13:31:52 2018
> @@ -44,7 +44,7 @@ void Thread::Init(uptr stack_buffer_star
> ScopedTaggingDisabler disabler;
>
> // If this process is "init" (pid 1), /proc may not be mounted yet.
> - if (IsMainThread() && !FileExists("/proc/self/maps")) {
> + if (IsMainThread() && !MemoryMappingLayout::IsAvailable()) {
> stack_top_ = stack_bottom_ = 0;
> tls_begin_ = tls_end_ = 0;
> } else {
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Thu Dec 27
> 13:31:52 2018
> @@ -243,3 +243,6 @@ COMMON_FLAG(bool, dump_registers, true,
> COMMON_FLAG(bool, detect_write_exec, false,
> "If true, triggers warning when writable-executable pages
> requests "
> "are being made")
> +COMMON_FLAG(bool, test_only_emulate_no_procfs, false,
> + "TEST ONLY fail to open any files under /proc to emulate
> sanitized "
> + "\"init\"")
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Dec 27
> 13:31:52 2018
> @@ -453,6 +453,8 @@ uptr internal_execve(const char *filenam
>
> // ----------------- sanitizer_common.h
> bool FileExists(const char *filename) {
> + if (ShouldMockFailureToOpen(filename))
> + return false;
> struct stat st;
> #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
> if (internal_syscall(SYSCALL(newfstatat), AT_FDCWD, filename, &st, 0))
> @@ -1003,6 +1005,8 @@ ThreadLister::~ThreadLister() {
> // Take care of unusable kernel area in top gigabyte.
> static uptr GetKernelAreaSize() {
> #if SANITIZER_LINUX && !SANITIZER_X32
> + if (!MemoryMappingLayout::IsAvailable())
> + return 0;
> const uptr gbyte = 1UL << 30;
>
> // Firstly check if there are writable segments
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h Thu Dec 27
> 13:31:52 2018
> @@ -44,6 +44,7 @@ struct MemoryMappingLayoutData {
> };
>
> void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
> +bool IsProcMapsAvailable();
>
> // Syscall wrappers.
> uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int
> count);
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Dec 27
> 13:31:52 2018
> @@ -282,6 +282,8 @@ uptr internal_waitpid(int pid, int *stat
>
> // ----------------- sanitizer_common.h
> bool FileExists(const char *filename) {
> + if (ShouldMockFailureToOpen(filename))
> + return false;
> struct stat st;
> if (stat(filename, &st))
> return false;
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Thu Dec 27
> 13:31:52 2018
> @@ -18,6 +18,7 @@
>
> #include "sanitizer_common.h"
> #include "sanitizer_file.h"
> +#include "sanitizer_flags.h"
> #include "sanitizer_libc.h"
> #include "sanitizer_posix.h"
> #include "sanitizer_procmaps.h"
> @@ -157,6 +158,8 @@ void MprotectMallocZones(void *addr, int
> #endif
>
> fd_t OpenFile(const char *filename, FileAccessMode mode, error_t
> *errno_p) {
> + if (ShouldMockFailureToOpen(filename))
> + return kInvalidFd;
> int flags;
> switch (mode) {
> case RdOnly: flags = O_RDONLY; break;
> @@ -229,6 +232,8 @@ static inline bool IntervalsAreSeparate(
> // several worker threads on Mac, which aren't expected to map big chunks
> of
> // memory).
> bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
> + if (!MemoryMappingLayout::IsAvailable())
> + return true; // hope for the best
> MemoryMappingLayout proc_maps(/*cache_enabled*/true);
> MemoryMappedSegment segment;
> while (proc_maps.Next(&segment)) {
> @@ -334,6 +339,11 @@ fd_t ReserveStandardFds(fd_t fd) {
> return fd;
> }
>
> +bool ShouldMockFailureToOpen(const char *path) {
> + return common_flags()->test_only_emulate_no_procfs &&
> + internal_strncmp(path, "/proc/", 6) == 0;
> +}
> +
> } // namespace __sanitizer
>
> #endif // SANITIZER_POSIX
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h Thu Dec 27
> 13:31:52 2018
> @@ -103,6 +103,8 @@ bool IsStateDetached(int state);
> // Move the fd out of {0, 1, 2} range.
> fd_t ReserveStandardFds(fd_t fd);
>
> +bool ShouldMockFailureToOpen(const char *path);
> +
> } // namespace __sanitizer
>
> #endif // SANITIZER_POSIX_H
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h Thu Dec 27
> 13:31:52 2018
> @@ -75,6 +75,7 @@ class MemoryMappingLayout {
> // to obtain the memory mappings. It should fall back to pre-cached data
> // instead of aborting.
> static void CacheMemoryMappings();
> + static bool IsAvailable();
>
> // Adds all mapped objects into a vector.
> void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_bsd.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_bsd.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_bsd.cc Thu
> Dec 27 13:31:52 2018
> @@ -45,6 +45,10 @@
>
> namespace __sanitizer {
>
> +bool IsProcMapsAvailable() {
> + return true;
> +}
> +
> void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
> const int Mib[] = {
> #if SANITIZER_FREEBSD
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_common.cc
> Thu Dec 27 13:31:52 2018
> @@ -144,6 +144,12 @@ void MemoryMappingLayout::DumpListOfModu
> }
> }
>
> +bool MemoryMappingLayout::IsAvailable() {
> + if (cached_proc_self_maps.data)
> + return true;
> + return IsProcMapsAvailable();
> +}
> +
> void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
> char *smaps = nullptr;
> uptr smaps_cap = 0;
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_linux.cc Thu
> Dec 27 13:31:52 2018
> @@ -13,10 +13,15 @@
> #include "sanitizer_platform.h"
> #if SANITIZER_LINUX
> #include "sanitizer_common.h"
> +#include "sanitizer_file.h"
> #include "sanitizer_procmaps.h"
>
> namespace __sanitizer {
>
> +bool IsProcMapsAvailable() {
> + return FileExists("/proc/self/maps");
> +}
> +
> void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
> if (!ReadFileToBuffer("/proc/self/maps", &proc_maps->data,
> &proc_maps->mmaped_size, &proc_maps->len)) {
>
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_solaris.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps_solaris.cc
> Thu Dec 27 13:31:52 2018
> @@ -20,6 +20,10 @@
>
> namespace __sanitizer {
>
> +bool IsProcMapsAvailable() {
> + return FileExists("/proc/self/xmap");
> +}
> +
> void ReadProcMaps(ProcSelfMapsBuff *proc_maps) {
> ReadFileToBuffer("/proc/self/xmap", &proc_maps->data,
> &proc_maps->mmaped_size,
> &proc_maps->len);
>
> Modified: compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc?rev=350101&r1=350100&r2=350101&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc (original)
> +++ compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc Thu Dec 27
> 13:31:52 2018
> @@ -9,6 +9,10 @@
> #include <stdlib.h>
> #include <unistd.h>
>
> +extern "C" const char *__asan_default_options() {
> + return "test_only_emulate_no_procfs=1";
> +}
> +
> void parent(int argc, char **argv) {
> fprintf(stderr, "hello\n");
> // CHECK: hello
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181227/0afd83ab/attachment.html>
More information about the llvm-commits
mailing list