Using LLVM 21.1.8 Toolset

Red Hat Developer Tools 1

Installing and using LLVM 21.1.8 Toolset

Red Hat Customer Content Services

Abstract

LLVM Toolset is a Red Hat offering for developers on the Red Hat Enterprise Linux (RHEL) operating system. Use this guide for an overview of LLVM Toolset, to learn how to invoke and use different versions of LLVM tools, and to find resources with more in-depth information.

Providing feedback on Red Hat documentation

We are committed to providing high-quality documentation and value your feedback. To help us improve, you can submit suggestions or report errors through the Red Hat Jira tracking system.

Procedure

  1. Log in to the Content from redhat.atlassian.net is not included.Jira website.

    If you do not have an account, select the option to create one.

  2. Click Create in the top navigation bar.
  3. Enter a descriptive title in the Summary field.
  4. Enter your suggestion for improvement in the Description field. Include links to the relevant parts of the documentation.
  5. Click Create at the bottom of the window.

Chapter 1. LLVM Toolset

LLVM Toolset is a Red Hat offering for developers on Red Hat Enterprise Linux. It includes the LLVM compiler infrastructure, Clang for C and C++, LLDB, and related code analysis tools.

LLVM Toolset is available as a module for RHEL 8 and as packages for RHEL 9 and 10.

1.1. LLVM Toolset components

LLVM Toolset provides Clang, LLDB, LLVM, compiler-rt, libomp, LLD, and python-lit for compiling, linking, and debugging C and C++ code. Each package in this release is version 21.1.8.

Table 1.1. Packages included in LLVM Toolset

NameVersionDescription

clang

21.1.8

An LLVM compiler front end for C and C++.

lldb

21.1.8

A C and C++ debugger using portions of LLVM.

compiler-rt

21.1.8

Runtime libraries for LLVM and Clang.

llvm

21.1.8

A collection of modular and reusable compiler and toolchain technologies.

libomp

21.1.8

A library for using the OpenMP API for parallel programming.

lld

21.1.8

An LLVM linker.

python-lit

21.1.8

A software testing tool for LLVM- and Clang-based test suites.

Note

The CMake build manager is not part of LLVM Toolset. CMake is available in the system repository. For more information on how to install CMake, see Installing the CMake build manager.

1.2. LLVM Toolset compatibility

You can use LLVM Toolset on Red Hat Enterprise Linux on AMD and Intel 64-bit (x86_64) and 64-bit ARM (aarch64) systems. You can also use it on IBM Power Systems, Little Endian (ppc64le), and 64-bit IBM Z (s390x) systems.

1.3. Installing LLVM Toolset

On Red Hat Enterprise Linux 8, enable the llvm-toolset module to install LLVM Toolset and dependent packages. On Red Hat Enterprise Linux 9 and 10, install the llvm-toolset package instead.

Prerequisites

  • All available Red Hat Enterprise Linux updates are installed.

Procedure

  1. Install LLVM Toolset:

    • On RHEL 8, enter:

      # yum module install llvm-toolset
    • On RHEL 9 and 10, enter:

      # dnf install llvm-toolset
  2. To also install the LLDB debugger and the python3-lit package, enter:

    # dnf install lldb python3-lit

1.4. LLVM Toolset documentation

For the official LLVM Toolset documentation, see the Content from releases.llvm.org is not included.upstream documentation.

Note

The llvm-doc package provides only a reference to the upstream documentation.

1.5. Installing the CMake build manager

The CMake build manager is a tool that manages the build process of your source code independently from your compiler. CMake generates a native build environment to compile source code, create libraries, generate wrappers, and build executable files. Install it by installing the cmake package on your system.

Procedure

  • Install CMake:

    # yum install cmake

1.6. Installing the CMake documentation

You can install documentation for the CMake build manager on your local system.

Procedure

  • Install the cmake-doc package:

    # dnf install cmake-doc

Verification

  • Open /usr/share/doc/cmake/html/index.html in a browser that is installed on the same host.

1.7. Additional resources

Chapter 2. The Clang compiler

Clang is an LLVM compiler front end for the C-based languages C, C++, Objective C/C++, OpenCL, and Cuda.

LLVM Toolset is distributed with Clang 21.1.8.

Note

To compile a C++ program, use clang++ instead of clang.

2.1. Prerequisites

  • LLVM Toolset is installed.

2.2. Compiling a source file

