使用 LLVM 18.1.8 Toolset


Red Hat Developer Tools 1

安装和使用 LLVM 18.1.8 Toolset

摘要

LLVM Toolset 是 Red Hat Enterprise Linux (RHEL)操作系统开发人员的一个红帽产品。使用本指南了解 LLVM Toolset 的概述,了解如何调用和使用不同的 LLVM 工具版本,以及查找具有更深入的信息的资源。

使开源包含更多

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。我们从这四个术语开始:master、slave、黑名单和白名单。由于此项工作十分艰巨,这些更改将在即将推出的几个发行版本中逐步实施。详情请查看 CTO Chris Wright 的信息

对红帽文档提供反馈

我们感谢您对我们文档的反馈。让我们了解如何改进它。

通过 Jira 提交反馈(需要帐户)

  1. 登录到 Jira 网站。
  2. 在顶部导航栏中点 Create
  3. Summary 字段中输入描述性标题。
  4. Description 字段中输入您对改进的建议。包括文档相关部分的链接。
  5. 点对话框底部的 Create

第 1 章 LLVM Toolset

LLVM Toolset 是 Red Hat Enterprise Linux (RHEL)上的开发人员的一个红帽产品。它提供了 LLVM 编译器基础架构框架、Clang 编译器和 C++ 语言的 Clang 编译器、LLDB 调试器以及用于代码分析的相关工具。

对于 Red Hat Enterprise Linux 8,LLVM Toolset 作为一个模块提供。LLVM Toolset 作为 Red Hat Enterprise Linux 9 软件包提供。

1.1. LLVM Toolset 组件

以下组件作为 LLVM Toolset 的一部分提供:

Expand
Name版本描述

clang

18.1.8

C++ 和 C++ 的 LLVM 编译器前端。

lldb

18.1.8

使用 LLVM 的部分的 C 和 C++ 调试器。

compiler-rt

18.1.8

LLVM 和 Clang 的运行时库。

llvm

18.1.8

模块化和可重复使用的编译器和工具链技术的集合。

libomp

18.1.8

一个库,用于并行编程使用 Open MP API 规格。

lld

18.1.8

LLVM 链接器。

python-lit

18.1.8

LLVM 和 Clang 测试套件的软件测试工具。

注意

CMake 构建管理器不是 LLVM Toolset 的一部分。在 Red Hat Enterprise Linux 8 中,System 仓库中提供了 CMake。在 Red Hat Enterprise Linux 9 中,System 仓库中提供了 CMake。有关如何在 Red Hat Enterprise Linux 上安装 CMake 的更多信息,请参阅 在 Red Hat Enterprise Linux 上安装 CMake

1.2. LLVM 工具集兼容性

LLVM Toolset 适用于 Red Hat Enterprise Linux 8 和 Red Hat Enterprise Linux 9:

  • AMD 和 Intel 64 位
  • 64-bit ARM
  • IBM Power Systems, Little Endian
  • 64-bit IBM Z

1.3. 安装 LLVM Toolset

完成以下步骤以安装 LLVM Toolset,包括所有开发和调试工具以及依赖的软件包。

先决条件

  • 已安装所有可用的 Red Hat Enterprise Linux 更新。

流程

在 Red Hat Enterprise Linux 8 中,运行以下命令来安装 llvm-toolset 模块:

# yum module install llvm-toolset
重要

这不会在 Red Hat Enterprise Linux 8 上安装 LLDB debugger 或 python3-lit 软件包。要安装 LLDB 调试器和 python3-lit 软件包,请运行:

# yum install lldb python3-lit

在 Red Hat Enterprise Linux 9 中,运行以下命令来安装 llvm-toolset 软件包:

# dnf install llvm-toolset
重要

这不会在 Red Hat Enterprise Linux 9 上安装 LLDB debugger 或 python3-lit 软件包。要安装 LLDB 调试器和 python3-lit 软件包,请运行:

# dnf install lldb python3-lit

1.4. 安装 CMake 构建管理器

CMake 构建管理器是一个独立于您的编译器管理源代码的构建过程的工具。Cmake 可以生成原生构建环境来编译源代码、创建库、生成打包程序和构建可执行文件。
完成以下步骤以安装 CMake 构建管理器。

先决条件

流程

要安装 CMake,请运行以下命令:

  • 在 Red Hat Enterprise Linux 8 中:
# yum install cmake
  • 在 Red Hat Enterprise Linux 9 中:
# dnf install cmake

