[llvm-branch-commits] [lld] ELF: CFI jump table relaxation. (PR #147424)
Vitaly Buka via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 1 17:51:25 PDT 2026
================
@@ -312,6 +313,193 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is,
return true;
}
+void X86_64::relaxCFIJumpTables() const {
+ // Relax CFI jump tables.
+ // - Split jump table into pieces and place target functions inside the jump
+ // table if small enough.
+ // - Move jump table before last called function and delete last branch
+ // instruction.
+ DenseMap<InputSection *, std::vector<InputSection *>> sectionReplacements;
+ SmallVector<InputSection *, 0> storage;
+ for (OutputSection *osec : ctx.outputSections) {
+ if (!(osec->flags & SHF_EXECINSTR))
+ continue;
+ for (InputSection *sec : getInputSections(*osec, storage)) {
+ if (sec->type != SHT_LLVM_CFI_JUMP_TABLE || sec->entsize == 0 ||
+ sec->size % sec->entsize != 0)
+ continue;
+
+ // We're going to replace the jump table with this list of sections. This
+ // list will be made up of slices of the original section and function
+ // bodies that were moved into the jump table.
+ std::vector<InputSection *> replacements;
+
+ // Add the slice [begin, end) of the original section to the replacement
+ // list. [rbegin, rend) is the slice of the relocation list that covers
+ // [begin, end).
----------------
vitalybuka wrote:
addSectionSlice can be moved closer to the user
https://github.com/llvm/llvm-project/pull/147424
More information about the llvm-branch-commits
mailing list