You can compile source files and assembly language files with clang command to produce an executable binary. Add the -g flag to your clang command to include debug information.

Note

To compile a C++ program, use clang++ instead of clang.

Procedure

  • Compile your program:

    $ clang -g -o <binary_file> <source_file>

    Replace <binary_file> with the name of your output file and <source_file> with the name of your source file.

2.3. Running a program

You produce an executable when you compile your program with clang command. Run the program from the directory that contains the executable file.

Prerequisites

  • Your program is compiled.

Procedure

  • To run your program, enter in the directory containing the executable file:

    $ ./<binary_file>

    Replace <binary_file> with the name of your executable file.

Additional resources

2.4. Linking object files together

By linking object files together, you can compile only source files that contain changes instead of your entire project.

When a project contains several source files, compile each one to an object file with clang command. Link the resulting object files with clang to produce an executable.

Note

To compile a C++ program, use clang++ instead of clang.

Procedure

  1. Compile a source file to an object file:

    $ clang -o <object_file> -c <source_file>

    Replace <object_file> with the name of your object file and <source_file> with the name of your source file.

  2. Link object files together:

    $ clang -o <output_file> <object_file_0> <object_file_n>

    Replace <output_file> with the name of your output file and <object_file> with the names of the object files you want to link.

    Important

    At the moment, certain library features are statically linked into applications built with LLVM Toolset to support their execution on multiple versions of Red Hat Enterprise Linux. This creates a small security risk. Red Hat will issue a security erratum in case you need to rebuild your applications due to this risk.

    Do not statically link your entire application.

2.5. Additional resources

Chapter 3. The LLDB debugger

You can debug C and C++ programs from the command line with LLDB, the LLVM project debugger. With LLDB, you can inspect memory, control how your program runs, and pause when selected code runs.

LLVM Toolset is distributed with LLDB 21.1.8.

3.1. Prerequisites

  • LLVM Toolset is installed.
  • Your compiler is configured to create debug information.

3.2. Starting a debugging session

Use LLDB to start an interactive debugging session.

Procedure

  1. Run LLDB on a program you want to debug:

    $ lldb <binary_file>

    Replace <binary_file> with the name of your compiled program.

    You have started your LLDB debugging session in interactive mode. Your command-line terminal now displays the default prompt (lldb).

  2. To quit the debugging session and return to the shell prompt:

    (lldb) quit

3.3. Executing your program during a debugging session

Use LLDB to run your program during your debugging session. The execution of your program stops when the first breakpoint is reached, when an error occurs, or when the program terminates.

Prerequisites

  • You started an interactive debugging session with LLDB.

Procedure

  • Run the program you are debugging:

    (lldb) run

    Alternatively, run the program you are debugging by using a specific argument:

    (lldb) run <argument>

    Replace <argument> with the command-line argument you want to use.

Additional resources

3.4. Using breakpoints

Use breakpoints to pause the execution of your program at a set point in your source code.

Prerequisites

  • You started an interactive debugging session with LLDB.

Procedure

  • To set a new breakpoint on a specific line, enter:

    (lldb) breakpoint set --file <source_file_name> --line <line_number>

    Replace <source_file_name> with the name of your source file and <line_number> with the line number you want to set your breakpoint at.

  • To set a breakpoint on a specific function, enter:

    (lldb) breakpoint set --name <function_name>
    • Replace <function_name> with the name of the function you want to set your breakpoint at.
  • To display a list of currently set breakpoints, enter:

    (lldb) breakpoint list
  • To delete a breakpoint, run:

    (lldb) breakpoint clear -f <source_file_name> -l <line_number>
    • Replace <source_file_name> with the name of your source file and <line_number> with line number of the breakpoint you want to delete.
  • To resume the execution of your program after it reached a breakpoint, enter:

    (lldb) continue
  • To skip a specific number of breakpoints, enter:

    (lldb) continue -i <breakpoints_to_skip>
    • Replace <breakpoints_to_skip> with the number of breakpoints you want to skip. To skip a loop, set the <breakpoints_to_skip> to match the loop iteration count.

Additional resources

3.5. Stepping through code

You can use LLDB to step through the code of your program to run only one line of code after the line pointer.

Prerequisites

  • You started an interactive debugging session with LLDB.

Procedure

  1. Set your line pointer to the line you want to run.
  2. Enter:

    (lldb) step

Additional resources

3.6. Listing source code

