Files
clang-p2996/compiler-rt/lib/msan/tests/msan_loadable.cc
Reid Kleckner c9d382b5a4 [msan] intercept dlopen and clear shadow for it
Summary:
The loader does not call mmap() through the PLT because it has to
bootstrap the process before libc is present.  Hooking dlopen() isn't
enough either because the loader runs module initializers before
returning, and they could run arbitrary msan instrumented code.

If msandr is present, then we can intercept the mmaps from dlopen at the
syscall layer and clear the shadow there.  If msandr is missing, we
clear the shadow after dlopen() and hope any initializers are trivial.

Reviewers: eugenis

CC: kcc, llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D509

llvm-svn: 176818
2013-03-11 18:07:42 +00:00

46 lines
1.2 KiB
C++

//===-- msan_loadable.cc --------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of MemorySanitizer.
//
// MemorySanitizer unit tests.
//===----------------------------------------------------------------------===//
#include "msan/msan_interface_internal.h"
#include <stdlib.h>
static void *dso_global;
// No name mangling.
extern "C" {
__attribute__((constructor))
void loadable_module_init(void) {
if (!__msan_has_dynamic_component())
return;
// The real test is that this compare should not make an uninit.
if (dso_global == NULL)
dso_global = malloc(4);
}
__attribute__((destructor))
void loadable_module_fini(void) {
if (!__msan_has_dynamic_component())
return;
free(dso_global);
// *Don't* overwrite it with NULL! That would unpoison it, but our test
// relies on reloading at the same address and keeping the poison.
}
void **get_dso_global() {
return &dso_global;
}
}