32 versus 64-bit programs

Unixwiz is not the only one confused by how our compilers decide whether to create a 32–bit or a 64–bit executable. I started to answer a similar question on the forums the other day. The confusion really only pops up if you use both Sun compilers  and gcc compilers, or if you use the Sun compilers on Linux.

I’ll start with the short answer before I explain why. The short answer is that Sun compilers on Solaris generate 32–bit binaries by default. Gcc running on a 64–bit platform generates 64–bit binaries by default. When porting our compilers to Linux, we decided to emulate gcc on Linux, but not change our default behavior on Solaris.

It seems confusing at first, until you realize that Solaris really looks like a 32–bit OS to users.  Remember Solaris has supported 64–bit programs for eons now. (“eons” because I’m too lazy to look up the exact number of years, but it’s been a long time.) Adding support in Solaris for 64–bit programs didn’t change too much.  All the utilities were still 32–bit programs (almost all) and there is only one version of the OS. The 64–bit support was implemented as additional files, libraries. etc installed along with the 32–bit bit files that were already there.

On Linux, they took a different approach.  Amd64 was seen as another different platform. All the utilities, libraries, etc are 64–bit by default. Then 32–bit files are merged in there to try to support 32–bit programs.  Because of that choice, when you run a 32–bit program on a 64–bit version of Linux, you’re not quite getting a 100% tested behavior. As an example, the dbx group had serious trouble with the behavior of some of the debugging libraries (libthread_db etc) that Linux provides to help debuggers inspect processes. Because of the gcc defaults, in you naively build and install a package on a 64–bit Linux, you’ll only get the 64–bit libraries. This has a cascade effect, and any clients that want to use those libraries are more likely to have their dependencies met if they also try to live in the 64–bit world.

Anyway, that’s why the default behavior for the Sun compilers is different on Linux, and why the Sun compilers on Solaris are different than gcc on Linux.

As a side note:

The Sun compilers used to require you to specify your exact instruction set variant when you specified whether you wanted a 32–bit or 64–bit program.  Most people are really better off letting compiler choose whether to use SPARC VIS instructions or intel SSE instructions or gobbledy goop like that. So we’ve added support for gcc’s -m32  and -m64 options to select whether you want your program to use the 32–bit or 64–bit ABI (works the same on sparc and x64 based processors).  If you been using -xarch=v9 on sparc to specify a 64–bit program, I highly recommend that you start to use -m64 when the next major release of the compilers comes out.   

Gotta run to family get together now, more later.

BTW, I’m liking BlogJet, but I wish it had a button for ‘preformatted’ text.  I expect to splatting code into my blogs on a regular basis.  I installed Xinha (thanks for the nudge Dave!) But I haven’t gotten a chance to use it yet.

—chris

 

Comments:

Post a Comment:
Comments are closed for this entry.
About

Chris Quenelle

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today