其他资源

  • 有关 CMake 构建管理器的更多信息,请参阅官方 CMake 文档 关于 CMake
  • 有关使用 CMake 构建管理器的介绍,请参阅:

1.5. 安装 LLVM Toolset 文档

您可以在本地系统上安装 LLVM Toolset 的文档。

先决条件

流程

要安装 llvm-doc 软件包,请运行以下命令:

  • 在 Red Hat Enterprise Linux 8 中:

    # yum install llvm-doc

    您可以在以下路径中找到文档: /usr/share/doc/llvm/html/index.html

  • 在 Red Hat Enterprise Linux 9 中:

    # dnf install llvm-doc

    您可以在以下路径中找到文档: /usr/share/doc/llvm/html/index.html

1.6. 安装 CMake 文档

您可以在本地系统上安装 CMake 构建管理器的文档。

先决条件

流程

要安装 cmake-doc 软件包,请运行以下命令:

  • 在 Red Hat Enterprise Linux 8 中:

    # yum install cmake-doc

    您可以在以下路径中找到文档: /usr/share/doc/cmake/html/index.html

  • 在 Red Hat Enterprise Linux 9 中:

    # dnf install cmake-doc

    您可以在以下路径中找到文档: /usr/share/doc/cmake/html/index.html

第 2 章 Clang 编译器

clang 是基于 C 语言 C、C++、目标 C/C++、OpenCL 和 Cuda 的 LLVM 编译器前端。

LLVM Toolset 与 Clang 18.1.8 一起发布。

2.1. 先决条件

2.2. 编译源文件

使用 Clang 编译器编译源文件和装配语言源文件。clang 会创建一个可执行的二进制文件,作为编译的结果。要能够调试代码,通过在 Clang 命令中添加 -g 标志来启用调试信息。

注意

要编译 C++ 程序,请使用 clang++ 而不是 clang

流程

要编译程序,请运行以下命令:

  • 在 Red Hat Enterprise Linux 8 中:

    $ clang -o -g <binary_file> <source_file>
    • <binary_file > 替换为输出文件所需的名称,将 <source_file > 替换为源文件的名称。
  • 在 Red Hat Enterprise Linux 9 中:

    $ clang -o -g <binary_file> <source_file>
    • <binary_file > 替换为输出文件所需的名称,将 <source_file > 替换为源文件的名称。

2.3. 运行程序

Clang 编译器会创建一个可执行的二进制文件,作为编译的结果。完成以下步骤以执行此文件并运行您的程序。

先决条件

  • 您的程序已编译。
    有关如何编译程序的更多信息,请参阅 编译源文件

流程

要运行程序,请在包含可执行文件的目录中运行:

$ ./<binary_file>
  • <binary_file > 替换为可执行文件的名称。

2.4. 将目标文件连接在一起

通过将目标文件连接在一起,您只能编译包含更改的源文件,而不是整个项目。
当您使用由多个源文件组成的项目时,请使用 Clang 编译器为每个源文件编译目标文件。下一步,将这些目标文件链接到一起。clang 会自动生成包含您链接的对象文件的可执行文件。编译后,将目标文件重新链接在一起。

注意

要编译 C++ 程序,请使用 clang++ 而不是 clang

流程

  1. 要将源文件编译到目标文件中,请运行以下命令:

    • 在 Red Hat Enterprise Linux 8 中:

      $ clang -o <object_file> -c <source_file>
      • <object_file > 替换为目标文件所需的名称,将 <source_file > 替换为源文件的名称。
    • 在 Red Hat Enterprise Linux 9 中:

      $ clang -o <object_file> -c <source_file>
      • <object_file > 替换为目标文件所需的名称,将 <source_file > 替换为源文件的名称。
  2. 要将目标文件连接在一起,请运行以下命令:

    • 在 Red Hat Enterprise Linux 8 中:

      $ clang -o <output_file> <object_file_0> <object_file_1>
      • <output_file > 替换为输出文件所需的名称,将 &lt ;object_file > 替换为您要链接的对象文件的名称。
    • 在 Red Hat Enterprise Linux 9 中:

      $ clang -o <output_file> <object_file_0> <object_file_1>
      • <output_file > 替换为输出文件所需的名称,将 &lt ;object_file > 替换为您要链接的对象文件的名称。
重要

目前,某些库功能被静态链接到使用 LLVM Toolset 构建的应用程序,以支持它们在多个 Red Hat Enterprise Linux 版本上执行。这会产生一个小的安全风险。如果您需要因为这个风险而重建应用程序,红帽会发出一个安全勘误。

红帽建议不要静态链接您的整个应用程序。

