Adding a secondary toolchain
Background
In OpenEmbedded-Core there in an included toolchain that is built up of GNU binutils, gcc, and eglibc. In addition related components such as gdb, cross-prelink, mklibs and others provider additional toolchain functionality. In this document we focus on explaining best practices for including an additional toolchain that is capable of assembling, compiling and linking code. This document does not cover replacing the existing toolchain or toolchain components with external elements.
Many companies have commercial / highly optimized toolchains for specific purposes, such as ICC from Intel, LLVM, ARM Ltd toolchains, etc.. In some cases, these highly optimized toolchains may result in better performance for some applications, however they are often not generally applicable as they can not compile all of the system software. So instead of replacing the included GNU toolchain, a mechanism for providing an alternative/secondary toolchain is desired.
Requirements
Secondary Toolchains should be implemented in a layer
In order to facilitate re-use and make it easier to completely disable the secondary toolchain, a layer must be used to implement the secondary toolchain.
Secondary Toolchain must be generally compatible with GNU toolchain
The secondary toolchain must be generally compatible with the idea of sysroots, linking to the defined libc, and various GNU conventions. This compatibility may be implemented directly by the secondary toolchain or via a wrapper of some type.
Per recipe selection of toolchain usage
A mechanism is needed to activate this alternative toolchain on a per-recipe basis. Using variables it should be possible to specify on a per-recipe basis which toolchain should be used, leaving the default up to the user. (It's assumed if the user does not select a default, the system GNU toolchain will be defaulted.)
Blacklist/Whitelist
Even with the requirement to be generally compatible, we can not expect all of the possible recipes to build properly with the secondary toolchain. As a consequence of this, it will be necessary to implement a blacklist (or whitelist) of specific recipes that are known to work. This way only supported components can be build by the user, avoid numerous complaints and unresolvable defects.
SDK
The SDK generated by OpenEmbedded-Core also includes the included toolchain components. It would be useful to also provide support for the secondary toolchain within the SDK environment.
Implementation
Bitbake variables
A set of common bitbake variables, defined in meta/conf/bitbake.conf, are used to define how to run the toolchain components and the proper arguments.
A number of key items may need to be changed, depending on the toolchain being provided. These items may include:
* TARGET_CPPFLAGS * TARGET_CFLAGS * TARGET_CXXFLAGS * TARGET_LDFLAGS * CC * CXX * F77 * CPP * LD * CCLD * AR * AS * RANLIB * STRIP * OBJCOPY * OBJDUMP * NM * SELECTED_OPTIMIZATION * FULL_OPTIMIZATION * DEBUG_OPTIMIZATION
Each of the above items has a default definition within the meta/conf/bitbake.conf file. In addition, many of the components are based on specific tune variables such as:
* TUNE_CCARGS * TUNE_LDARGS * TUNE_ASARGS
Deciding which items need to be overridden is up to the author of the layer. It is expected that only a subset of the above referenced variables will need secondary toolchain specific versions for most implementations.
Override
In order to allow for the layer to selectively override the variables listed above, a standard override syntax is needed.
The standard override syntax will be 'toolchain-${TOOLCHAIN}'. This will allow us to specify multiple alternative and primary toolchain combinations as necessary.
Each of the toolchain related variables can then be overridden using the standard override syntax: _toolchain-<toolchain>, such as:
CC_toolchain-icc = "icc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
In order for an individual recipe to use the secondary toolchain, the user would define: TOOLCHAIN_pn-<recipe> = 'toolchain', such as:
TOOLCHAIN_pn-bash = "icc"
The OVERRIDE is implemented in the tc-secondary.bbclass in the example.
Blacklist/Whitelist
A standard blacklist/whitelist facility is to be implemented. This facility is independent of the existing blacklist class that is part of OpenEmbedded-Core.
Similar to the existing blacklist class, you will be able to define a blacklist, per toolchain type, such as:
TCBLACKLIST[pn] = "toolchain"
or alternatively create a whitelist facility using:
TCBLACKLIST = "toolchain" TCWHITELIST[pn] = "toolchain"
Using the second approach will allow you to blacklist all recipes, and only enable those known to work with the alternative toolchain. A standard implementation is available in the secondary toolchain example.
SDK
MGH: Add SDK extension details
Implementation Example
The following example implements a secondary toolchain. The example is generated in a new layer named: meta-toolchain-test
MGH: include example here..