Before you run the program you are debugging, the LLDB debugger automatically displays the first 10 lines of source code. Each time the execution of the program is stopped, LLDB displays the line of source code on which it stopped and its surrounding lines. You can use LLDB to manually trigger the display of source code during your debugging session.

Prerequisites

  • You started an interactive debugging session with LLDB.

Procedure

  • To list the first 10 lines of the source code of the program you are debugging, enter:

    (lldb) list
    (lldb) list <source_file_name>:<line_number>

    Replace <source_file_name> with the name of your source file and <line_number> with the number of the line you want to display.

Additional resources

3.7. Displaying current program data

The LLDB debugger provides data on variables of any complexity, any valid expressions, and function call return values. You can use LLDB to display data relevant to the program state.

Prerequisites

  • You started an interactive debugging session with LLDB.

Procedure

  • Display the current value of a certain variable, expression, or return value:

    (lldb) print <data_name>

    Replace <data_name> with data you want to display.

Additional resources

3.8. Additional resources

Chapter 4. Container images with LLVM Toolset

You can build your own LLVM Toolset container images on top of Red Hat Universal Base Images (UBI) containers by using container files.

4.1. Creating a custom UBI-based container with LLVM Toolset

LLVM Toolset packages are part of the Red Hat Universal Base Images (UBIs) repositories. To keep the container image size small, install only individual packages instead of the entire LLVM Toolset.

Prerequisites

Procedure

  • To create a container image containing LLVM Toolset, add the following to your container file:

    • For an image based on RHEL 8, enter:

      FROM registry.access.redhat.com/ubi8/ubi:latest
      
      RUN yum module install -y llvm-toolset
    • For an image based on RHEL 9, enter:

      FROM registry.access.redhat.com/ubi9/ubi:latest
      
      RUN yum install -y llvm-toolset
    • For an image based on RHEL 10, enter:

      FROM registry.access.redhat.com/ubi10/ubi:latest
      
      RUN yum install -y llvm-toolset

4.2. Additional resources

Chapter 5. Changes in LLVM Toolset 21.1.8

Red Hat Enterprise Linux is distributed with LLVM Toolset version 21.1.8.

  • LLVM Toolset 21.1.8:

    • Upstream LLVM 21.1.8 is the last planned release in the LLVM 21.1.x line.
    • Maintenance fixes include corrections in ExtractAPI typedef formatting, the SelectOptimize pass for large integer immediates, and the WebAssembly back end (handling of locals).
    • ClangFormat includes regression and crash fixes for star annotation before lambdas, AlignArrayOfStructures, and qualifier placement with override.
    • The Realtime Sanitizer (RTSan) handles attributed IR function declarations more reliably.
    • Compiler-rt includes a sanitizer build fix for 32-bit x86 on Haiku. This change does not affect typical Red Hat Enterprise Linux builds but reflects upstream stabilization.
  • LLVM 21 (when you migrate from LLVM Toolset 20):

    • LLVM 21 introduces IR and attribute updates, including replacing nocapture with captures(none) in LLVM IR. Bitcode is upgraded automatically; tools that parse LLVM IR as text might need updates.
    • Clang and the LLVM back ends include further C and C++ conformance work, target-specific improvements, and debugger updates. Review the upstream notes if you rely on specific language options, warning behavior, or CPU tuning models.

For LLVM 21.1.8 source and the list of cherry-picked changes, see the Content from discourse.llvm.org is not included.LLVM 21.1.8 release announcement and the Content from github.com is not included.llvmorg-21.1.8 tag on GitHub. For the LLVM 21.1 feature set, see the Content from releases.llvm.org is not included.LLVM release notes and Content from releases.llvm.org is not included.Clang release notes.

LLVM Toolset is a rolling Application Stream, and only the latest version is supported. For more information, see the Red Hat Enterprise Linux Application Streams Life Cycle document.

Legal Notice

Copyright © Red Hat.
Except as otherwise noted below, the text of and illustrations in this documentation are licensed by Red Hat under the Creative Commons Attribution–Share Alike 3.0 Unported license . If you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, the Red Hat logo, JBoss, Hibernate, and RHCE are trademarks or registered trademarks of Red Hat, LLC. or its subsidiaries in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS is a trademark or registered trademark of Hewlett Packard Enterprise Development LP or its subsidiaries in the United States and other countries.
The OpenStack® Word Mark and OpenStack logo are trademarks or registered trademarks of the Linux Foundation, used under license.
All other trademarks are the property of their respective owners.