gcc 4.2 to llvm-gcc 4.2 transition

Hi,

I am currently studying the possibility to make the transition from gcc 4.2 to llvm-gcc 4.2 for the projects I am working on.
These projects are huge projects, most of the source code is written in C++ but we have objc, c and assembly code. We are targeting MacOSX 10.5 and MacOSX 10.6.

Our build system is currently running on MacOSX 10.5 and uses Xcode 3.1.4 with gcc 4.2. It is used to generate the release builds we ship and the beta releases. We could possibly switch this machine to 10.6 and Xcode 3.2.x. We still plan to support 10.5 for some time.

Switching the compiler to llvm-gcc 4.2 on 10.6 with Xcode 3.2.3 is smooth. By just changing the compiler setting in Xcode, I was basically able to compile the projects with llvm-gcc 4.2 with no major issues. On 10.5 with Xcode 3.1.4, it is a different story. Xcode 3.1.4 contains an old version of llvm-gcc 4.2 which can't build our applications. There are 2 causes of the compilation failure:

- llvm-gcc 4.2 contained in Xcode 3.1.4 can't compile CodeWarrior or Microsoft inline assembly.

- llvm-gcc 4.2 contained in Xcode 3.1.4 doesn't recognize some i386 inline assembly instructions ("mov edx,aFloat" where aFloat is a float*).

