summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/asan/TestCases/Linux/init_fini_sections.cpp
blob: 3037b232926ee05e7c4e927da96a4b7b2a563136 (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
// RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s

#include <stdio.h>

int c = 0;

static void foo() {
  ++c;
}

static void fini() {
  printf("fini\n");
}

int main() {
  printf("c=%d\n", c);
  return 0;
}

__attribute__((section(".preinit_array")))
void (*call_foo)(void) = &foo;

__attribute__((section(".init_array")))
void (*call_foo_2)(void) = &foo;

__attribute__((section(".fini_array")))
void (*call_foo_3)(void) = &fini;

// CHECK: c=2
// CHECK: fini
OpenPOWER on IntegriCloud