出于好奇,加载使用 MSVCR 编译的应用程序时究竟会发生什么。Windows的加载器实际上是如何初始化CRT的?对于我到目前为止所收集的内容,当程序以及所有导入的库都加载到内存中并且所有重定位都完成时,CRT 启动代码 ( _CRT_INIT()
?) 会初始化.CRT$XC*
部分中的所有全局初始化程序并调用用户定义的main()
函数。我希望到目前为止这是正确的。
But let's assume, for the sake of explanation, a program that is not using the MSVCR (e.g. an application built with Cygwin GCC or other compilers) tries to load a library at runtime, requiring the CRT, using a custom loader/runtime linker, so no LoadLibrary()
involved. How would the loader/linker has to handle CRT initialization? Would it have to manually initialize all "objects" in said sections, does it have to do something else to make the internal wiring of the library work properly, or would it have to just call _CRT_INIT()
(which unpractically is defined in the runtime itself and not exported anywhere as far as I am aware). Would this mix-up even work in any way, assuming that the non-CRT application and the CRT-library would not pass any objects, exceptions and things the like between them?
我很想知道,因为我不太清楚 CRT 对实际加载过程有什么影响......
任何信息都非常感谢,谢谢!