externaltoolchain

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
externaltoolchain [2015/04/12 20:56] – CraigRodriguesexternaltoolchain [2020/09/15 15:51] (current) – BrooksDavis
Line 1: Line 1:
-==== External Toolchain Support ====+====== External Toolchain Support ======
  
 %%FreeBSD%% needs support for external toolchains to ease testing of new compiler versions, support compilers that don't make sense to integrate into the base, and speed builds (by avoiding building of bootstrap compilers).  This page documents efforts towards this. %%FreeBSD%% needs support for external toolchains to ease testing of new compiler versions, support compilers that don't make sense to integrate into the base, and speed builds (by avoiding building of bootstrap compilers).  This page documents efforts towards this.
  
-===== XCC =====+===== Using pre-built toolchain packages ===== 
 + 
 +The simplest way to do this is with the pre-built toolchain packages.  Toolchains are available via the ''%%devel/llvm##%%'' (for LLVM 10.0.0 and later), ''%%devel/xtoolchain-llvm<version>%%'' (for LLVM 8 and 9), and ''%%devel/freebsd-gcc<version>%%'' ports.  For the GCC ports, architectures are provided as flavors and the resulting packages are named ''%%<arch>-gcc<version>%%''.  Once a toolchain is installed, it can be used with top-level system make targets such as buildworld and buildkernel via the CROSS_TOOLCHAIN variable to the name of the package (without the ''%%xtoolchain-%%'' prefix for LLVM toolchains).  It can also be used with buildenv to build individual programs in the base system. 
 + 
 +==== Cross-building with a pre-built toolchain package ==== 
 + 
 +For example, to build powerpc64 using GCC 6, you would do: 
 + 
 +<code> 
 +pkg install powerpc64-gcc6 
 +make CROSS_TOOLCHAIN=powerpc64-gcc6 TARGET=powerpc TARGET_ARCH=powerpc64 buildworld 
 +make CROSS_TOOLCHAIN=powerpc64-gcc6 TARGET=powerpc TARGET_ARCH=powerpc64 installworld DESTDIR=/sysroots/powerpc64 
 +make CROSS_TOOLCHAIN=powerpc64-gcc6 TARGET=powerpc TARGET_ARCH=powerpc64 distribution DESTDIR=/sysroots/powerpc64 
 +</code> 
 + 
 +To build arm64 with LLVM11, you would do: 
 + 
 +<code> 
 +pkg install llvm11 
 +make CROSS_TOOLCHAIN=llvm11 TARGET=arm64 buildworld 
 +make CROSS_TOOLCHAIN=llvm11 TARGET=arm64 installworld DESTDIR=/sysroots/arm64 
 +make CROSS_TOOLCHAIN=llvm11 TARGET=arm64 distribution DESTDIR=/sysroots/arm64 
 +</code> 
 + 
 +==== Use cross compiler to build native compiler ==== 
 + 
 +<code> 
 +cd /usr/ports/base/binutils 
 +make CROSS_TOOLCHAIN=powerpc64-gcc6 TARGET=powerpc TARGET_ARCH=powerpc64 CROSS_SYSROOT=/sysroots/powerpc64 package 
 +cd /usr/ports/base/gcc6 
 +make CROSS_TOOLCHAIN=powerpc64-gcc6 TARGET=powerpc TARGET_ARCH=powerpc64 CROSS_SYSROOT=/sysroots/powerpc64 package 
 +</code> 
 + 
 +===== Under the hood ===== 
 + 
 +The rest of this page provides details on how this works and how to override individual components if desired. 
 + 
 +==== XCC ====
  
 The XCC approach works with top level build targets (buildworld, buildkernel, etc) and overrides common make variables such as CC, CXX, and AS during the cross building portions of the build with values specified by the XCC, XCPP, XAS, etc variables.  This method touches few files and is relatively easy to understand, but has drawbacks including the inability to build individual programs easily. The XCC approach works with top level build targets (buildworld, buildkernel, etc) and overrides common make variables such as CC, CXX, and AS during the cross building portions of the build with values specified by the XCC, XCPP, XAS, etc variables.  This method touches few files and is relatively easy to understand, but has drawbacks including the inability to build individual programs easily.
  
