Difference between revisions of "Adding a secondary toolchain"

From Openembedded.org
Jump to: navigation, search
(Implementation Example)
Line 101: Line 101:
=== SDK ===
=== SDK ===
TBD: Add SDK extension details
In order to make it easier to use the alternative toolchain within the SDK.  An additional environment-* file should be created.  The purpose of this file is to simply override the settings in the main environment file.
See the example section for an implementation that will create this file automatically.
* need to add a custom toolchain_create_sdk_env_script for the secondary toolchain(s) (supporting override).
* need to support more then one secondary toolchain
* populate_sdk_image_append -- define a python class to dump the secondary toolchain bits...
== Implementation Example ==
== Implementation Example ==

Revision as of 22:19, 14 November 2012


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.


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.)


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.


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.


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:

  * CC
  * CXX
  * F77
  * CPP
  * LD
  * CCLD
  * AR
  * AS
  * NM

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:


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.

It is suggested that the secondary toolchain values be defined in a single configuration file. Within the example this is "conf/tc-example.conf". The standard name for the file should be 'conf/tc-<toolchain>.conf'.


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.


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.

The blacklist items should be defined within conf/tc-<toolchain>-blacklist.conf. The validation of the blacklist should use the standard tc-blacklist.bbclass implementation available within the example.


In order to make it easier to use the alternative toolchain within the SDK. An additional environment-* file should be created. The purpose of this file is to simply override the settings in the main environment file.

See the example section for an implementation that will create this file automatically.

Implementation Example

An example implementation has been created in the layer "meta-tc-example". The file format follows:

meta-tc-example/ meta-tc-example/bin meta-tc-example/bin/example-toolchain meta-tc-example/conf meta-tc-example/conf/layer.conf meta-tc-example/conf/tc-example.conf meta-tc-example/conf/tc-example-blacklist.conf meta-tc-example/classes meta-tc-example/classes/tc-secondary.bbclass meta-tc-example/classes/tc-blacklist.bbclass


  # We have a conf and classes directory, append to BBPATH
  BBFILE_COLLECTIONS += "tc-example"
  # If we have a recipes directory, add to BBFILES
  #BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/*/recipes-*/*/*.bbappend"
  #BBFILE_COLLECTIONS += "tc-example"
  #BBFILE_PATTERN_tc-example := "^${LAYERDIR}/"
  #BBFILE_PRIORITY_tc-example = "5"

Above is standard layer configuration. Note, the commented out sections should be re-enabled if the secondary toolchain includes recipes and/or bbappend files.

  PATH := "${PATH}:${LAYERDIR}/bin"

Add to the path a standard system path, a layer specific path. This is the way you can add a secondary toolchain to the path.

  # Define the alternative toolchain
  SECONDARYTC = 'example'
  # Enable the secondary toolchain
  INHERIT += 'tc-secondary tc-blacklist'

Define the alternative toolchain name in SECONDARYTC. The inherit causes the tc-secondary.bbclass and tc-blacklist.bbclass to be loaded later. Eventually this class used SECONDARYTC to load in the secondary toolchain configuration files.


  # Define default system toolchain (default to built-in)
  TOOLCHAIN = 'gnu'

Define a reasonable default such as gnu. The purpose of this default is to allow someone to specify the default or provide default override items for the built-in toolchain.

  # Define a secondary toolchain called 'example'
  # the 'example' toolchain can be activated using:
  # Per package (preferred):
  #   TOOLCHAIN_pn-bash = 'example'
  # Globally:
  #   TOOLCHAIN = 'example'
  #   TOOLCHAIN_pn-eglibc = 'gnu'

The above is an example of how to use the alternative toolchain.

  # When the secondary toolchain is used, we add an automatic depend...
  DEPENDS_append_toolchain-example = " virtual/TOOLCHAIN-EXAMPLE"
  # ...the depend can be provided by a recipe or as an ASSUME_PROVIDED

Use the above as an example on how to add additional dependencies to specific packages. This can be used to trigger a recipe to build.

  # Default values from bitbake.conf...
  # Variables with a '*' are things likely to need to be overridden:
  #   DEBUG_OPTIMIZATION = "-O -fno-omit-frame-pointer ${DEBUG_FLAGS} -pipe"
  # * TARGET CXXFLAGS = "${TARGET_CFLAGS} -fpermissive"
  # * CCLD = "${CC}"
  #   AR = "${HOST_PREFIX}ar"
  #   AS = "${HOST_PREFIX}as ${HOST_AS_ARCH}"
  #   RANLIB = "${HOST_PREFIX}ranlib"
  #   STRIP = "${HOST_PREFIX}strip"
  #   OBJCOPY = "${HOST_PREFIX}objcopy"
  #   OBJDUMP = "${HOST_PREFIX}objdump"
  #   NM = "${HOST_PREFIX}nm"
  # Override values:
  CC_toolchain-example  = "example-toolchain ${HOST_PREFIX}gcc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
  CXX_toolchain-example = "example-toolchain ${HOST_PREFIX}g++ ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
  CPP_toolchain-example = "example-toolchain ${HOST_PREFIX}gcc -E${TOOLCHAIN_OPTIONS} ${HOST_CC_ARCH}"
  LD_toolchain-example  = "example-toolchain ${HOST_PREFIX}ld${TOOLCHAIN_OPTIONS} ${HOST_LD_ARCH}"

The above implements the necessary overrides for the example toolchain.


Example configuration file that enables the blacklist and defines the defaults.

  # Blacklist certain items...
  TCBLACKLIST[eglibc] = 'example'
  TCBLACKLIST[bash] = 'example'
  # or
  # Switch to a global blacklist and whitelist situation...
  # TCBLACKLIST = 'example'
  # TCWHITELIST[bash] = 'example'


This is the standard secondary toolchain class. It should be the same in all secondary toolchain layers.

  # In order to add overrides, we need to do it later then in the layers.conf
  # the only standard way is using an inherit, which requires a bbclass
  # Add the necessary override
  require conf/tc-${SECONDARYTC}.conf


This is the standard secondary toolchain blacklist class. It should be the same in all secondary toolchain layers.

  # Implement blacklist/whitelist functionality for alternative toolchains
  # Based on the oe-core blacklist bclass
  # To add a blacklisted package:
  #   TCBLACKLIST[pn] = 'toolchain'
  # To blacklist everything, and whitelist a package:
  #   TCBLACKLIST = 'toolchain'
  #   TCWHITELIST[pn] = 'toolchain'
  include conf/tc-${SECONDARYTC}-blacklist.conf
  python () {
      tc = d.getVar('TOOLCHAIN', True)
      pn = d.getVar('PN', True)
      blacklist = d.getVarFlag('TCBLACKLIST', pn, True)
      if blacklist and blacklist == tc:
          raise bb.parse.SkipPackage("Recipe '%s' is blacklisted for the '%s' toolchain" % (pn, tc))
      blacklist = d.getVar('TCBLACKLIST', True)
      whitelist = d.getVarFlag('TCWHITELIST', pn, True)
      if blacklist and (not whitelist or whitelist != tc):
          raise bb.parse.SkipPackage("Recipe '%s' is blacklisted for the '%s' toolchain" % (pn, tc))

Further comments and information