x64 .NET compilation / Process Explorer oddity

谁说胖子不能爱 提交于 2020-01-03 14:43:29

问题


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?


回答1:


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).




回答2:


They then get JITted to 32-bit if executed on a 32-bit platform or 64-bit code if executed on x64...right?

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).



来源:https://stackoverflow.com/questions/247098/x64-net-compilation-process-explorer-oddity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!