-====== How to use ======+==== How to use ====
  
 If is possible to replace both the compiler and binutils.  It is possible to replace the compiler and use the built-in binutils.  To replace binutils, you must also replace the compiler. If is possible to replace both the compiler and binutils.  It is possible to replace the compiler and use the built-in binutils.  To replace binutils, you must also replace the compiler.
Line 13: Line 50:
 Both the compiler and binutils must be configured to support --sysroot to find headers and libraries. Both the compiler and binutils must be configured to support --sysroot to find headers and libraries.
  
-===== Using an external compiler =====+==== Using an external compiler ====
  
 To use an external compiler such as clang, set the variables XCC, XCXX, and XCPP when building and installing.  You must generally set all three.  For example: To use an external compiler such as clang, set the variables XCC, XCXX, and XCPP when building and installing.  You must generally set all three.  For example:
Line 33: Line 70:
 If the compiler is clang and the target architecture is not the same as the build host then an appropriate target triple will be created and passed to clang to support native cross compilation. If the compiler is clang and the target architecture is not the same as the build host then an appropriate target triple will be created and passed to clang to support native cross compilation.
  
-===== Using an external binutils =====+==== Using an external binutils ====
  
 To use an external binutils, set the XAS, XAR, XLD, XNM, XOBJDUMP, XRANLIB, and XSTRINGS.  As with the compiler, there is a CROSS_BINUTILS_PREFIX variable.  If the both the compiler and binutils have the same prefix a CROSS_TOOLCHAIN_PREFIX variable can be used to set both. To use an external binutils, set the XAS, XAR, XLD, XNM, XOBJDUMP, XRANLIB, and XSTRINGS.  As with the compiler, there is a CROSS_BINUTILS_PREFIX variable.  If the both the compiler and binutils have the same prefix a CROSS_TOOLCHAIN_PREFIX variable can be used to set both.
  
-====== Caveats ======+==== Caveats ====
  
 To use XCC, you must not set any of the variables that can be overridden by X* variables in /etc/make.conf or /etc/src.conf as Makefile.inc1 will be unable to change them. To use XCC, you must not set any of the variables that can be overridden by X* variables in /etc/make.conf or /etc/src.conf as Makefile.inc1 will be unable to change them.
  
-External, cross-building gcc toolchains support is still somewhat weak (which means doesn't work)+===== See Also =====
  
-Cross building generally works only with clang 3.4 or whatever the current in-tree compiler is (and often slightly newer tress).+[[ExternalGCC]]
  
-There are some bootstrapping issues still if you want to build the in-tree compiler as part of the build.+----
  
-====== Status ====== +{{tag>Project}}
-Patches have been committed to HEAD. +
-Works with: +
-  * [[https://www.freshports.org/lang/clang-devel/|lang/clang-devel]]  and [[https://www.freshports.org/devel/binutils|devel/binutils]] ports. +
-  * [[https://lists.freebsd.org/pipermail/freebsd-current/2014-November/053577.html|Preliminary support for gcc 4.9.1]] +
- +
-====== Use pre seeded configurations ====== +
- +
-The following xtoolchain ports are available: +
-  * devel/amd64-xtoolchain-gcc +
-  * devel/powerpc64-xtoolchain-gcc +
-  * devel/sparc64-xtoolchain-gcc +
- +
-For example, to build using powerpc64-xtoolchain-gcc, you would do: +
- +
-<code> +
-pkg install devel/powerpc64-xtoolchain-gcc +
-make CROSS_TOOLCHAIN=powerpc64-gcc TARGET=powerpc TARGET_ARCH=powerpc64 buildworld +
-</code>+
  
  • externaltoolchain.1428872188.txt.gz
  • Last modified: 2015/04/12 20:56
  • by CraigRodrigues