summaryrefslogtreecommitdiff
path: root/lib/msan/tests/msan_loadable.cc
blob: db3bf489853dc833e5f2a75216d077b12b1a5438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//===-- 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;
}

}