forked from OSchip/llvm-project
[sanitizer-coverage] nuke more stale code
llvm-svn: 304503
This commit is contained in:
parent
3bb4829936
commit
c1a56baa3e
|
|
@ -242,9 +242,8 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
|
|||
CheckNoDeepBind(filename, flag); \
|
||||
} while (false)
|
||||
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
|
||||
#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) \
|
||||
CoverageUpdateMapping()
|
||||
#define COMMON_INTERCEPTOR_LIBRARY_UNLOADED() CoverageUpdateMapping()
|
||||
#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle)
|
||||
#define COMMON_INTERCEPTOR_LIBRARY_UNLOADED()
|
||||
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED (!asan_inited)
|
||||
#define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end) \
|
||||
if (AsanThread *t = GetCurrentThread()) { \
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ set(SANITIZER_LIBCDEP_SOURCES
|
|||
sancov_flags.cc
|
||||
sanitizer_coverage_libcdep.cc
|
||||
sanitizer_coverage_libcdep_new.cc
|
||||
sanitizer_coverage_mapping_libcdep.cc
|
||||
sanitizer_coverage_win_sections.cc
|
||||
sanitizer_linux_libcdep.cc
|
||||
sanitizer_posix_libcdep.cc
|
||||
|
|
|
|||
|
|
@ -320,7 +320,6 @@ void PrepareForSandboxing(__sanitizer_sandbox_arguments *args);
|
|||
void CovPrepareForSandboxing(__sanitizer_sandbox_arguments *args);
|
||||
void SetSandboxingCallback(void (*f)());
|
||||
|
||||
void CoverageUpdateMapping();
|
||||
void CovBeforeFork();
|
||||
void CovAfterFork(int child_pid);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ static atomic_uintptr_t coverage_counter;
|
|||
// To make the pc_array thread- and async-signal-safe it has to be large enough.
|
||||
// 128M counters "ought to be enough for anybody" (4M on 32-bit).
|
||||
|
||||
// With coverage_direct=1 in ASAN_OPTIONS, pc_array memory is mapped to a file.
|
||||
// In this mode, __sanitizer_cov_dump does nothing, and CovUpdateMapping()
|
||||
// dump current memory layout to another file.
|
||||
|
||||
static bool cov_sandboxed = false;
|
||||
static fd_t cov_fd = kInvalidFd;
|
||||
static unsigned int cov_max_block_size = 0;
|
||||
|
|
@ -137,8 +133,6 @@ class CoverageData {
|
|||
|
||||
static CoverageData coverage_data;
|
||||
|
||||
void CovUpdateMapping(const char *path, uptr caller_pc = 0);
|
||||
|
||||
void CoverageData::DirectOpen() {
|
||||
InternalScopedString path(kMaxPathLength);
|
||||
internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.raw",
|
||||
|
|
@ -150,7 +144,6 @@ void CoverageData::DirectOpen() {
|
|||
}
|
||||
|
||||
pc_array_mapped_size = 0;
|
||||
CovUpdateMapping(coverage_dir);
|
||||
}
|
||||
|
||||
void CoverageData::Init() {
|
||||
|
|
@ -210,7 +203,6 @@ void CoverageData::ReInit() {
|
|||
uptr npcs = size / sizeof(uptr);
|
||||
Enable();
|
||||
if (size) Extend(npcs);
|
||||
if (coverage_enabled) CovUpdateMapping(coverage_dir);
|
||||
} else {
|
||||
Enable();
|
||||
}
|
||||
|
|
@ -598,11 +590,6 @@ void ReInitializeCoverage(bool enabled, const char *dir) {
|
|||
coverage_data.ReInit();
|
||||
}
|
||||
|
||||
void CoverageUpdateMapping() {
|
||||
if (coverage_enabled)
|
||||
CovUpdateMapping(coverage_dir);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -1,122 +0,0 @@
|
|||
//===-- sanitizer_coverage_mapping.cc -------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Mmap-based implementation of sanitizer coverage.
|
||||
//
|
||||
// This is part of the implementation of code coverage that does not require
|
||||
// __sanitizer_cov_dump() call. Data is stored in 2 files per process.
|
||||
//
|
||||
// $pid.sancov.map describes process memory layout in the following text-based
|
||||
// format:
|
||||
// <pointer size in bits> // 1 line, 32 or 64
|
||||
// <mapping start> <mapping end> <base address> <dso name> // repeated
|
||||
// ...
|
||||
// Mapping lines are NOT sorted. This file is updated every time memory layout
|
||||
// is changed (i.e. in dlopen() and dlclose() interceptors).
|
||||
//
|
||||
// $pid.sancov.raw is a binary dump of PC values, sizeof(uptr) each. Again, not
|
||||
// sorted. This file is extended by 64Kb at a time and mapped into memory. It
|
||||
// contains one or more 0 words at the end, up to the next 64Kb aligned offset.
|
||||
//
|
||||
// To convert these 2 files to the usual .sancov format, run sancov.py rawunpack
|
||||
// $pid.sancov.raw.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "sanitizer_allocator_internal.h"
|
||||
#include "sanitizer_libc.h"
|
||||
#include "sanitizer_procmaps.h"
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
static const uptr kMaxTextSize = 64 * 1024;
|
||||
|
||||
struct CachedMapping {
|
||||
public:
|
||||
bool NeedsUpdate(uptr pc) {
|
||||
int new_pid = internal_getpid();
|
||||
if (last_pid == new_pid && pc && pc >= last_range_start &&
|
||||
pc < last_range_end)
|
||||
return false;
|
||||
last_pid = new_pid;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetModuleRange(uptr start, uptr end) {
|
||||
last_range_start = start;
|
||||
last_range_end = end;
|
||||
}
|
||||
|
||||
private:
|
||||
uptr last_range_start, last_range_end;
|
||||
int last_pid;
|
||||
};
|
||||
|
||||
static CachedMapping cached_mapping;
|
||||
static StaticSpinMutex mapping_mu;
|
||||
|
||||
void CovUpdateMapping(const char *coverage_dir, uptr caller_pc) {
|
||||
if (!common_flags()->coverage_direct) return;
|
||||
|
||||
SpinMutexLock l(&mapping_mu);
|
||||
|
||||
if (!cached_mapping.NeedsUpdate(caller_pc))
|
||||
return;
|
||||
|
||||
InternalScopedString text(kMaxTextSize);
|
||||
|
||||
{
|
||||
text.append("%d\n", sizeof(uptr) * 8);
|
||||
ListOfModules modules;
|
||||
modules.init();
|
||||
for (const LoadedModule &module : modules) {
|
||||
const char *module_name = StripModuleName(module.full_name());
|
||||
uptr base = module.base_address();
|
||||
for (const auto &range : module.ranges()) {
|
||||
if (range.executable) {
|
||||
uptr start = range.beg;
|
||||
uptr end = range.end;
|
||||
text.append("%zx %zx %zx %s\n", start, end, base, module_name);
|
||||
if (caller_pc && caller_pc >= start && caller_pc < end)
|
||||
cached_mapping.SetModuleRange(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error_t err;
|
||||
InternalScopedString tmp_path(64 + internal_strlen(coverage_dir));
|
||||
uptr res = internal_snprintf((char *)tmp_path.data(), tmp_path.size(),
|
||||
"%s/%zd.sancov.map.tmp", coverage_dir,
|
||||
internal_getpid());
|
||||
CHECK_LE(res, tmp_path.size());
|
||||
fd_t map_fd = OpenFile(tmp_path.data(), WrOnly, &err);
|
||||
if (map_fd == kInvalidFd) {
|
||||
Report("Coverage: failed to open %s for writing: %d\n", tmp_path.data(),
|
||||
err);
|
||||
Die();
|
||||
}
|
||||
|
||||
if (!WriteToFile(map_fd, text.data(), text.length(), nullptr, &err)) {
|
||||
Printf("sancov.map write failed: %d\n", err);
|
||||
Die();
|
||||
}
|
||||
CloseFile(map_fd);
|
||||
|
||||
InternalScopedString path(64 + internal_strlen(coverage_dir));
|
||||
res = internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.map",
|
||||
coverage_dir, internal_getpid());
|
||||
CHECK_LE(res, path.size());
|
||||
if (!RenameFile(tmp_path.data(), path.data(), &err)) {
|
||||
Printf("sancov.map rename failed: %d\n", err);
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
Loading…
Reference in New Issue