GCC Hybrids

What is a GCC Hybrid?

With Changeset 25536, it became possible to build Haiku as a GCC Hybrid. In such a case, Haiku will be capable of running binaries that are compiled with either GCC 2.95 or GCC 4.x. As of Changeset 30875, it became possible to use a GCC Hybrid to compile objects for either GCC.

In a GCC Hybrid, there is the main GCC and the alternative GCC. The main GCC is the version that was used to compile Haiku. The alternative GCC provides both a runtime time environment and a cross-compiler for using and creating other-GCC objects. Switching between compilers is done with a simple command : setgcc -h.

Since x86 is the only platform for which BeOS R5 binary compatibility is possible, no other target platforms need to be built with gcc2. Thus, x86 is the only platform that a GCC Hybrid is usable.

Which GCC should I use?

In short, a GCC 2 Hybrid. For R1 and earlier releases, GCC 2 Hybrid is the offiicial release style. As such you can expect the least amount of issues on it.

Due to the way Haiku handles libaries and related files, it is easier to run BeOS R5 programs on a GCC 2 Hybrid. For example on a GCC 2 Hybrid, libraries built with gcc2 belong in */lib/ and those built with gcc4 need to be in */lib/gcc4/. Since BeOS software is not aware of this convention, it will unconditionally install its libraries into */lib/. As a result, there may be issues with any software that does not take this convention into account.

Why not GCC 4?

Even though GCC 4 has stronger optimization algorithms, the performance increase from compiling Haiku with GCC 4 is nil to none. More importantly, for R1 and earlier releases, only the GCC 2 ABI can be considered stable and future proof. Once R1 is released, binaries built with GCC 4 will need to be recompiled (and more than likely have their sources updated for new API).

How are GCC Hybrids built?

Setting up directories

  /path/haiku/buildtools/
  /path/haiku/haiku/
  /path/haiku/haiku/generated.x86gcc2
  /path/haiku/haiku/generated.x86gcc4

Configuring the directories

Be sure to consult the various configure options, such as --use-gcc-pipe, --use-xattr, and -j<N>

...within Haiku

  cd generated.gcc4
  ../configure --alternative-gcc-output-dir ../generated.x86gcc2 --cross-tools-prefix /boot/develop/abi/x86/gcc4/tools/current/bin/
  cd ..
  cd generated.gcc2
  ../configure --alternative-gcc-output-dir ../generated.x86gcc4 --cross-tools-prefix /boot/develop/abi/x86/gcc2/tools/current/bin/
  cd ..

...from another OS

  cd generated.x86gcc2
  ../configure --alternative-gcc-output-dir ../generated.x86gcc4 --build-cross-tools ../../buildtools/
  cd ..
  cd generated.x86gcc4
  ../configure --alternative-gcc-output-dir ../generated.x86gcc2 --build-cross-tools-gcc4 x86 ../../buildtools/
  cd ..

Jamming inside one of the generated folders

Be sure to consult the various jam options.

GCC 2.95 with GCC 4.x as secondary libraries (x86gcc2hybrid)

  cd generated.x86gcc2
  jam -q @nightly-raw

GCC 4.x with GCC 2.95 as secondary libraries (x86gcc4hybrid)

  cd generated.x86gcc4
  jam -q @nightly-raw

GCC 2.95 Only

  cd generated.x86gcc2
  jam -q -sHAIKU_ADD_ALTERNATIVE_GCC_LIBS=  @nigthly-raw

GCC4 Only

  cd generated.x86gcc4
  jam -q -sHAIKU_ADD_ALTERNATIVE_GCC_LIBS=  @nightly-raw
Without re-configuring, non-hybrids can be built from the same generated folder. This is accomplished by unsetting the variable HAIKU_ADD_ALTERNATIVE_GCC_LIBS=. Notice there is no text attached to the equal sign.