Skip to content
Lu Weining edited this page Jun 19, 2024 · 2 revisions

GNU Toolchain Combination Status of the LoongArch

Preamble

This is a document used to test whether different versions of Binutils, GCC, and Glibc in LoongArch can be built and used normally.

We selected the latest release of each major version for testing. These sources are obtained from https://ftp.gnu.org/gnu.

  • Binutils tested 5 release versions: 2.38, 2.39, 2.40, 2.41, 2.42, and 1 development version 2.43.
  • GCC tested 3 release versions: 12.3.0, 13.2.0, 14.1.0, and 1 development version 15.
  • Glibc tested 4 release versions: 2.36, 2.37, 2.38, 2.39, and 1 development version 2.40.

Table of Contents

Upstream Toolchain Combination Testing

The test of build process is based on cross-compilation: first, build the toolchain by cross-compiling; second, use this toolchain to compile and run the spec 2006 and 2017.

1. Test Process

  • Compile and install a versions of Binutils.
  • Use the new Binutils to build a degraded GCC that does not depend on the host Glibc. If this version of Binutils cannot build GCC, it is considered that the two cannot be combination.
  • Install the linux-6.8.4 kernel.
  • Compile a version of Glibc using the new GCC and Binutils.
  • Compile a complete GCC with new Binutils and Glibc.
  • Compile and run the spec 2006 and 2017 test using the toolchain above. The test uses -march=loongarch64 -Ofast and does not use vector instructions.
  • If any of the above test steps fails, it is considered that the corresponding version of the toolchain cannot be combination.

Note:

  • GCC requires the GMP, MPFR and MPC packages. As these packages may not be included in host, run the contrib/download_prerequisites script in the GCC source directory to obtain these packages,they will be built with GCC. If the versions of config.guess and config.sub in the source of these packages are too low, copy them from the gcc source directory.

  • GCC configure uses the default march and abi.

2. Test Results

The combinations that can complete all test processes are shown in Table 1.

The columns in the table are Binutils versions, the rows are GCC versions, and the intersection between them is the Glibc version. The X of intersection between them means that a certain step in the test process cannot be completed, which we call uncombinable.

Table 1. result of toolchain combinations

binutils/glibc/gcc 12.3.0 13.2.0 14.1.0 15
2.38 X X X X
2.39 2.36/2.37/2.38 2.36/2.37/2.38 X X
2.40 2.36/2.37/2.38 2.36/2.37/2.38 X X
2.41 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40
2.42 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40
2.43 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40 2.36/2.37/2.38/2.39/2.40

Note:

  • Binutils 2.38 cannot build any version of degraded GCC. Binutils 2.38 uses two ABI names, lp64 and ilp32, and GCC uses 3 ABI names, lp64d, lp64f, and lp64s. The default lp64d option passed by GCC is not recognized by the 2.38 version of the assembler.

  • Binutils 2.39 and 2.40 cannot build degraded GCC 14 and 15. GCC 14 and 15 use la64v1.0 as the default march, which enables lsx to generate vector instructions and causes Binutils 2.39 and Binutils 2.40 to be unrecognized.

  • Glibc 2.39 requires Binutils vector instruction support, and Binutils 2.41 and above add vector instruction support.

Toolchain Support of ABI Instructions and new Features

LoongArch ABI Revision History

For more information about ABI, please see the following link. Only some of the changes between versions are listed here. https://github.com/loongson/la-abi-specs.

  • v1.00
    • Add register usage convention, data type conventions and the list of ELF relocation types.
  • v2.00
    • Add description of ILP32 data model.
    • Add description of return value register aliases.
    • Add relocation types with direct immediate-filling semantics.
  • v2.01
    • Adjust description of ABI type encoding scheme.
  • v2.10
    • Add the DWARF standard for the LoongArch architecture (ladwarf) document.
    • Differentiate machine data types with the C/C++ types.
  • v2.20
    • Revise the parameter passing rules of structures.
    • Add R_LARCH_CALL36 relocation type.
    • Remove R_LARCH_DELETE and mark its relocation number as reserved.
    • Remove R_LARCH_CFA and mark its relocation number as reserved.
  • v2.30
    • Add vector arguments passing rules to the base ABI.
    • Add relocation types for TLS Descriptors.

Binutils Related Support

Table 2. ABI, instruction set, and new feature support for Binutils

version/support ABI Instruction Set New Features
2.38 1.00 Loongson Base
2.39 1.00 Loongson Base
2.40 1.00/2.00/2.01 Loongson Base - New relocation
2.41 1.00/2.00/2.01/2.10 Loongson Base
LSX/LASX
LVZ/LBT
- Link relaxation
2.42 1.00/2.00/2.01/2.10/2.20/2.30 Loongson Base
LSX/LASX
LVZ/LBT
LoongArch V1.1
- TLS Descriptors
- TLS le relax
- Branch relax
2.43 1.00/2.00/2.01/2.10/2.20/2.30 Loongson Base
LSX/LASX
LVZ/LBT
LoongArch V1.1
- TLS type transition

Binutils New Features Description

