x64 .NET 编译/Process Explorer 奇怪之处
如果我要说的任何内容没有意义或忽略了一些明显的东西,我深表歉意 - 我对 CLR 内部结构的了解很参差不齐。
如果我理解正确,那么如果我只是在 VS2K5 中构建“AnyCPU”的解决方案(或将 MSBuild 指向具有这些设置的 .sln 文件),那么二进制文件仅编译至 MSIL。 然后,如果在 32 位平台上执行,它们会被 JITted 为 32 位;如果在 x64 上执行,它们会被 JITted 为 64 位代码……对吧?
这些 DLL 用于 Web 应用程序并托管在 W3WP.exe 进程中。 Process Explorer 告诉我 W3WP 是一个 64 位进程。
但是,当我使用 Process Explorer 在 DLL 视图中检查这些 DLL 之一的属性时,它显示:“图像:32 位”。 是什么赋予了?
如果我对有问题的 dll 运行 corflags ,它会告诉我: ILONLY 1 , 32BIT 0 but PE PE32 。 我的理解是,这意味着是的,它仅编译到 IL,不,它不限于 32 位或 64 位,但我并不完全清楚。 PE32 标志与上面显示的 32 位有什么关系吗?
Apologies if any of what I'm about to say makes no sense or overlooks something obvious - my knowledge of CLR internals is spotty.
If I understand correctly, then if I just build a solution for 'AnyCPU' in VS2K5 (or point MSBuild at that .sln file with those settings) then the binaries only compile as far as MSIL. They then get JITted to 32-bit if executed on a 32-bit platform or 64-bit code if executed on x64...right?
The DLLs are used for a web app and hosted in the W3WP.exe process. Process Explorer tells me W3WP is a 64-bit process.
But when I use Process Explorer to check the properties on one of these DLLs in DLL view, it says: 'Image: 32-bit'. What gives?
If I run corflags against the dll in question it tells me: ILONLY 1 , 32BIT 0 but PE PE32 . My understanding is that this means yes it is compiled only as far as IL, no it's not limited to either 32 bit or 64 bit, but I'm not entirely clear. Is the PE32 flag anything to do with it showing up as 32-bit as per above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题与此问题相关< /a>. 您在流程资源管理器中看到的是图像类型,它与程序集 corflags。
设置“Any Cpu”的目的是强制本机映像和程序集中最常见的分母,以便让 .NET 的 Windows 引导程序选择最适合当前平台的运行时类型。
因此,对于您的示例,您确实有一个 32 位映像(由 PE 标头指定),其中包含“任何 CPU”程序集(由程序集的 CorFlags 指定)。
Your question is related to this question. What you are seeing in process explorer is the type of image, which is different of the "runtime compatibility" type specified in the assembly's corflags.
The point of setting "Any Cpu" is to force the most common denominator in both the native image and the assembly, so that it lets the windows bootstrapper for .NET choose what kind of Runtime will be the most appropriate for the current platform.
So, for your example, you do have a 32 Bits image (as specified by the PE Header), containing an "Any CPU" assembly (as specified by the CorFlags for the assembly).
是的,您可以通过执行为 AnyCPU 编译的相同 exe 进行检查:
sizeof(IntPtr) == 4 //true on 32bit
sizeof(IntPtr) == 8 //true on 64bit
但是,如果在编译的进程中引用了您的程序集仅限 32 位平台,它将被编译为 32 位(在 64 位 Windows 的 WOW 中运行)。
Right, you can check by executing the same exe compiled for AnyCPU :
sizeof(IntPtr) == 4 //true on 32bit
sizeof(IntPtr) == 8 //true on 64bit
But, if your assembly is referenced in a process compiled for 32-bit platform only, it'll be jited to 32bit (run in WOW for 64-bit Windows).