NT DLL Loader是否按照可执行文件的导入部分的顺序加载DLL? [英] Does the NT DLL Loader load DLLs in the order of the import section of the executable?

查看:246
本文介绍了NT DLL Loader是否按照可执行文件的导入部分的顺序加载DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在Windows上有可执行文件,您可以使用DUMPBIN实用程序(包括在Visual Studio中)查看其导入部分。

If you have an executable on Windows, you can view its import section with the DUMPBIN utility (included e.g. in Visual Studio).

要获取所有导入的DLL可以运行这样的东西(只是一个例子):

To get a list of all imported DLLs you can run something like this (just an arbitrary example):

C:\Programme\GIMP-2.0\bin>dumpbin /IMPORTS gimp-2.4.exe | grep -i \.dll
    libgimpcolor-2.0-0.dll
    libgimpmath-2.0-0.dll
    libgimpmodule-2.0-0.dll
    libgimpthumb-2.0-0.dll
    libgimpwidgets-2.0-0.dll
    libart_lgpl_2-2.dll
    libfontconfig-1.dll
    freetype6.dll
    libgdk-win32-2.0-0.dll
    libgdk_pixbuf-2.0-0.dll
    libglib-2.0-0.dll
    libgobject-2.0-0.dll
    libgthread-2.0-0.dll
    libgtk-win32-2.0-0.dll
    intl.dll
    libpango-1.0-0.dll
    libpangoft2-1.0-0.dll
    libgimpbase-2.0-0.dll
    libgimpconfig-2.0-0.dll
    KERNEL32.dll
    msvcrt.dll
    msvcrt.dll
    USER32.dll

我现在已经在另一个问题中猜测 / a>,独立DLL的 ,Loader(将DLL映射到地址空间中并调用其DllMain函数的组件)将按照以下顺序加载DLL:

I have now speculated in another question that, for independent DLLs the Loader (the component that maps the DLLs into the address space and calls their DllMain function) will load the DLLs in the order in which they appear in the import section.

注意:这显然只适用于独立的DLL,因为加载程序必须解析依赖关系,所以任何DLL这取决于任何其他将永远是加载器之后的另一个。

Note: This can obviously only apply to independent DLLs because the loader will have to resolve dependencies so any DLL that is dependent on any other will always be loader after the other. So this question can only apply to independent (non-system) DLLs.

为了保持我上面的(任意选择)的例子, p>

To stay with my (arbitrarily chosen) example above,

C:\Programme\GIMP-2.0\bin>dumpbin /IMPORTS libgimpcolor-2.0-0.dll | grep -i \.dll
Dump of file libgimpcolor-2.0-0.dll
    libglib-2.0-0.dll
    libgobject-2.0-0.dll
    msvcrt.dll

C:\Programme\GIMP-2.0\bin>dumpbin /IMPORTS libgimpmath-2.0-0.dll | grep -i \.dll
Dump of file libgimpmath-2.0-0.dll
    libglib-2.0-0.dll
    libgobject-2.0-0.dll
    msvcrt.dll

C:\Programme\GIMP-2.0\bin>dumpbin /IMPORTS libgobject-2.0-0.dll | grep -i \.dll
Dump of file libgobject-2.0-0.dll
    libglib-2.0-0.dll
    KERNEL32.dll
    msvcrt.dll

C:\Programme\GIMP-2.0\bin>dumpbin /IMPORTS libglib-2.0-0.dll | grep -i \.dll
Dump of file libglib-2.0-0.dll
    iconv.dll
    intl.dll
    ADVAPI32.DLL
    KERNEL32.dll
    msvcrt.dll
    msvcrt.dll
    OLE32.dll
    SHELL32.DLL
    USER32.dll
    WS2_32.DLL

libgimpmath libgimpcolor 在这个意义上,独立的DLL。所以这里的问题是:Loader总是在 libgimpmath 之前加载 libgimpcolor ,因为它是导入部分的第一个

libgimpmath and libgimpcolor are independent DLLs in that sense. So here the question would be: Will the Loader always load libgimpcolor before libgimpmath because it comes first in the import section?

推荐答案

对于独立的DLL,加载顺序确实与IAT的顺序相同。

For independent DLLs, the load order is indeed the same as the order of the IAT.


Michael Grier的MSDN博客

From Michael Grier's MSDN Blog

实现是线性的/顺序的。因此即使静态导入表中的导入顺序也是重要的。 [...]如果链接器由于某种原因导致静态导入的顺序倒转,您会看到相反的。

The implementation is linear/sequential. Therefore even the order of the imports in your static import tables matters. [...] If the linker for some reason reverses the order of the static imports, you'll see the opposite.

这篇关于NT DLL Loader是否按照可执行文件的导入部分的顺序加载DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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