2

Is it safe to assume that any x86 compiled app would always run under x64 edition of same OS the app was compiled in?

As far as I know, For Windows OS the answer is "Yes". Windows x86 emulation layer is built for the same purpose. But, I just want to reconfirm this from experts here.

What about Unix, Linux? Are there any caveats?

user1
  • 4,031
  • 8
  • 37
  • 66
  • just a sidenote concerning Windows: as far as I know WinPE (the "emergency mode" of Windows) does not provide 32 bit emulation when created using a Windows x64. – Marged Oct 21 '15 at 06:20
  • And obviously if the program has any bugs it might behave differently on x64. – Harry Johnston Oct 21 '15 at 21:14

2 Answers2

4

No, for x86 code to run it need to be run in compatibility or legacy mode. If the OS doesn't support running processes in compatibility mode the program would most likely not being able to run.

Linux and IFAIK Windows currently supports compatibility mode and it looks like many more are supporting it too, more or less. My understanding is that NETBSD requires a special module to support this, so it's not necessarily without special care that it will be supported and it shows that it's quite possible that there exists OS'es where the possibility has been dropped completely.

Then in addition there's the possibility of breaking the backwards compatibility in the future, that's already happened on the CPU as virtual x86 mode is no longer available from long mode that is you can't run 16 bits program anymore under 64-bit Windows or Linux.

It could also happen on the OS side, that the developers could decide not to support compatibility mode anymore. Note that this may also have happened as it might be possible to support virtual x86 mode by first switching to legacy mode, but if possible no-one seem to have bothered doing it. Similarly neither Windows or Linux developers seems to have bothered implementing possibility to run kernel code in legacy mode in 64-bit kernel.

The preceding two sections shows that there are future or even present indications on this might not always be possible.

Besides as this is a C++ question you would have to ask yourself the question why you would want to make such a assumption? If well written your code should be able to be compiled for 64-bit mode - for you haven't relied on data types being of specific width, have you?

skyking
  • 13,817
  • 1
  • 35
  • 57
  • 1
    Addition: For some stuff like drivers on Windows, there never was any compatibilty. – deviantfan Oct 21 '15 at 11:08
  • 1
    @deviantfan Yes, that's probably also true for Linux. It's similar to the restriction that they closed the virtual x86 possibility as it would require the kernel to switch to 32-bit mode first. – skyking Oct 21 '15 at 11:19
2

No. We have a whole bunch of Debian servers which miss the Multi-Arch i386 (32 bits) libraries. On Windows Server Core, WoW64 (the 32 bit subsystem) is optional. So for both Linux and Windows, there are known 64 bit systems that won't run x86 executables.

MSalters
  • 173,980
  • 10
  • 155
  • 350