summaryrefslogtreecommitdiff
path: root/bolt/include
AgeCommit message (Collapse)Author
2025-11-14[BOLT][print] Add option '--print-only-file' (NFC) (#168023)YongKang Zhu
With this option we can pass to BOLT names of functions to be printed through a file instead of specifying them all on command line.
2025-11-11[BOLT] Move call probe information to CallSiteInfoAmir Ayupov
Pseudo probe matching (#100446) needs callee information for call probes. Embed call probe information (probe id, inline tree node, indirect flag) into CallSiteInfo. As a consequence: - Remove call probes from PseudoProbeInfo to avoid duplication, making it only contain block probes. - Probe grouping across inline tree nodes becomes more potent + allows to unambiguously elide block id 1 (common case). Block mask (blx) encoding becomes a low-ROI optimization and will be replaced by a more compact encoding leveraging simplified PseudoProbeInfo in #166680. The size increase is ~3% for an XL profile (461->475MB). Compact block probe encoding shrinks it by ~6%. Test Plan: updated pseudoprobe-decoding-{inline,noinline}.test Reviewers: paschalis-mpeis, ayermolo, yota9, yozhu, rafaelauler, maksfb Reviewed By: rafaelauler Pull Request: https://github.com/llvm/llvm-project/pull/165490
2025-11-11[BOLT][DWARF] Slice .debug_str from the DWP for each CU (#159540)Liu Ke
Slice .debug_str from the DWP for each CU using .debug_str_offsets and emit it, instead of directly copying the global .debug_str, in order to address the bloat issue of DWO after updates. (more details here - #155766 )
2025-11-10[BOLT][AArch64] Add more heuristics on epilogue determination (#167077)YongKang Zhu
Add more heuristics to check if a basic block is an AArch64 epilogue. We assume instructions that load from stack or adjust stack pointer as valid epilogue code sequence if and only if they immediately precede the branch instruction that ends the basic block.
2025-11-10[BOLT] Simplify RAState helpers (NFCI) (#162820)Gergely Bálint
- unify isRAStateSigned and isRAStateUnsigned to a common getRAState, - unify setRASigned and setRAUnsigned into setRAState(MCInst, bool), - update users of these to match the new implementations.
2025-11-09[BOLT] Support restartable sequences in tcmalloc (#167195)Maksim Panchenko
Add `RSeqRewriter` to detect code references from `__rseq_cs` section and ignore function referenced from that section. Code references are detected via relocations (static or dynamic). Note that the abort handler is preceded by a 4-byte signature byte sequence and we cannot relocate the handler without that the signature, otherwise the application may crash. Thus we are ignoring the function, i.e. making sure it's not separated from its signature.
2025-11-08[BOLT] Refactor tracking internals of BinaryFunction. NFCI (#167074)Maksim Panchenko
In addition to tracking offsets inside a `BinaryFunction` that are referenced by data relocations, we need to track those relocations too. Plus, we will need to map symbols referenced by such relocations back to the containing function. This change introduces `BinaryFunction::InternalRefDataRelocations` to track the aforementioned relocations and expands `BinaryContext::SymbolToFunctionMap` to include local/temp symbols involved in relocation processing. There is no functional change introduced that should affect the output. Future PRs will use the new tracking capabilities.
2025-11-07[BOLT] Refactor undefined symbols handling. NFCI (#167075)Maksim Panchenko
Remove internal undefined symbol tracking and instead rely on the emission state of `MCSymbol` while processing data-to-code relocations. Note that `CleanMCState` pass resets the state of all `MCSymbol`s prior to code emission.
2025-11-04[BOLT][AArch64] Run LDR relaxation (#165787)YongKang Zhu
Replace the current `ADRRelaxationPass` with `AArch64RelaxationPass`, which, besides the existing ADR relaxation, will also run LDR relaxation that for now only handles these two forms of LDR instructions: `ldr Xt, [label]` and `ldr Wt, [label]`.
2025-10-31[BOLT] Refactor handling of branch targets. NFCI (#165828)Maksim Panchenko
Refactor code that verifies external branch destinations and creates secondary entry points.
2025-10-29[BOLT][NFC] Drop unused profile staleness stats (#165489)Amir Ayupov
Equal number of blocks in a function/instructions in a block between stale profile and the binary isn't used in the matching. Remove these stats to declutter the output. Test Plan: NFC
2025-10-28[BOLT] Fix thread-safety of MarkRAStates (#165368)Gergely Bálint
The pass calls setIgnored() on functions in parallel, but setIgnored is not thread safe. This patch adds a std::mutex to guard setIgnored calls. Fixes: #165362
2025-10-25[BOLT] Remove CreatePastEnd parameter in getOrCreateLocalLabel(). NFC (#165065)Maksim Panchenko
CreatePastEnd parameter had no effect on the label creation. Remove it.
2025-10-22[BOLT][AArch64] Validate code padding (#164037)YongKang Zhu
Check whether AArch64 function code padding is valid, and add an option to treat invalid code padding as error.
2025-10-15[BOLT][NFC] Rename getNames for PLT, TailDuplication (#119870)Paschalis Mpeis
2025-10-14[bolt] Fix typos discovered by codespell (#124726)Christian Clauss
https://github.com/codespell-project/codespell ```bash codespell bolt --skip="*.yaml,Maintainers.txt" --write-changes \ --ignore-words-list=acount,alledges,ans,archtype,defin,iself,mis,mmaped,othere,outweight,vas ```
2025-10-08Reapply "[BOLT][AArch64] Handle OpNegateRAState to enable optimizing ↵Gergely Bálint
binaries with pac-ret hardening" (#162353) (#162435) Reapply "[BOLT][AArch64] Handle OpNegateRAState to enable optimizing binaries with pac-ret hardening (#120064)" (#162353) This reverts commit c7d776b06897567e2d698e447d80279664b67d47. #120064 was reverted for breaking builders. Fix: changed the mismatched type in MarkRAStates.cpp to `auto`. --- Original message: OpNegateRAState is an AArch64-specific DWARF CFI used to change the value of the RA_SIGN_STATE pseudoregister. The RA_SIGN_STATE register records whether the current return address has been signed with PAC. OpNegateRAState requires special handling in BOLT because its placement depends on the function layout. Since BOLT reorders basic blocks during optimization, these CFIs must be regenerated after layout is finalized. This patch introduces two new passes: - MarkRAStates (runs before optimizations): assigns a signedness annotation to each instruction based on OpNegateRAState CFIs in the input binary. - InsertNegateRAStates (runs after optimizations): reads the annotations and emits new OpNegateRAState CFIs where RA state changes between instructions. Design details are described in: `bolt/docs/PacRetDesign.md`.
2025-10-07Revert "[BOLT][AArch64] Handle OpNegateRAState to enable optimizing binaries ↵Gergely Bálint
with pac-ret hardening" (#162353) Reverts llvm/llvm-project#120064. @gulfemsavrun reported that the patch broke toolchain builders.
2025-10-07[BOLT][AArch64] Handle OpNegateRAState to enable optimizing binaries with ↵Gergely Bálint
pac-ret hardening (#120064) OpNegateRAState is an AArch64-specific DWARF CFI used to change the value of the RA_SIGN_STATE pseudoregister. The RA_SIGN_STATE register records if the current return address has been signed with PAC. OpNegateRAState requires special handling in BOLT because its placement depends on the function layout. Since BOLT reorders basic blocks during optimization, these CFIs must be regenerated after layout is finalized. This patch introduces two new passes: - MarkRAStates (runs before optimizations): assigns a signedness annotation to each instruction based on OpNegateRAState CFIs in the input binary. - InsertNegateRAStates (runs after optimizations): reads the annotations and emits new OpNegateRAState CFIs where RA state changes between instructions. Design details are described in: `bolt/docs/PacRetDesign.md`.
2025-10-03[BOLT][AArch64] Refuse to run CDSplit pass (#159351)Paschalis Mpeis
LongJmp does not support warm blocks. On builds without assertions, this may lead to unexpected crashes. This patch exits with a clear message.
2025-10-03[BOLT] Add GNUPropertyRewriter and warn on AArch64 BTI note (#161206)Gergely Bálint
This commit adds the GNUPropertyRewriter, which parses features from the .note.gnu.property section. Currently we only read the bit indicating BTI support (GNU_PROPERTY_AARCH64_FEATURE_1_BTI). As BOLT does not add BTI landing pads to targets of indirect branches/calls, we have to emit a warning that the output binary may be corrupted.
2025-10-01[BOLT] Remove unused parameter. NFC (#161617)Maksim Panchenko
`Skip` parameter not used/set inside `analyzeRelocation()`.
2025-09-30[BOLT] Introduce helpers to match `MCInst`s one at a time (NFC) (#138883)Anatoly Trosinenko
Introduce a low-level instruction matching DSL to capture and/or match the operands of MCInst, single instruction at a time. Unlike the existing `MCPlusBuilder::MCInstMatcher` machinery, this DSL is intended for the use cases when the precise control over the instruction order is required. For example, when validating PtrAuth hardening, all registers are usually considered unsafe after a function call, even though callee-saved registers should preserve their old values _under normal operation_. Usage example: // Bring the short names into the local scope: using namespace LowLevelInstMatcherDSL; // Declare the registers to capture: Reg Xn, Xm; // Capture the 0th and 1st operands, match the 2nd operand against the // just captured Xm register, match the 3rd operand against literal 0: if (!matchInst(MaybeAdd, AArch64::ADDXrs, Xm, Xn, Xm, Imm(0)) return AArch64::NoRegister; // Match the 0th operand against Xm: if (!matchInst(MaybeBr, AArch64::BR, Xm)) return AArch64::NoRegister; // Manually check that Xm and Xn did not match the same register: if (Xm.get() == Xn.get()) return AArch64::NoRegister; // Return the matched register: return Xm.get();
2025-09-30[BOLT] Refactor MCInstReference and move it to Core (NFC) (#155846)Anatoly Trosinenko
Refactor MCInstReference class and move it from PAuth gadget scanner to Core. MCInstReference is a class representing a reference to a constant instruction inside a parent entity - either inside a basic block (which has a reference to its parent function) or directly inside a function (when CFG information is not available). This patch reapplies #138655 with a fix for iterator usage and multiple minor issues fixed during the second round of review.
2025-09-25[BOLT] Add heuristics to determine constant island's alignment (#159486)YongKang Zhu
Constant island embedded in text section doesn't have its alignment information from input binary and we currently set its alignment as 8 bytes. Constant island might be given a much larger alignment due to performance or other reasons, so this change adds some heuristics to determine its alignment based on its size, original address from input binary and its owning section's alignment.
2025-09-25[BOLT][AArch64][instr] Consider targeting ARM64 CPUs without LSE support ↵YongKang Zhu
(#158738) `stadd` is only available in recent arm64 CPUs that have LSE support (like Cortex-A73 and Cortex-A75) and is not available on old arm64 CPUs (like Cortex-A53 and Cortex-A55). Devices could have a mixture of these two kinds of CPUs, for which we need to provide an option for BOLT to generate instrumentation sequence that emulates what `stadd` would do. The implementation puts counter increment into an injected helper function so we don't need to update CFG in the function that is being instrumented and instrumentation induced binary size increase will be smaller.
2025-09-23[BOLT] Avoid n^2 complexity in fixBranches(). NFCI (#160407)Maksim Panchenko
Iterator implementation of PR #156243: This improves BOLT runtime when optimizing rustc_driver.so from 15 minutes to 7 minutes (or 49 minutes to 37 minutes of userspace time). Co-authored-by: Mark-Simulacrum <mark.simulacrum@gmail.com>
2025-09-23[BOLT][DWARF] Skip processing DWARF CUs with a DWO ID but no DWO name (#154749)Jinjie Huang
This patch tries to skip processing DWARF CUs with a DWO ID but no DWO name, and ensure them not included in the final binary.
2025-09-12[BOLT] fix print-mem-data not working (#156332)Haibo Jiang
This option `print-mem-data` is currently not working, use this fix to restore its functionality.
2025-09-11[BOLT] Fix debug line emission for functions in multiple compilation units ↵Grigory Pastukhov
(#151230) This patch fixes a bug in BOLT's debug line emission where functions that belong to multiple compilation units (such as inline functions in header files) were not handled correctly. Previously, BOLT incorrectly assumed that a binary function could belong to only one compilation unit, leading to incomplete or incorrect debug line information. ### **Problem** When a function appears in multiple compilation units (common scenarios include): * Template instantiated functions * Inline functions defined in header files included by multiple source files BOLT would only emit debug line information for one compilation unit, losing debug information for other CUs where the function was compiled. This resulted in incomplete debugging information and could cause debuggers to fail to set breakpoints or show incorrect source locations. ### **Root Cause** The issue was in BOLT's assumption that each binary function maps to exactly one compilation unit. However, when the same function (e.g., an inline function from a header) is compiled into multiple object files, it legitimately belongs to multiple CUs in the final binary.
2025-09-09[BOLT][AArch64] Inlining of Memcpy (#154929)YafetBeyene
The pass for inlining memcpy in BOLT was currently X86-specific and was using the instruction `rep movsb`. This patch implements a static size analysis system for AArch64 memcpy inlining that extracts copy sizes from preceding instructions to then use it to generate the optimal width-specific load/store sequences.
2025-08-27Revert "[BOLT] Refactor MCInstReference and move it to Core (NFC)" (#155639)Anatoly Trosinenko
Reverts llvm/llvm-project#138655.
2025-08-27[BOLT] Refactor MCInstReference and move it to Core (NFC) (#138655)Anatoly Trosinenko
Refactor MCInstReference class and move it from PAuth gadget scanner to Core. MCInstReference is a class representing a constant reference to an instruction inside a parent entity - either inside a basic block (which has a reference to its parent function) or directly inside a function (when CFG information is not available).
2025-08-25[BOLT] Gadget scanner: account for BRK when searching for auth oracles (#137975)Anatoly Trosinenko
An authenticated pointer can be explicitly checked by the compiler via a sequence of instructions that executes BRK on failure. It is important to recognize such BRK instruction as checking every register (as it is expected to immediately trigger an abnormal program termination) to prevent false positive reports about authentication oracles: autia x2, x3 autia x0, x1 ; neither x0 nor x2 are checked at this point eor x16, x0, x0, lsl #1 tbz x16, #62, on_success ; marks x0 as checked ; end of BB: for x2 to be checked here, it must be checked in both ; successor basic blocks on_failure: brk 0xc470 on_success: ; x2 is checked ldr x1, [x2] ; marks x2 as checked
2025-08-22[BOLT] Add dump-dot-func option for selective function CFG dumping (#153007)YafetBeyene
## Change: * Added `--dump-dot-func` command-line option that allows users to dump CFGs only for specific functions instead of dumping all functions (the current only available option being `--dump-dot-all`) ## Usage: * Users can now specify function names or regex patterns (e.g., `--dump-dot-func=main,helper` or `--dump-dot-func="init.*`") to generate .dot files only for functions of interest * Aims to save time when analysing specific functions in large binaries (e.g., only dumping graphs for performance-critical functions identified through profiling) and we can now avoid reduce output clutter from generating thousands of unnecessary .dot files when analysing large binaries ## Testing The introduced test `dump-dot-func.test` confirms the new option does the following: - [x] 1. `dump-dot-func` can correctly filter a specified functions - [x] 2. Can achieve the above with regexes - [x] 3. Can do 1. with a list of functions - [x] No option specified creates no dot files - [x] Passing in a non-existent function generates no dumping messages - [x] `dump-dot-all` continues to work as expected
2025-08-20[BOLT] Validate extra entry point by querying data marker symbols (#154611)YongKang Zhu
Look up marker symbols and decide whether candidate is really extra entry point in `adjustFunctionBoundaries()`.
2025-08-15[BOLT] Do not use HLT as split point when build the CFG (#150963)Haibo Jiang
For x86, the halt instruction is defined as a terminator instruction. When building the CFG, the instruction sequence following the hlt instruction is treated as an independent MBB. Since there is no jump information, the predecessor of this MBB cannot be identified, and it is considered an unreachable MBB that will be removed. Using this fix, the instruction sequences before and after hlt are refused to be placed in different blocks.
2025-08-07Revert "[BOLT][NFC] Register profiled functions once (#150622)" (#152597)Rafael Auler
In perf2bolt, we are observing sporadic crashes in the recently added registerProfiledFunctions from #150622. Addresses provided by the hardware (from LBR) might be -1, which clashes with what LLVM uses in DenseSet as empty tombstones records. This causes DenseSet to assert with "can't insert empty tombstone into map" when ingesting this data. Revert this change for now to unbreak perf2bolt.
2025-07-28[BOLT][NFC] Register profiled functions once (#150622)Amir Ayupov
While registering profiled functions, only handle each address once. Speeds up `DataAggregator::preprocessProfile`. Test Plan: For intermediate size pre-aggregated profile (10MB), reduces parsing time from ~0.41s down to ~0.16s.
2025-07-12[BOLT] Impute missing trace fall-through (#145258)Amir Ayupov
2025-07-10[BOLT] Ensure remember and restore CFIs are in the same list (#144348)Asher Dobrescu
In `addCFIInstruction`, we split the CFI information between `CFIInstrMapType CIEFrameInstructions` and `CFIInstrMapType FrameInstructions`. In some cases we can end up with the remember CFI in `CIEFrameInstructions` and the restore CFI in `FrameInstructions`. This patch adds a check to make sure we do not split remember and restore states and fixes https://github.com/llvm/llvm-project/issues/133501.
2025-07-07[BOLT][NFCI] Report perf script time (#147232)Amir Ayupov
Leverage `sys::ProcessStatistics` to report the run time and memory usage of perf script processes launched when reading perf data. The reporting is enabled in debug mode with `-debug-only=aggregator`. Switch buildid-list command to non-waiting `launchPerfProcess` to get its runtime as well, unifying it with the rest of perf script processes. Test Plan: NFC
2025-07-02[BOLT] Decouple new segment creation from PHDR rewrite. NFCI (#146111)Maksim Panchenko
Refactor handling of PHDR table rewrite to make modifications easier.
2025-06-30[BOLT] Refactor mapCodeSections(). NFC (#146434)Maksim Panchenko
Factor out non-relocation specific code into a separate function.
2025-06-27MC: Reduce MCSymbolRefExpr::VK_None usesFangrui Song
2025-06-27Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… ↵Sterling-Augustine
(#145959) (#146112) Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… (#145959) This reapplies cbf781f0bdf2f680abbe784faedeefd6f84c246e, with fixes for the shared-library build and the unconventional sanitizer-runtime build. Original Description: This is the culmination of a series of changes described in [1]. Although somewhat large by line count, it is almost entirely mechanical, creating a new library in DebugInfo/DWARF/LowLevel. This new library has very minimal dependencies, allowing it to be used from more places than the normal DebugInfo/DWARF library--in particular from MC. 1. https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-26Revert "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… ↵Sterling-Augustine
(#145959) …145081)" This reverts commit cbf781f0bdf2f680abbe784faedeefd6f84c246e. Breaks a couple of buildbots.
2025-06-26[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#145081)Sterling-Augustine
This is the culmination of a series of changes described in [1]. Although somewhat large by line count, it is almost entirely mechanical, creating a new library in DebugInfo/DWARF/LowLevel. This new library has very minimal dependencies, allowing it to be used from more places than the normal DebugInfo/DWARF library--in particular from MC. I am happy to put it in another location, or to structure it differently if that makes sense. Some have suggested in BinaryFormat, but it is not a great fit there. But if that makes more sense to the reviewers, I can do that. Another possibility would be to use pass-through headers to allow clients who don't care to depend only on DebugInfo/DWARF. This would be a much less invasive change, and perhaps easier for clients. But also a system that hides details. Either way, I'm open. 1. https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-25[bolt] Fix the build after 0556a2aa187b86c28a9441aec3e98b9780a2c9eeBenjamin Kramer
StringRef now implictly converts into ArrayRef<char>.
2025-06-24[BOLT][NFC] Split out parsePerfData (#145248)Amir Ayupov