These issues prevent us to switch from gcc 4.2 to llvm-gcc 4.2. We could switch our build system to 10.6 but if we have a 10.5 specific issue, we need to be able to compile and debug our code on 10.5 on the developers machines. I would like to avoid to temporary change all the projects to gcc 4.2 on a machine in order to fix a 10.5 issue (and to hope the compiler doesn't change the issue behavior).

We have right now several possibilities:

- we don't switch to llvm-gcc 4.2 until we drop 10.5 support. But that could be in 1 or 2 years. At this point we might decide to switch directly to LLVM 2.0 since Xcode 4 will probably be available.

- we hope that Apple release for 10.5 a new version of Xcode (Xcode 3.1.5) with an updated llvm-gcc 4.2 compiler. I really doubt about it.

- we find a way to update the llvm-gcc 4.2 version in Xcode 3.1.4. I haven't investigated this point yet. Does anyone know if this is possible at all?

Does anyone have some recommendations? Is llvm-gcc 4.2 appropriate to use in our case or should we keep using gcc 4.2 for some time?

Thanks,
Alexandre

Since you are switching compilers, why not switch to clang instead of
llvm-gcc?

Best regards,
--Edwin

2010/7/24 Török Edwin <edwintorok@gmail.com>

There are several reasons why I am currently not considering the transition to Clang (although I would love to switch to it):

- Clang (LLVM compiler 2.x) is only integrated by default in Xcode 4 which has not been released yet. I guess it might be possible to use Clang in Xcode 3.2 and Xcode 3.1.

- Clang is a new compiler and the C++ support is really new and might contain bugs. Moreover Apple recommends to use llvm-gcc 4.2. The default compiler with Xcode 4 will be llvm-gcc 4.2 and not clang.

- Our code is mostly written in C++. The LLVM 1.0 compiler included in Xcode 3.2.x can't compile C++ code and falls back to llvm-gcc 4.2.So even If we switch to LLVM 1.0, it is very likely that we will get the exact same issues as if we switch to llvm-gcc 4.2.

- Some of our code (or third party code we use) contains gcc predefined macro and we also have some third party libraries. With llvm-gcc we would keep the gcc parser which means less compatibility issues.

- I am not sure if clang can generate code that runs on 10.5.

Alexandre

There are several reasons why I am currently not considering the transition to Clang (although I would love to switch to it):

- Clang (LLVM compiler 2.x) is only integrated by default in Xcode 4 which has not been released yet. I guess it might be possible to use Clang in Xcode 3.2 and Xcode 3.1.

Right.

- Clang is a new compiler and the C++ support is really new and might contain bugs. Moreover Apple recommends to use llvm-gcc 4.2. The default compiler with Xcode 4 will be llvm-gcc 4.2 and not clang.

Clang is actually going to be the default for new projects, but you're right that llvm-gcc is much more mature.

- Our code is mostly written in C++. The LLVM 1.0 compiler included in Xcode 3.2.x can't compile C++ code and falls back to llvm-gcc 4.2.So even If we switch to LLVM 1.0, it is very likely that we will get the exact same issues as if we switch to llvm-gcc 4.2.
- Some of our code (or third party code we use) contains gcc predefined macro and we also have some third party libraries. With llvm-gcc we would keep the gcc parser which means less compatibility issues.

Clang should be very compatible with GCC and its extensions, except that it is more pedantic about enforcing C++ language rules. One major feature not supported by clang yet is "microsoft/codewarrier style inline assembly". Since you are apparently using this, Clang sounds like a non-starter for you for now.

- I am not sure if clang can generate code that runs on 10.5.

It can, but it does not support powerpc (llvm-gcc does).

-Chris

I am currently studying the possibility to make the transition from gcc 4.2 to llvm-gcc 4.2 for the projects I am working on.
These projects are huge projects, most of the source code is written in C++ but we have objc, c and assembly code. We are targeting MacOSX 10.5 and MacOSX 10.6.

Ok, great!

Our build system is currently running on MacOSX 10.5 and uses Xcode 3.1.4 with gcc 4.2. It is used to generate the release builds we ship and the beta releases. We could possibly switch this machine to 10.6 and Xcode 3.2.x. We still plan to support 10.5 for some time.

Xcode 3.2 running on 10.6 definitely supports building apps for 10.5.

Switching the compiler to llvm-gcc 4.2 on 10.6 with Xcode 3.2.3 is smooth. By just changing the compiler setting in Xcode, I was basically able to compile the projects with llvm-gcc 4.2 with no major issues. On 10.5 with Xcode 3.1.4, it is a different story. Xcode 3.1.4 contains an old version of llvm-gcc 4.2 which can't build our applications. There are 2 causes of the compilation failure:

- llvm-gcc 4.2 contained in Xcode 3.1.4 can't compile CodeWarrior or Microsoft inline assembly.

- llvm-gcc 4.2 contained in Xcode 3.1.4 doesn't recognize some i386 inline assembly instructions ("mov edx,aFloat" where aFloat is a float*).

Right. llvm-gcc in 3.1.4 is really really ancient and buggy. I really don't recommend using it.

These issues prevent us to switch from gcc 4.2 to llvm-gcc 4.2. We could switch our build system to 10.6 but if we have a 10.5 specific issue, we need to be able to compile and debug our code on 10.5 on the developers machines. I would like to avoid to temporary change all the projects to gcc 4.2 on a machine in order to fix a 10.5 issue (and to hope the compiler doesn't change the issue behavior).

Apple fully supports deployment of apps to 10.5 machines when built on 10.6.

We have right now several possibilities:

- we don't switch to llvm-gcc 4.2 until we drop 10.5 support. But that could be in 1 or 2 years. At this point we might decide to switch directly to LLVM 2.0 since Xcode 4 will probably be available.

Yep.

- we hope that Apple release for 10.5 a new version of Xcode (Xcode 3.1.5) with an updated llvm-gcc 4.2 compiler. I really doubt about it.

Not going to happen, Apple only releases new tools for their current OS's.

- we find a way to update the llvm-gcc 4.2 version in Xcode 3.1.4. I haven't investigated this point yet. Does anyone know if this is possible at all?

This is definitely possible, but you have to build your own copy of llvm-gcc off llvm.org. This will give you a configuration that Apple will not support, but it should work fine.

Does anyone have some recommendations? Is llvm-gcc 4.2 appropriate to use in our case or should we keep using gcc 4.2 for some time?

llvm-gcc (in Xcode 3.2.3 or later) is fully mature, and a heck of a lot less buggy than apple gcc 4.2. I strongly recommend upgrading to it.

-Chris

Really? I couldn't find any Apple documentation that mentions this.
Also we have built powerpc code with the clang "LLVM compiler 1.5" and it does run on powerpc.

Should we use the llvm-gcc compiler for the powerpc architecture instead?

Thomas

clang in Xcode is compiled without powerpc support, it'll fall back to gcc.

That's right and it actually falls back to llvm-gcc.
I didn't know that.

Thanks!
Thomas

Thanks for the answers. We will first switch our build system to 10.6 and Xcode 3.2.x and then probably switch our projects to llvm-gcc 4.2.

- we find a way to update the llvm-gcc 4.2 version in Xcode 3.1.4. I haven't investigated this point yet. Does anyone know if this is possible at all?

This is definitely possible, but you have to build your own copy of llvm-gcc off llvm.org. This will give you a configuration that Apple will not support, but it should work fine.

I will check if I can make a custom build of llvm-gcc to use on MacOSX 10.5 with Xcode 3.1.4. This would only be used if we need to boot on 10.5 to fix 10.5-only issues with our products.
As long as we can easily compile and debug our code on 10.5, I'm fine with that.

Clang should be very compatible with GCC and its extensions, except that it is more pedantic about enforcing C++ language rules. One major feature not supported by clang yet is "microsoft/codewarrier style inline assembly". Since you are apparently using this, Clang sounds like a non-starter for you for now.

We are indeed using microsoft/codewarrior inline assembly. This is another reason why we can't currently use Clang.

- I am not sure if clang can generate code that runs on 10.5.

It can, but it does not support powerpc (llvm-gcc does).

ppc is not really an issue. We plan to drop support for it soon. Also we can't use Clang anyway.

Keep up the good work on Clang,
Alexandre