Descriptions of new features are available along with the Binutils release at the following link. Only some of the changes are listed below.

binutils: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=binutils/NEWS;hb=refs/heads/binutils-2_42-branch. gas: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=gas/NEWS;hb=refs/heads/binutils-2_42-branch. ld: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=ld/NEWS;hb=refs/heads/binutils-2_42-branch.

  • Link relaxation: A link-time optimization that reduces the number of instructions required to access a symbol. Set gcc/as -mrelax/-mno-relax to enable/disable link relaxation. Set ld --relax/--no-relax to enable/disable link relaxation.

  • TLS Descriptors: It is a more efficient alternative to the traditional general dynamic and local dynamic TLS models. Configured GCC with --with-tls=desc to enable TLS Descriptors by default. Set GCC -mtls-dialect=desc to enable TLS Descriptors.

  • TLS type transition Transition to a more efficient TLS access model. There are currently 3 transitions implemented:

    • desc -> ie
    • desc -> le
    • ie -> le

GCC Related Support

Table 3. Instruction set, and new feature support for GCC

version/support Instruction Set New Features
12.3.0 Loongson Base
13.2.0 Loongson Base - Command-line option
- Code model of extreme/medium
- Built-in functions
- Subprojects Support
14.1.0 Loongson Base
LSX/LASX
LoongArch V1.1
- Add more -march parameters
- Add more -mtune parameters
- ISA Extension
- Intrinsics
- Compiler Option
- Support for Ada and D
- Support for libffi
- TLS Descriptors support
15 Loongson Base
LSX/LASX
LoongArch V1.1

GCC New Features Description

Descriptions of new features are available along with the GCC release at the following link. Only some of the changes are listed below. https://gcc.gnu.org.

  • Code model:

    • medium code model: The text segment and data segment must be within 2GB addressing space. Set gcc option -mcmodel=medium to use medium code model.

    • extrme code model: This mode does not limit the size of the code segment and data segment. The -mcmodel=extreme option is incompatible with -fplt and/or -mexplicit-relocs=none. Set gcc option -mcmodel=extreme to use extreme code model, incompatible with -mno-explicit-relocs.

  • Subprojects Support:

    • libvtv support.

    • libitm support.

    • Address sanitizers other than HWASan and TSan are now supported on LoongArch.

  • Add more -march parameters:

    • la64v1.0
    • la64v1.1
    • la664
  • Add more -mtune parameters:

    • generic
    • la664
  • TLS Descriptors: Compiler support for TLS Descriptors. The current default configuration is --with-tls=trad. Configured GCC with --with-tls=desc to enable TLS Descriptors. Set GCC -mtls-dialect=desc to enable TLS Descriptors. Set GCC -mtls-dialect=trad to enable Traditional TLS model.


Glibc Related Support

Table 4. New feature support for Glibc

version/support New Features
2.36 - Hard-float ABI
- System interface
- Support TLS
- Atomic operation
- setjmp/longjmp pointer encryption
2.37 - Floating point function builtin
- Soft-float ABI
- LoongArch static PIE
2.38 - _dl_runtime_resolve vector implementation
- _dl_runtime_profile function
- Improve ldconfig function
2.39 - str/mem function vector implementation and ifunc
2.40 - Tunables
- TLS Descriptors

Glibc New Features Description

Descriptions of new features are available along with the Glibc release at the following link. Only some of the changes are listed below. https://sourceware.org/glibc.

  • setjmp/longjmp pointer encryption During the setjmp/longjmp process, the ra/sp pointers are encrypted and protected by random numbers.

  • Atomic operation Supports atomic operation instructions.

  • Floating point function builtin Implemented builtin support for floating-point functions.

  • Soft-float ABI Supports soft floating point ABI.

  • LoongArch static PIE Supports static PIE executable programs.

  • _dl_runtime_resolve vector implementation Added lsx 128-bit implementation _dl_runtime_resolve_lsx and lasx 256-bit implementation _dl_runtime_resolve_lasx.

  • _dl_runtime_profile function Add dynamic linker _dl_runtime_profile function.

  • str/mem function vector implementation and ifunc Add multiple versions of str/mem functions and implement ifunc functionality.

  • Improve ldconfig function Add and improve the functions of ldconfig.

  • Tunables Add glibc.cpu.hwcap support for tuning HWCAP feature.

  • TLS Descriptors Glibc support for TLS Descriptors.

Problematic Situations

  • The default configure for GCC12 and 13 is --with-arch=loongarch64, and for GCC 14 and above is --with-arch=la64v1.0. If you want to use GCC 14 and above with Binutils2.39 and 2.40, you need to configure GCC as --with-arch=loongarch64.

  • To generate vector instructions using -mlsx/-mlasx, only GCC 14 can be used, and Binutils 2.41 and above can be used.

  • If -falign-labels is used but not falign-labels=0/1/2/3/4, GCC 12 13 cannot be used with Binutils 2.42. This is because of a change in the behavior of Binutils in handling .align. GCC 14 and later can use non-zero/one falign-labels with Binutils 2.42.