tags:

views:

391

answers:

3

How is Linux simultaneously 32bit and 64bit? Or is that something handled in glibc?

I run CentOS 5.3 and it is a "64 bit" version; although I build things for 64 bit and 32 bit. From what I think I know, Windows supposedly has a 32bit emulator. Does Linux do the same thing? Is it in userspace or kernel space?

If libc handles it, is it kind of like a emulator that says, I'll link with 32 bit apps, but speak 64 bit to the kernel?

+2  A: 

Nothing is stopping the cpu from switching from 64bit to 32bit. It just switches.

You can have a 64 bit kernel, and run 32bit apps. You can even have a 32bit kernel and run 64bit apps(Mac os x).

However you need the libaries they use to also be 32bit or or 64bit, which is why you might see files called lib64 or lib32 on linux for the 64bit or 32bit libaries.

UK-AL
Linux does not support running 64-bit userspace on a 32-bit kernel.
ephemient
It is possible though. xnu does it.
UK-AL
+1  A: 

Because x86_64 processors are designed over x86 technology, they are still able to support 32-bit programs without any hardware emulation, like what you would need to run x86 programs in a PowerPC or Sparc environment. In Linux, all you need to do is install the necessary software libraries to run the 32-bit software.

Aaron M
+5  A: 

The cpu can execute both 64 and 32bit instructions and the kernel can switch between modes. The only limitation is that you cannot link 32bit programs against 64bit libraries so you must have both 32 and 64bit versions of libc, etc. installed.

akosch
To answer the question more directly, a 64-bit program "speaks" 64-bit to the kernel and a 32-bit program "speaks" 32-bit to the kernel, and the kernel understands both, presuming that `CONFIG_IA32_EMULATION` was set when the kernel was compiled. Actually, 64-bit programs are even allowed to make 32-bit syscalls, though that's a bit perverse...
ephemient