[all-commits] [llvm/llvm-project] 7212c8: ELF: CFI jump table relaxation.

Peter Collingbourne via All-commits all-commits at lists.llvm.org
Mon Jun 8 09:55:17 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7212c8f83b16afae9f4f4ca2fb724bc6518ae4f2
      https://github.com/llvm/llvm-project/commit/7212c8f83b16afae9f4f4ca2fb724bc6518ae4f2
  Author: Peter Collingbourne <pcc at google.com>
  Date:   2026-06-08 (Mon, 08 Jun 2026)

  Changed paths:
    M lld/ELF/Arch/X86_64.cpp
    M lld/ELF/OutputSections.cpp
    M lld/ELF/Target.h
    M lld/ELF/Writer.cpp
    M lld/docs/ld.lld.1
    A lld/test/ELF/x86-64-relax-jump-tables.s

  Log Message:
  -----------
  ELF: CFI jump table relaxation.

Indirection via the jump table increases the icache and TLB miss rate
associated with indirect calls, and according to internal benchmarking
was identified as one of the main runtime costs of CFI, contributing
around 30% of the total overhead. #145579 addressed the problem for
direct calls to jump table entries, but the indirect call overhead is
still present. This patch implements jump table relaxation, which is a
technique for opportunistically reducing the indirect call overhead.

The basic idea is to eliminate the indirection by moving function
bodies into the jump table wherever possible. This is possible in two
circumstances:

- When the body size is at most the size of a jump table entry.
- When the function is the last function in the jump table.

In both cases, we may move the function body into the jump table by
splitting the jump table in two, with enough space in the middle for the
function body, and placing the function there.

We leave the last function in the jump table at its original location
and place the rest of the jump table behind it. The goal of this is to
decrease the TLB miss rate, on the assumption that it is more likely
for functions with the same type (and their callees) to be in the same
page as each other than for them to be in the same page as the original
location of the jump table (typically clustered together near the end
of the binary).

A complete implementation of jump table relaxation was found to reduce
the overhead of CFI in a large realistic internal Google benchmark
by between 0.2 and 0.5 percentage points, or 10-25%, depending on the
microarchitecture.

Reviewers: vitalybuka, MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/147424



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list