什么时候.so文件被装载Linux呢? [英] When do .so files get loaded Linux?

查看:164
本文介绍了什么时候.so文件被装载Linux呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享对象(a.so)链接到我的可执行myexe。
a.so暴露的方法称为get_val(),它myexe使用。

I have a shared object (a.so) which is linked to my executable myexe. a.so exposed a method called get_val(), which myexe is using.

现在,当a.so将被加载到myexe的进程地址空间?当myexe调用它get_val()API,或者当myexe被推出。

Now when a.so will be loaded into myexe's process address space? is it when myexe calls get_val() API, or when myexe gets launched.

推荐答案

有二(三)类型的库:


  • 静态库的(后缀: .A / 的.lib ),这本身变为二进制的一部分。严格来说,它不是全库,它是从哪个是满足未解决的链接库中的对象。

  • 共享(动态)库的(后缀:的.so / 的.dll ) ,它有两种类型,按时间区分库加载:

    • 动态链接库的,这是它的你告诉编译器和链接以及调用像静态库,但不属于你的库中的库 - 它们是由加载器/连接器加载(在Linux中,通常为__的main()从的libc 致电的dlopen()的一部分code>)。

    • 动态加载库的为您调用的dlopen()自己。

    • static libraries (suffix: .a / .lib), which itself becomes part of the binary. Strictly speaking, it's not the whole library, it's those objects from the library which are required to satisfy unresolved links.
    • shared (dynamic) libraries (suffix: .so / .dll), which come in two flavors, distinguished by the time the library is loaded:
      • dynamic link library, which are libraries of which you told the compiler and linker and which you call like static libraries but which are not part of your library - they are loaded by the loader/linker (in Linux usually as part of __main() from libc by calling dlopen()).
      • dynamic load library for which you call dlopen() yourself.

      (条件似乎有点模糊,我用不同的角度看待不同的文学,上述条款是我为了记住这些概念记住它。)

      (The terms seem a bit fuzzy, I've seen different literature using different terms; the terms above is how I memorized it in order to remember the concepts.)

      所以,如果你使用 a.so 无需调用的dlopen()自己, a.so 是一个动态链接库,所以它在程序启动时加载。在这种情况下,删除 a.so 从系统prevent启动您的程序 - 它会被加载,但它会在失败主()被调用。

      So, if you use a.so without calling dlopen() yourself, a.so is a dynamic link library, so it is loaded at program start. In that case, removing a.so from the system will prevent your program from starting - it will be loaded, but it will fail before main() gets called.

      如果您使用 a.so 与调用的dlopen()自己,这是你的掌控之中。

      If you use a.so with calling dlopen() yourself, it's completely under your control.

      在您的问题

      Q1:如果你调用的dlopen()自己,用 RTLD_LAZY A第一个未解决的电话,可以通过 a.so 解决时作出的.so 将被载入。如果你调用的dlopen()自己,用 RTLD_NOW a.so 之前即的dlopen()立即返回加载。如果你不叫的dlopen()自己,但让的libc 做的工作对你来说, a.so 将在程序开始加载。

      Q1: If you call dlopen() yourself, with RTLD_LAZY, the a.so will be loaded when the first unresolved call that can be resolved by a.so is made. If you call dlopen() yourself, with RTLD_NOW, a.so is loaded immediately, i.e. before dlopen() returns. If you do not call dlopen() yourself but let libc do the work for you, a.so will be loaded at program start.

      Q2:你删除 a.so 。如果你调用的dlopen() RTLD_LAZY ,并且不通过code,需要<$ C运行$ C> a.so ,程序将愉快地运行,否则信号将被提高。如果你不叫的dlopen()而是让的libc 为你做的工作,程序将无法成功启动。

      Q2: You delete a.so. If you call dlopen() with RTLD_LAZY, and do not run through the code that needs a.so, the program will run happily, otherwise a signal will be raised. If you do not call dlopen() but let libc do the work for you, the program will not start successfully.

      Q3:实际上,有没有办法来加载 a.so 无需调用的dlopen()(或东西相当于将取代它)。现在的问题就是,你叫的dlopen()自己,还是你让环境(即的libc )做为你的工作。

      Q3: Effectively, there is no way to load a.so without calling dlopen() (or something equivalent that would replace it). The question is just, do you call dlopen() yourself, or do you let the environment (i.e. libc) do the work for you.

      免责声明:我不是这个东西的专家,我的答案的某些部分可能是错误的。我会确认哪些我怀疑我自己,即无论是的libc 调用的dlopen()或别的东西,以及是否有可能即使你不使用的dlopen()自己有延迟绑定。一旦我有了结果我会更新的答案。

      Disclaimer: I'm not an expert for this stuff, and some parts of my answer may be wrong. I'll verify those parts of my answer on which I have doubts myself, i.e. whether it is libc that calls dlopen() or something else, and whether or not it's possible to have lazy binding even if you're not using dlopen() yourself. I'll update the answer once I have the results.

      这篇关于什么时候.so文件被装载Linux呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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