From 1836ed28ddbe419258cfd9de103888093003fe97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 2 Aug 2018 14:28:07 +0300 Subject: [PATCH] Test __attribute__((constructor)) and __attribute__((destructor)) When using a global C++ object, the destructor isn't handled via the .dtors section, but the destructor is set up with atexit() once the constructor has been called. --- test/hello-cpp.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/hello-cpp.cpp b/test/hello-cpp.cpp index 27683f2..915cf5c 100644 --- a/test/hello-cpp.cpp +++ b/test/hello-cpp.cpp @@ -30,6 +30,14 @@ public: Hello global_h; +__attribute__((constructor)) static void attr_ctor(void) { + printf("attr_ctor\n"); +} + +__attribute__((destructor)) static void attr_dtor(void) { + printf("attr_dtor\n"); +} + int main(int argc, char* argv[]) { std::cout<<"Hello world C++"<