Arch linux arm cross compiling

distcc

distcc is a program to distribute builds of C, C++, Objective C or Objective C++ code across several machines on a network to speed up building. It should always generate the same results as a local build, is simple to install and use, and is usually much faster than a local compile. Further, one can use it together with native Arch build tools such as makepkg.

Contents

Terms

Getting started

Install the distcc package on all participating PCs in the distcc cluster. For other distros, or even operating systems including Windows through using Cygwin, refer to the distcc docs or the included man pages distcc(1) and distccd(1) . Be sure to allow traffic through the port on which distcc runs (the default is 3632/tcp), see Category:Firewalls.

Configuration

Modes of operation

Distcc can be run in plain mode (default) or in pump mode. At a high level, the key difference is in how distcc deals with preprocessed source. Plain mode transfers the complete source and compiler args. Preprocessing is kept on the client. Pump mode distributes both preprocessing and compilation to the distcc cluser which, in many cases, is more efficient and faster. See man distcc for more details.

Volunteers

The configuration for the volunteer is stored in /etc/conf.d/distccd . At a minimum, add the —allow-private switch which covers a number of ipv4 private network ranges. Logging to a file is also nice for troubleshooting if needed.

If multiple interfaces are present on the machine, consider passing the —listen ADDRESS option as well. Other options can be defined. Refer to distccd(1) .

Start distccd.service on every participating volunteer. To have distccd.service start at boot-up, enable it.

Client

For use with makepkg

Edit /etc/makepkg.conf in the following sections:

  1. The BUILDENV array will need to have distcc unbanged i.e. list it without exclamation point.
  2. Uncomment the DISTCC_HOSTS line and add the host name or IP addresses of the volunteers. Optionally, follow this with a forward slash and the max number of threads they are to use. The subsequent nodes should be separated by a white space. This list should be ordered from most powerful to least powerful (processing power).
  3. Adjust the MAKEFLAGS variable to correspond roughly twice the number max threads per server. In the example below, this is 2x(9+5+5+3)=44.

It should be noted that there are no true universal configurations. Try one, test it, compare the results to other setups. The following are a few common setups:

Plain mode example
Pump mode example

Several things to call out here:

  • Pump mode generally performs better with a high value for MAKEFLAGS than plain mode.
  • In pump mode, the IP or hostname is suffixed with a literal ‘,cpp,lzo’ as required by pump mode. Further, the localhost in this example was not. This means that distcc will load localhost with the 9 jobs defined and more aggressively distribute the code generation to the volunteers. It could be that in larger clusters, one might want to restrict the number of local jobs on the localhost to fewer to allow processing of distribution out to the cluster. One could also use the ,cpp,lzo suffix to the localhost as well.
  • As mentioned above, there is not a single configuration that will work efficiently with all distcc clusters/determining the optimal settings are derived empirically through testing and benchmarking.
Читайте также:  Как удалить песочницу windows

For use without makepkg

Plain mode example

The minimal configuration for distcc on the client includes the setting of the available volunteers and re-defining the PATH .

Pump mode example

Compile

With makepkg

Plain mode example

No special steps are needed once /etc/makepkg.conf has been configured. Simply call makepkg as normal.

Pump mode example

The user must start pump prior to compiling whether with makepkg or on the shell. Since pump includes a check to make sure there is a set of DISTCC_HOSTS correctly configured, we need to first define a bogus DISTCC_HOSTS line. Remember that makepkg will use the values specified in /etc/makepkg.conf .

Now call makepkg as normal.

When finished, optionally stop pump:

Without makepkg

Plain mode example

After exporting the two variables describe in #For use without makepkg, simply call the compiler:

Some programs may require one to define the CC and/or CXX variable to work properly:

Pump mode example

Start pump as illustrated above. Compilation is no different than plain mode.

With CMake

Use the following CMake options to build a CMake-based project with distcc:

Monitoring progress

distcc ships with a cli monitor distccmon-text one can use to check on compilation status.

The cli monitor can run continuously by appending a space followed by integer to the command which corresponds to the number of sec to wait for a repeat query:

Cross compiling with distcc

One can use distcc to help cross compile.

  • A machine running the target architecture must be used as the client.
  • Non-native architecture volunteers will help compile but they require the corresponding toolchain to be installed and their distccd pointing to it.

Arch Linux ARM as clients (x86_64 as volunteers)

This section details how to use Arch Linux (x86_64) volunteers to help an Arch ARM device cross-compile. See these tests for evidence that speed gains on the order of 2-4x can be realized with just a single x86_64 machine helping an ARM device compile.

Volunteers

The Arch ARM developers highly recommend using the official project toolchains which should be installed on the x86_64 volunteer(s). Rather than manually managing these, the AUR provides all four toolchains as well as configuration and systemd service units:

Setup on the volunteer containing the arm/arm64 toolchains is identical to #Volunteers except that the name of the configuration and systemd service file matches that of the respective package. For example, for armv7h the config file is /etc/conf.d/distccd-armv7h and the systemd service unit is distccd-armv7h.service .

