brintos

brintos / llvm-project-archived public Read only

0
0
Text · 994 B · 58dffba Raw
44 lines · c
1// REQUIRES: crt2 3// RUN: %clang -fno-use-init-array -g -c %s -o %t.o4// RUN: %clang -o %t -no-pie -nostdlib %crt1 %crti %crtbegin %t.o %libc %libgcc %crtend %crtn5// RUN: %run %t 2>&1 | FileCheck %s6 7#include <stdio.h>8#include <stdlib.h>9 10// Ensure the various startup functions are called in the proper order.11 12// CHECK: __register_frame_info()13/// ctor() is here if ld.so/libc supports DT_INIT/DT_FINI14// CHECK:      main()15/// dtor() is here if ld.so/libc supports DT_INIT/DT_FINI16// CHECK:      __deregister_frame_info()17 18struct object;19static int counter;20 21void __register_frame_info(const void *fi, struct object *obj) {22  printf("__register_frame_info()\n");23}24 25void __deregister_frame_info(const void *fi) {26  printf("__deregister_frame_info()\n");27}28 29void __attribute__((constructor)) ctor() {30  printf("ctor()\n");31  ++counter;32}33 34void __attribute__((destructor)) dtor() {35  printf("dtor()\n");36  if (--counter != 0)37    abort();38}39 40int main() {41  printf("main()\n");42  return 0;43}44