diff --git a/compiler-rt/lib/crt/crtbegin.c b/compiler-rt/lib/crt/crtbegin.c --- a/compiler-rt/lib/crt/crtbegin.c +++ b/compiler-rt/lib/crt/crtbegin.c @@ -73,12 +73,12 @@ __cxa_finalize(__dso_handle); #ifndef CRT_HAS_INITFINI_ARRAY - if (__deregister_frame_info) - __deregister_frame_info(__EH_FRAME_LIST__); - const size_t n = __DTOR_LIST_END__ - __DTOR_LIST__ - 1; for (size_t i = 1; i <= n; i++) __DTOR_LIST__[i](); #endif + + if (__deregister_frame_info) + __deregister_frame_info(__EH_FRAME_LIST__); } #ifdef CRT_HAS_INITFINI_ARRAY diff --git a/compiler-rt/test/crt/ctor_dtor.c b/compiler-rt/test/crt/ctor_dtor.c --- a/compiler-rt/test/crt/ctor_dtor.c +++ b/compiler-rt/test/crt/ctor_dtor.c @@ -4,9 +4,23 @@ #include -// CHECK: ctor() +// Ensure the various startup functions are called in the proper order. + +// CHECK: __register_frame_info() +// CHECK-NEXT: ctor() // CHECK-NEXT: main() // CHECK-NEXT: dtor() +// CHECK-NEXT: __deregister_frame_info() + +struct object; + +void __register_frame_info(const void *fi, struct object *obj) { + printf("__register_frame_info()\n"); +} + +void __deregister_frame_info(const void *fi) { + printf("__deregister_frame_info()\n"); +} void __attribute__((constructor)) ctor() { printf("ctor()\n");