Build platform target AnyCPU EXE still shows 32bit header in 64bit machine

我只是一个虾纸丫 提交于 2019-12-24 02:42:51

问题


Not sure this has been asked before (I could not find any). I have simple console app/ESE and have the below settings.

I'm running Windows 8, 63bit OS. And the EXE target framework .NET 4.5 However, when I compile this EXE, it still shows as a 32bit EXE.

Since this is "Any CPU", I would expect the EXE to compile as 64bit / PE32+.

Can some please help tell why this would be still 32bit?


回答1:


You are misinterpreting CorFlags I think. Here is a CorFlags truth table:

CPU Architecture           PE      32BITREQ   32BITPREF
------------------------   -----   --------   ---------
x86 (32-bit)               PE32           1           0
x64 (64-bit)               PE32+          0           0
Any CPU                    PE32           0           0
Any CPU 32-Bit Preferred   PE32           0           1

As you can see, it will only report PE32+ if you compile it as 64-bit and not as Any CPU. The reason is because the header must be backward compatible. meaning if an assembly is to work in 'Any CPU', both 32 and 64 bit, then the header format must be in a format recognizable by a 32-bit operating system. PE32+ is a 64-bit only header format and if that header was applied to an assembly compiled as Any CPU, then a 32-bit operating system would not recognize the PE32+ header format.




回答2:


The exe files doesn't contain any 32-bit or 64-bit code, it only contains IL code.

The JIT compiler creates machine code from the IL code, and the platform target determines what kind of machine code the JIT compiler is allowed to create.



来源:https://stackoverflow.com/questions/27830701/build-platform-target-anycpu-exe-still-shows-32bit-header-in-64bit-machine

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