Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX 10.6 compiler: a puzzling experience with 32 vs 64 bit

I have trouble understanding the gcc compiler provided by OSX 10.6 snow leopard, mainly because of my lack of experience with 64 bits environments.

$ cat >foo.c
main() {}
$ gcc foo.c -o foo
$ file foo
foo: Mach-O 64-bit executable x86_64
$ lipo -detailed_info foo
input file foo is not a fat file
Non-fat file: foo is architecture: x86_64

However, my architecture is seen as an intel i386 type (I have one of the latest Intel Core2 duo MacBook)

$ arch
i386

and the compiler targets i686-apple-darwin10

$ gcc --version 
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)

Of course, if I compile 32 bits I get a 32 bit executable.

$ gcc -m32 foo.c -o foo
$ file foo
foo: Mach-O executable i386

but I don't get the big picture. The default setup for the compiler is to produce x86_64 executables, even if I have arch saying I have a 32 bit machine (why? Core2 is 64); even if (I guess) I am running a 32 bit kernel; even if I have a compiler targeting the i686-apple-darwin platform. Why? How can they run ? Should I compile 64 or 32 ?

This question is due to my attempt to compile gcc 4.2.3 on the mac, but I am having a bunch of issues with gmp, mpfr and libiberty getting (in some cases) compiled for x86_64. Should I compile everything x86_64 ? If so, what's the target (not i686-apple-darwin10 I guess)?

Thanks for the help

like image 894
Stefano Borini Avatar asked Sep 21 '09 17:09

Stefano Borini


People also ask

How do I know if I should install 32-bit or 64-bit Mac?

To see if your Mac's processor is 32-bit or 64-bit, go to the Apple menu and choose About This Mac. Below the operating system version and computer model name you'll see your processor. If the processor is an Intel Core Solo or Intel Core Duo, it's 32-bit only.

Will 32-bit programs run on 64-bit Mac?

32-bit apps can run on a 64-bit system as they've been doing for years, but Apple wants to get rid of outdated apps to make sure everything that runs on the Mac is properly optimized and isn't an unnecessary drain on system resources.

Why did macOS stop supporting 32-bit?

This means that many legacy apps will no longer function at all. The answer to why Apple is dropping 32-bit app support is quite simple: to improve the performance of the iPhone.

Is Mac Sierra 64-bit high?

Even in High Sierra, as of this writing, all of Apple's code is 64-bit—but you can continue to develop and run 32-bit apps as long as there's not some other compatibility problem. January 2018: All new apps submitted to the Mac App Store need to be 64-bit only.


1 Answers

The default compiler on Snow Leopard is gcc4.2, and its default architecture is x86_64. The typical way to build Mac software is to build multiple architectures in separate passes, then use lipo to combine the results. (lipo only compiles single-arch files into a multiple-arch file, or strips archs out of a multi-arch file. It has no utility on single-arch files, as you discovered.)

The bitness of the compiler has nothing to do with anything. You can build 32-bit binaries with a 64-bit compiler, and vice versa. (What you think is the "target" of the compiler is actually its executable, which is different.)

The bitness of the kernel has nothing to do with anything. You can build and run 64-bit binaries when booted on a 32-bit kernel, and vice versa.

What matters is when you link, whether you have the appropriate architectures for linking. You can't link 32-bit builds against 64-bit binaries or vice versa. So the important thing is to see what the architectures of your link libraries are, make sure they're coherent, then build your binary of the same architecture so you can link against the libraries you have.

like image 199
cdespinosa Avatar answered Nov 16 '22 04:11

cdespinosa