Linux相当于DllMain [英] Linux equivalent of DllMain

查看:447
本文介绍了Linux相当于DllMain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在* nix .so库中,在加载和卸载库时是否有系统调用的入口点?



在一个更实用的注意事项:if .so是用C ++编写的,它包含具有构造函数和析构函数的全局对象,并且从没有构造/破坏概念的语言加载,是正确构造/破坏的全局对象吗?


  • 对于JNI库,例如在Android上,可能有一个特殊的条目JNI_OnLoad用于填充JNI函数表。


  • GCC定义特殊属性构造函数<允许一些代码在共享库加载时运行。


  • C ++保证将执行全局和静态对象的构造函数, .so知道这些类,或者有建构的概念。



    对于析构函数同样有效,但是至少有一些析构函数没有机会运行 - 例如当



  • In *nix .so libraries, is there an entry point that's invoked by the system when the library is loaded and unloaded?

    On a more practical note: if the .so was written in C++ and it contains global objects with constructors and destructors, and it's loaded from a language that has no notion of construction/destruction, are the global objects properly constructed/destructed?

    解决方案

    1. No, there is no equivalent to DllMain.

    2. For JNI libraries, e.g. on Android, there may be a special entry JNI_OnLoad which is intended to fill JNI function table.

    3. GCC defines special attribute constructor to allow some code to run on shared library load.

    4. C++ guarantees that the constructors for global and static objects will be performed, no matter if the code that loaded the .so was aware of these classes, or had notion of construction.

      Same holds for destructors, but there may be unhappy circumstances when at least some destructors have no chance to run - e.g. when there is a sigfault and exceptions are disabled.

    这篇关于Linux相当于DllMain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