__do_global_dtors_aux and __do_global_ctors_aux

后端 未结 2 1368
长情又很酷
长情又很酷 2021-01-02 09:53

I disassembled a simple program written in C++ and there are these two function names. I guess that ctor means constructor and dtor means destructor, and word global maybe m

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 10:50

    They are auxiliary functions added by the compiler to construct and destroy static objects.

    e.g.

    std::vector some_global;
    
    int main() { return 0; }
    

    some_global needs to be actually constructed (and destructed) somewhere, and C++ guarantees that construction happens before main. One way to do this is to emit a function that happens before main, which constructs global objects, and another function that happens after main to destroy them.

    If you stuck a breakpoint inside the std::vector constructor and ran this program, the stack trace would show you the function that it was being initialised from.

提交回复
热议问题