Note that each of the toolchains runs on a unique port thus allowing all four of them to co-exist on the volunteer if needed. Be sure to allow traffic to the port on which distcc runs see Category:Firewalls and distcc(1) .

Target architecture Distcc Port
armv5 3633
armv6h 3634
armv7h 3635
armv8h/aarch64 3636

Client

The easiest method to setup the Arch ARM client is to use distccd-arch-arm AUR . It provides all four configurations and systemd service units covering all four flavors of Arch ARM. For example, if the Arch ARM client is running an armv7h image, optionally edit /etc/conf.d/distccd-armv7h and change the defaults therein. When ready to build, enable distccd-armv7h.service and compile.

For a more detailed tutorial, see usage-examples.

If one would rather setup the client without using the AUR package mentioned above, manual setup of the client is identical to #Client except, one needs to modify the following two files to define the now non-standard port the volunteers are expected to use. Refer to the table above if using the AUR package.

  1. /etc/conf.d/distcc : example on an armv7h machine: DISTCC_ARGS=»—allow-private —log-level info —log-file /tmp/distccd-armv7h.log —port 3635″
  2. /etc/makepkg.conf : example on an armv7h machine: DISTCC_HOSTS=»192.168.10.2/5:3635 192.168.10.3/5:3635″
Note about localhost on ARM clients

When building on Arch ARM devices using x86_64 volunteers, it is highly recommended to exclude the localhost directive from DISTCC_HOSTS since many ARM devices do not have the needed processing power.

To illustrate this effect, consider the following example compiling the linux kernel version 5.10.44’s Image target. The client is a RPi4B (aarch64) and the volunteer (192.168.1.288) is a quad core/hyper threaded Intel machine. Each compile job was run only once and make clean was run in between them.

Читайте также:  Красивый терминал для windows

Running make -j15 Image CC=distcc CXX=distcc

DISTCC_HOSTS= Time (mm:ss) Fold slower
«192.168.1.288:3636/9» 6:50
«localhost/5 192.168.1.288:3636/9» 10:34 2.8x
«192.168.1.288:3636/9 localhost/5» 10:13 2.7x

Arch Linux (x86_64) as clients (Arch ARM as volunteers)

This section details how to use Arch ARM volunteers to help an x86_64 client cross-compile. See these tests for evidence that compilation times can be significantly sped up using even 1 Arch ARM volunteer and that up to 2 can double that gain.

Client

Setup of the client is identical to #Client with distcc running on the standard port 3632.

Volunteers

distccd-x86_64 AUR will provide a toolchain to install on the Arch ARM devices to enable cross compilation.

Additional toolchains

  • EmbToolkit: Tool for creating cross compilation tool chain; supports ARM and MIPS architectures; supports building of an LLVM based tool chain
  • crosstool-ng: Similar to EmbToolkit; supports more architectures (see website for more information)
  • Linaro: Provides tool chains for ARM development

The EmbToolkit provides a nice graphical configuration menu ( make xconfig ) for configuring the tool chain.

Troubleshooting

Quirks compiling the Arch Linux kernel package

If building the kernel from the official PKGBUILD (or many from the AUR), distcc will not work due to the fact that the kernel is hard-coded to use GCC plugins which cannot be supported by distccd due to technical reasons.

A workaround is to edit the kernel source removing the hard-coded requirement of GCC plugins. This can be accomplished with a sed one liner in the PKGBUILD itself inserted before the make step:

Failure to do this will result in distcc not working during the build. See FS#64275.

Another option is to pass the CC=distcc and CXX=distcc variables as part of the build command:

Quirks compiling chromium

Compiling chromium which uses clang is currently affected by issue#386. In order to circumvent the bug, add the following to the _flags array in the PKGBUILD:

Journalctl

Use journalctl to find out what was going wrong:

Adjust log level

By default, distcc will log to /var/log/messages.log as it goes along. One trick (actually recommended in the distccd manpage) is to log to an alternative file directly. Again, one can locate this in RAM via /tmp. Another trick is to lower to log level of minimum severity of error that will be included in the log file. Useful if only wanting to see error messages rather than an entry for each connection. LEVEL can be any of the standard syslog levels, and in particular critical, error, warning, notice, info, or debug.

Either call distcc with the arguments mentioned here on the client or appended it to DISTCC_ARGS in /etc/conf.d/distccd on the volunteers:

Limit HDD/SSD usage by relocating $HOME/.distcc

By default, distcc creates $HOME/.distcc which stores transient relevant info as it serves up work for nodes to compile. This will avoid needless HDD read/writes and is particularly important for SSDs.

For distccd-alarm

No such file or directory

Errors similar to the following indicate that the user is mistakenly running the distccd service provided by distcc and NOT provided by the distccd-alarm packages (ie distccd-alarm-armv5 AUR , distccd-alarm-armv6h AUR , distccd-alarm-armv7h AUR , or distccd-alarm-armv8 AUR .)

