2

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

enter image description here

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.

enter image description here

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?

Spock
  • 7,009
  • 1
  • 41
  • 60

2 Answers2

8

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.

Icemanind
  • 47,519
  • 50
  • 171
  • 296
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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Thanks. If the "Platform target" determines what kind of machine code the JIT compiler should create, should it be 64bit since it is AnyCPU? – Spock Jan 07 '15 at 23:54
  • @Spock: I can't be 64-bit for AnyCPU, because a 32-bit system has to be able to create 32-bit code from it. – Guffa Jan 08 '15 at 09:47