| 1 | // RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | int c = 0; |
| 6 | |
| 7 | static void foo() { |
| 8 | ++c; |
| 9 | } |
| 10 | |
| 11 | static void fini() { |
| 12 | printf(format: "fini\n" ); |
| 13 | } |
| 14 | |
| 15 | int main() { |
| 16 | printf(format: "c=%d\n" , c); |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | __attribute__((section(".preinit_array" ))) |
| 21 | void (*call_foo)(void) = &foo; |
| 22 | |
| 23 | __attribute__((section(".init_array" ))) |
| 24 | void (*call_foo_2)(void) = &foo; |
| 25 | |
| 26 | __attribute__((section(".fini_array" ))) |
| 27 | void (*call_foo_3)(void) = &fini; |
| 28 | |
| 29 | // CHECK: c=2 |
| 30 | // CHECK: fini |
| 31 | |