跳转至

ev-mold-consteval-max-distance-001

字段 值
项目 rui314/mold
固定 commit 27162691b71a
路径 src/thunks.cc
行段 L36-L43
特性 consteval 与 constinit
许可证 MIT
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-26
测试代码 否
发现方式 manual

用法

用 consteval 计算目标平台的分支距离上限

为什么典型

目标架构在编译期已确定,距离上限不应在运行时重复计算;consteval 强制所有调用都产生常量。

摘录

static consteval i64 max_distance() {
  // ARM64's branch has 26 bits immediate. The immediate is padded with
  // implicit two-bit zeros because all instructions are 4 bytes aligned
  // and therefore the least two bits are always zero. So the branch
  // operand is effectively 28 bits long. That means the branch range is
  // [-2^27, 2^27) or PC ± 128 MiB.
  if (is_arm64<E>)
    return 1 << 27;

备注

生产路径;链接器的 thunk 距离计算,结果参与代码生成。

查看固定 commit 源码 · 返回证据索引