Be sure to start the correct service for the target architecture.

Avahi-daemon stops publishing when distccd.service starts

The factual accuracy of this article or section is disputed.

Источник

Cross-compiling tools package guidelines

This page describes how to create packages for cross-compiler toolchains. Another method to cross-compile makes use of distcc on mixed architectures. See Distcc#Cross compiling with distcc.

Contents

Important note

This page describes the new way of doing things, inspired by the following packages:

  • mingw-w64-gcc and other packages from mingw-w64-* series
  • arm-none-eabi-gcc and other packages from arm-none-eabi-* series
  • Other packages from arm-wince-cegcc-* series

Version compatibility

The following strategies allows you to select compatible versions of gcc, binutils, kernel and C library:

  • General rules:
    • there is a correlation between gcc and binutils releases, use simultaneously released versions;
    • it is better to use latest kernel headers to compile libc but use —enable-kernel switch (specific to glibc, other C libraries may use different conventions) to enforce work on older kernels;
  • Official repositories: you may have to apply additional fixes and hacks, but versions used by Arch Linux (or it’s architecture-specific forks) most probably can be made to work together;
  • Software documentation: all GNU software have README and NEWS files, documenting things like minimal required versions of dependencies;
  • Other distributions: they too do cross-compilation
  • https://trac.clfs.org covers steps, necessary for building cross-compiler and mentions somewhat up-to-date versions of dependencies.
Читайте также:  Windows шлюз по умолчанию dhcp

Building a cross compiler

The general approach to building a cross compiler is:

  1. binutils: Build a cross-binutils, which links and processes for the target architecture
  2. headers: Install a set of C library and kernel headers for the target architecture
    1. use linux-api-headers as reference and pass ARCH=target-architecture to make
    2. create libc headers package (process for Glibc is described here)
  3. gcc-stage-1: Build a basic (stage 1) gcc cross-compiler. This will be used to compile the C library. It will be unable to build almost anything else (because it cannot link against the C library it does not have).
  4. libc: Build the cross-compiled C library (using the stage 1 cross compiler).
  5. gcc-stage-2: Build a full (stage 2) C cross-compiler

The source of the headers and libc will vary across platforms.

Package naming

The package name shall not be prefixed with the word cross- (it was previously proposed, but was not adopted in official packages, probably due to additional length of names), and shall consist of the package name, prefixed by GNU triplet without vendor field or with «unknown» in vendor field; example: arm-linux-gnueabihf-gcc . If shorter naming convention exists (e.g. mips-gcc ), it may be used, but this is not recommended.

File placement

Latest versions of gcc and binutils use non-conflicting paths for sysroot and libraries. Executables shall be placed into /usr/bin/ , to prevent conflicts here, prefix all of them with architecture name.

Typically, ./configure would have at least following parameters:

where your_target can be, e.g., «i686-pc-mingw32».

Example

This is PKGBUILD for binutils for MinGW. Things worth noticing are:

  • specifying root directory of the cross-environment
  • usage of $ <_pkgname>, $ <_target>and $ <_sysroot>variables to make the code more readable
  • removal of the duplicated/conflicting files

Hows and whys

Why not installing into /opt ?

  1. First, according to File Hierarchy Standard, these files just belong somewhere to /usr . Period.
  2. Second, installing into /opt is a last measure when there is no other option.

What is that out-of-path executables thing?

This weird thing allows easier cross-compiling. Sometimes, project Makefiles do not use CC & co. variables and instead use gcc directly. If you just want to try to cross-compile such project, editing the Makefile could be a very lengthy operation. However, changing the $PATH to use «our» executables first is a very quick solution. You would then run PATH=/usr/arch/bin/:$PATH make instead of make .

Troubleshooting

What to do if compilation fails without clear message?

For error, occurred during running configure , read $srcdir/pkgname-build/config.log . For error, occurred during compilation, scroll console log up or search for word «error».

What does this error [error message] means?

Most probably you made some of non-obvious errors:

  • Too many or too few configuration flags. Try to use already proven set of flags.
  • Dependencies are corrupted. For example misplaced or missing binutils files may result in cryptic error during gcc configuration.
  • You did not add export CFLAGS=»» to your build() function (see bug 25672 in GCC Bugzilla).
  • Some —prefix / —with-sysroot combination may require directories to be writable (non-obvious from clfs guides).
  • sysroot does nor yet has kernel/libc headers.
  • If google-fu does not help, immediately abandon current configuration and try more stable/proven one.

Why do files get installed in wrong places?

Various methods of running generic make install line results in different results. For example, some make targets may not provide DESTDIR support and instead require install_root usage. The same for tooldir , prefix and other similar arguments. Sometimes providing parameters as arguments instead of environment variables, e.g

and vice versa may result in different outcomes (often caused by recursive self-invocation of configure/make).

Источник

Оцените статью