Cross compilation in the 64-bit .NET Framework world for platform specific features

In today’s world, a lot of applications are written targeting both the 32-bit and/or the 64-bit platform. Using cross compilation, users can now create applications using the .NET Framework which are platform agnostic. This is achieved by the data in the PE header maintained for each app in the .NET Framework world.

Compilers like that of C# and C++ language use the /platform switch to empower the user to choose the platform type, they want their binaries to be executed on. Using this switch the users can just compile their binaries to be anycpu binaries – which implies that they are platform agnostic and execute natively on the 32-bit and the 64-bit platforms. This also enables users to compile binaries specific to a targeted platform – be it x86, x64 or the itanium platform.

This looks to be a perfect solution for compilation of binaries that do not have any feature dependencies on platform specific architectures. Now, lets take a hypothetical scenario where a language supports some features that are 32-bit specific and some features that are platform agnostic. In such cases how should the compiler behave? Here is description of the way I feel applications should be targeted in such cases

Compilation from

Anycpu

X86

X64

IA64

32-bit compiler on a 32-bit machine

Invokes the 32-bit compiler

Invokes the 32-bit compiler

Error

Error

32-bit WoW compiler on a 64-bit machine

Invokes the 64-bit compiler as another process and compiles using the same

Invokes the 32-bit compiler

Invokes the 64-bit compiler as another process and compiles using the same

Invokes the 64-bit compiler as another process and compiles using the same

64-bit compiler

Invokes the 64-bit compiler

Invokes the 32-bit compiler as another process and compiles using the same

Invokes the 64-bit compiler

Invokes the 64-bit compiler

Apart from the compiler, the users should also be aware of the compiler they are compiling from and the targeted scenarios. For e.g. Let us consider an application which is dependent of features not supported in the 64-bit world. The user compiles the same to a binary of the type anycpu from a 32-bit machine. The user then tries to execute the same binary on a 64-bit machine. In most of the cases the user is bound to run into issues and a Bad Format Exception might be thrown. Thus, it is not true that in all scenarios, cross compilation always works.

In case you believe that there is some other way, let me know too.