第 3 章 LLDB debugger

LLDB debugger 是调试 C 和 C++ 程序的命令行工具。使用 LLDB 检查被调试的代码中的内存,控制代码的执行状态,并检测代码的特定部分的执行。

LLVM Toolset 与 LLDB {comp-ver-rhel-7} 一起分发。

3.1. 先决条件

  • LLVM Toolset 已安装。
    如需更多信息,请参阅安装 LLVM Toolset
  • 您的编译器被配置为创建调试信息。
    有关配置 Clang 编译器的说明,请参阅 Clang Compiler User Manual 中的 控制 调试信息。
    有关配置 GCC 编译器的说明,请参阅 Red Hat Developer Toolset 用户指南中的 为调试准备程序

3.2. 启动调试会话

使用 LLDB 启动交互式调试会话。

流程

  • 要在您要调试的程序上运行 LLDB,请使用以下命令:

    • 在 Red Hat Enterprise Linux 8 中:

      $ lldb <binary_file>
      • <binary_file > 替换为编译的程序的名称。

        您已在交互模式中启动 LLDB 调试会话。您的命令行终端现在显示默认提示 (lldb)

    • 在 Red Hat Enterprise Linux 9 中:

      $ lldb <binary_file>
      • <binary_file > 替换为编译的程序的名称。

        您已在交互模式中启动 LLDB 调试会话。您的命令行终端现在显示默认提示 (lldb)

  • 要退出调试会话并返回到 shell 提示符,请运行以下命令:
(lldb) quit

3.3. 在调试会话中执行程序

使用 LLDB 在调试会话期间执行您的程序。当达到第一个断点、发生错误或程序终止时,程序的执行会停止。

先决条件

流程

  • 要执行您要调试的程序,请运行:

    (lldb) run
  • 要使用特定参数执行您要调试的程序,请运行:

    (lldb) run <argument>
    • 使用您要使用的命令行参数替换 < 参数 >。

3.4. 使用断点

使用断点在源代码中的集合点暂停程序的执行。

先决条件

流程

  • 要在特定行中设置一个新的断点,请运行以下命令:

    (lldb) breakpoint set --file <source_file_name> --line <line_number>
    • <source_file_name > 替换为源文件的名称,将 &lt ;line_number > 替换为您要在其中设置断点的行号。
  • 要在特定功能上设置断点,请运行以下命令:

    (lldb) breakpoint set --name <function_name>
    • <function_name > 替换为您要在其中设置断点的功能的名称。
  • 要显示当前设置断点列表,请运行以下命令:

    (lldb) breakpoint list
  • 要删除断点,请运行:

    (lldb) breakpoint clear -f <source_file_name> -l <line_number>
    • <source_file_name > 替换为源文件的名称,将 &lt ;line_number > 替换为您要删除的断点的行号。
  • 要在达到断点后恢复程序的执行,请运行:

    (lldb) continue
  • 要跳过特定数量的断点,请运行以下命令:

    (lldb) continue -i <breakpoints_to_skip>
    • <breakpoints_to_skip > 替换为您要跳过的断点数。

      注意

      要跳过一个循环,将 &lt ;breakpoints_to_skip& gt; 设置为与循环迭代计数匹配。

3.5. 逐步浏览代码

您可以使用 LLDB 单步调试程序代码,使其仅在行指针后执行一行代码。

先决条件

流程

  • 单行代码:

    1. 将行指针设置为您要执行的行。
    2. 运行以下命令:

      (lldb) step
  • 逐步浏览特定数量的代码行:

    1. 将行指针设置为您要执行的行。
    2. 运行以下命令:

      (lldb) step -c <number>
      • 使用您要执行的行数替换 <number>。

3.6. 列出源代码

在执行调试程序之前,LLDB 调试器会自动显示源代码的前 10 行。每次程序执行停止时,LLDB 会显示它停止的源代码行,以及它们周围的行。您可以使用 LLDB 在调试会话过程中手动触发源代码显示。

先决条件

流程

  • 要列出您要调试的程序源代码的前 10 行,请运行:

    (lldb) list
  • 要显示特定行的源代码,请运行:

    (lldb) list <source_file_name>:<line_number>
    • <source_file_name > 替换为源文件的名称,将 & lt;line_number > 替换为您要显示的行数。

3.7. 显示当前程序数据

LLDB debugger 对任何复杂性、任何有效的表达式和函数调用返回值提供数据。您可以使用 LLDB 显示与程序状态相关的数据。

先决条件

流程

要显示特定变量、表达式或返回值的当前值,请运行:

(lldb) print <data_name>
  • 使用您要 显示的数据替换 <data_name >。

在 RHEL 8 中,您可以使用 Containerfiles 在 Red Hat Universal Base Images (UBI)容器上构建自己的 LLVM Toolset 容器镜像。

4.1. 在 RHEL 8 上创建 LLVM Toolset 的容器镜像

在 RHEL 8 中,LLVM Toolset 软件包是 Red Hat Universal Base Images (UBI)软件仓库的一部分。要保持容器镜像大小小,请只安装单个软件包而不是整个 LLVM Toolset。

先决条件

  • 一个现有的 Containerfile。
    有关创建 Containerfiles 的详情,请参考 Dockerfile 参考 页面。

流程

  • 访问 红帽容器目录
  • 选择 UBI。
  • Get this image 并按照说明进行操作。
  • 要创建包含 LLVM Toolset 的容器镜像,请在 Containerfile 中添加以下行:
FROM registry.access.redhat.com/ubi8/ubi:latest

RUN yum module install -y llvm-toolset
  • 要创建只包含独立软件包的容器镜像,请在 Containerfile 中添加以下行:

    RUN yum install -y <package-name>
    • 将 < package-name > 替换为您要安装的软件包的名称。

第 5 章 LLVM Toolset 中的更改

LLVM Toolset 在 RHEL 8 和 RHEL 9 上已从 17.0.6 更新至 18.1.8。

重要的 LLVM 更新:

  • 以下指令的常量表达式变体已删除:and,orlshr,ashr,zext,sext,fptrunc,fpext,fptoui,fptosi,uitofp,sitofp.
  • 添加了 llvm.exp10 内在函数。
  • 添加了全局变量的 code_model 属性。
  • 改进了 AArch64, AMDGPU, PowerPC, RISC-V, SystemZ 和 x86 架构的后端。
  • LLVM 工具已改进。

显著的 Clang 改进:

  • C++20 功能支持:

    • clang 不再执行 One Definition Rule(ODR)来检查全局模块片段中的声明。要启用更严格的行为,请使用 -Xclang -fno-skip-odr-check-in-gmf 选项。
  • C++23 功能支持:

    • 添加了一个新的诊断标记 -Wc++23-lambda-attributes,以警告对 lambdas 使用属性。
  • C++2c 功能支持:

    • clang 现在允许在同一范围内多次使用 _ 字符作为占位符变量名称。
    • 在是字符串文字的属性参数中,属性现在期望未评估的字符串。
    • 对 C++26 中弃用的枚举的算术转换已删除。
    • 改进了模板参数初始化的规范。
  • 有关更改的完整列表,请参阅 Clang 的上游发行注记

Clang 中的 ABI 变化:

  • 按照 x86_64 的 SystemV ABI ,__int128 参数不再在寄存器和堆栈插槽之间拆分。
  • 如需更多信息,请参阅 Clang 中 ABI 变化的列表

重要的后向不兼容变化:

  • 模板运算符的反向参数顺序中的 bug 修复破坏了之前在 C++17 中接受的 C++20 中的代码。
  • GCC_INSTALL_PREFIX CMake 变量(其设置默认的 -gcc-toolchain=)已被弃用,并将被删除。改为在配置文件中指定 --gcc-install-dir=--gcc-triple= 选项。
  • 预编译标头(PCH)生成(-c -xc-header-c -xc++-header)的默认扩展名称是 .pch 而不是 .gch
  • -include a.h 探测 a.h.gch 文件时,如果a.h.gch 不是 Clang PCH 文件或包含任何 Clang PCH 文件的目录,则 include 现在忽略 a.h.gch
  • 修复了对某些 C++-11-style 属性导致 __has_cpp_attribute__has_c_attribute 返回错误值的 bug 。
  • 在添加反向 operator== 时查找匹配的 operator!= 的 bug 已修复。
  • 功能模板的名称修改规则已更改为接受函数可以在其模板参数列表或 requires 子句上超载。
  • 现在,在系统标头和宏上默认启用 -Wenum-constexpr-conversion 警告。在下一个 Clang 版本中,它将被转换为一个硬(不可升级)错误。
  • 用于 C++20 命名的模块的导入模块的路径不再被硬编码。您必须从命令行指定所有依赖的模块。
  • 不再可能使用 import <module> 来导入模块;Clang 使用明确构建的模块。
  • 如需了解更多详细信息,请参阅 可能破坏更改的列表

有关更新的详细信息,请参阅上游 LLVM 发行注记Clang 发行注记

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, 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, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部