summaryrefslogtreecommitdiff
path: root/bolt/lib/Core/Exceptions.cpp
AgeCommit message (Collapse)Author
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-08-01[BOLT] Use std::optional::value_or (NFC) (#151628)Kazu Hirata
2024-11-13[BOLT] Never emit "large" functions (#115974)Maksim Panchenko
"Large" functions are functions that are too big to fit into their original slots after code modifications. CheckLargeFunctions pass is designed to prevent such functions from emission. Extend this pass to work with functions with constant islands. Now that CheckLargeFunctions covers all functions, it guarantees that we will never see such functions after code emission on all platforms (previously it was guaranteed on x86 only). Hence, we can get rid of RewriteInstance extensions that were meant to support "large" functions.
2024-11-12[BOLT] Use AsmInfo for address size. NFCI (#115932)Maksim Panchenko
Use AsmInfo instead of DWARFObj interface for extracting address size and format.
2024-07-24[BOLT][NFC] Track fragment relationships using EquivalenceClassesAmir Ayupov
Three-way splitting can create references between split fragments (warm to cold or vice versa) that are not handled by `isChildOf/isParentOf/isChildOrParentOf`. Generalize fragment relationships to allow checking if two functions belong to one group, potentially in presence of ICF which can join multiple groups. Test Plan: NFC for existing tests Reviewers: maksfb, ayermolo, rafaelauler, dcci Reviewed By: rafaelauler Pull Request: https://github.com/llvm/llvm-project/pull/99979
2024-02-27[BOLT] Refactor interface for instruction labels. NFCI (#83209)Maksim Panchenko
To avoid accidentally setting the label twice for the same instruction, which can lead to a "lost" label, introduce getOrSetInstLabel() function. Rename existing functions to getInstLabel()/setInstLabel() to make it explicit that they operate on instruction labels. Add an assertion in setInstLabel() that the instruction did not have a prior label set.
2024-02-12[BOLT][NFC] Log through JournalingStreams (#81524)Amir Ayupov
Make core BOLT functionality more friendly to being used as a library instead of in our standalone driver llvm-bolt. To accomplish this, we augment BinaryContext with journaling streams that are to be used by most BOLT code whenever something needs to be logged to the screen. Users of the library can decide if logs should be printed to a file, no file or to the screen, as before. To illustrate this, this patch adds a new option `--log-file` that allows the user to redirect BOLT logging to a file on disk or completely hide it by using `--log-file=/dev/null`. Future BOLT code should now use `BinaryContext::outs()` for printing important messages instead of `llvm::outs()`. A new test log.test enforces this by verifying that no strings are print to screen once the `--log-file` option is used. In previous patches we also added a new BOLTError class to report common and fatal errors, so code shouldn't call exit(1) now. To easily handle problems as before (by quitting with exit(1)), callers can now use `BinaryContext::logBOLTErrorsAndQuitOnFatal(Error)` whenever code needs to deal with BOLT errors. To test this, we have fatal.s that checks we are correctly quitting and printing a fatal error to the screen. Because this is a significant change by itself, not all code was yet ported. Code from Profiler libs (DataAggregator and friends) still print errors directly to screen. Co-authored-by: Rafael Auler <rafaelauler@fb.com> Test Plan: NFC
2024-02-12[BOLT][NFC] Propagate BOLTErrors from Core, RewriteInstance, and passes ↵Amir Ayupov
(2/2) (#81523) As part of the effort to refactor old error handling code that would directly call exit(1), in this patch continue the migration on libCore, libRewrite and libPasses to use the new BOLTError class whenever a failure occurs. Test Plan: NFC Co-authored-by: Rafael Auler <rafaelauler@fb.com>
2023-12-09[BOLT] Determine address size from binary (#74870)Nathan Sidwell
Query the executable for address size.
2023-11-20[BOLT] Fix C++ exceptions when LPStart is specified (#72737)Maksim Panchenko
Whenever LPStartEncoding was different from DW_EH_PE_omit, we used to miscalculate LPStart. As a result, landing pads were assigned wrong addresses. Fix that.
2023-11-06[BOLT] Fix build after 0df1546Maksim Panchenko
2023-11-06[BOLT] Use Label annotation instead of EHLabel pseudo. NFCI. (#70179)Maksim Panchenko
When we need to attach EH label to an instruction, we can now use Label annotation instead of EHLabel pseudo instruction.
2023-05-19[BOLT] Add isParentOf and isParentOrChildOf BF checksAmir Ayupov
Add helper methods and simplify cases where we want to check if two functions are parent-child of each other (function-fragment relationship). Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D142668
2023-02-09[BOLT] Rename BF::isParentFragment -> isChildOfAmir Ayupov
`isChildOf` is a more concise name for the check. Also, there's no need to test if the function is a fragment before doing `isChildOf` check. Reviewed By: #bolt, rafauler, maksfb Differential Revision: https://reviews.llvm.org/D142667
2023-02-04[AArch64] fix bug #55005 handle DW_CFA_GNU_NegateRAStateSebastian Pop
GCC on AArch64 uses DW_CFA_GNU_NegateRAState for return address signing. Differential Revision: https://reviews.llvm.org/D142572
2022-12-06[BOLT][NFC] Use std::optional in MCPlusBuilderAmir Ayupov
Reviewed By: maksfb, #bolt Differential Revision: https://reviews.llvm.org/D139260
2022-12-05[DebugInfo] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-21[bolt] Use llvm::sys::RWMutex instead of std::shared_timed_mutexNico Weber
This has the following advantages: - std::shared_timed_mutex is macOS 10.12+ only. llvm::sys::RWMutex automatically switches to a different implementation internally when targeting older macOS versions. - bolt only needs std::shared_mutex, not std::shared_timed_mutex. llvm::sys::RWMutex automatically uses std::shared_mutex internally where available. std::shared_mutex and RWMutex have the same API, so no code changes other than types and includes are needed. Differential Revision: https://reviews.llvm.org/D138423
2022-09-14[BOLT] Preserve original LSDA type encodingrevunov.denis@huawei.com
In non-pie binaries BOLT unconditionally converted type encoding from indirect to absptr, which broke std exceptions since pointers to their typeinfo were only assigned at runtime in .data section. In this patch we preserve original encoding so that indirect remains indirect and can be resolved at runtime, and absolute remains absolute. Reviewed By: rafauler, maksfb Differential Revision: https://reviews.llvm.org/D132484
2022-09-08[BOLT] Emit LSDA call sites for all fragmentsFabian Parzefall
For exception handling, LSDA call sites have to be emitted for each fragment individually. With this patch, call sites and respective LSDA symbols are generated and associated with each fragment of their function, such that they can be used by the emitter. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D132052
2022-08-24[BOLT] Allocate FunctionFragment on heapFabian Parzefall
This changes `FunctionFragment` from being used as a temporary proxy object to access basic block ranges to a heap-allocated object that can store fragment-specific information. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D132050
2022-08-24Revert "[BOLT] Allocate FunctionFragment on heap"Fabian Parzefall
This reverts commit 101344af1af82d1633c773b718788eaa813d7f79.
2022-08-24[BOLT] Allocate FunctionFragment on heapFabian Parzefall
This changes `FunctionFragment` from being used as a temporary proxy object to access basic block ranges to a heap-allocated object that can store fragment-specific information. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D132050
2022-08-18[BOLT] Make exception handling fragment awareFabian Parzefall
This adds basic fragment awareness in the exception handling passes and generates the necessary symbols for fragments. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D130520
2022-08-06[bolt] silence unused variables warningsThorsten Schütt
2022-07-16[BOLT] Add function layout classFabian Parzefall
This patch adds a dedicated class to keep track of each function's layout. It also lays the groundwork for splitting functions into multiple fragments (as opposed to a strict hot/cold split). Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D129518
2022-07-14[BOLT] Support split landing padHuan Nguyen
We previously support split jump table, where some jump table entries target different fragments of same function. In this fix, we provide support for another type of intra-indirect transfer: landing pad. When C++ exception handling is used, compiler emits .gcc_except_table that describes the location of catch block (landing pad) for specific range that potentially invokes a throw(). Normally landing pads reside in the function, but with -fsplit-machine-functions, landing pads can be moved to another fragment. The intuition is, landing pads are rarely executed, so compiler can move them to .cold section. This update will mark all fragments that have landing pad to another fragment as non-simple, and later propagate non-simple to all related fragments. This update also includes one manual test case: split-landing-pad.s Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D128561
2022-06-23[BOLT][NFC] Use range-based STL wrappersAmir Ayupov
Replace `std::` algorithms taking begin/end iterators with `llvm::` counterparts accepting ranges. Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D128154
2022-06-09[BOLT][AArch64] Handle data at the beginning of a function when ↵Denis Revunov
disassembling and building CFG. This patch adds getFirstInstructionOffset method for BinaryFunction which is used to properly handle cases where data is at zero offset in a function. The main change is that we add basic block at first instruction offset when disassembling, which prevents assertion failures in buildCFG. Reviewed By: yota9, rafauler Differential Revision: https://reviews.llvm.org/D127111
2022-06-05[bolt] Remove unneeded cl::ZeroOrMore for cl::opt optionsFangrui Song
2022-02-15Cleanup LLVMDWARFDebugInfoserge-sans-paille
As usual with that header cleanup series, some implicit dependencies now need to be explicit: llvm/DebugInfo/DWARF/DWARFContext.h no longer includes: - "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" - "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" - "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" - "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" - "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" - "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" - "llvm/DebugInfo/DWARF/DWARFDebugMacro.h" - "llvm/DebugInfo/DWARF/DWARFGdbIndex.h" - "llvm/DebugInfo/DWARF/DWARFSection.h" - "llvm/DebugInfo/DWARF/DWARFTypeUnit.h" - "llvm/DebugInfo/DWARF/DWARFUnitIndex.h" Plus llvm/Support/Errc.h not included by a bunch of llvm/DebugInfo/DWARF/DWARF*.h files Preprocessed lines to build llvm on my setup: after: 1065629059 before: 1066621848 Which is a great diff! Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119723
2021-12-20[BOLTCore] [NFC] Fix braces usages according to LLVMRafael Auler
Summary: Fix according to Coding Standards doc, section Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements. This set of changes applies to lib Core only. (cherry picked from FBD33240028)
2021-12-21[BOLT][NFC] Fix file-description commentsMaksim Panchenko
Summary: Fix comments at the start of source files. (cherry picked from FBD33274597)
2021-12-14[BOLT][NFC] Reformat with clang-formatMaksim Panchenko
Summary: Selectively apply clang-format to BOLT code base. (cherry picked from FBD33119052)
2021-12-09[BOLT] Refactor BinaryBasicBlock to use ADTMaksim Panchenko
Summary: Refactor members of BinaryBasicBlock. Replace some std containers with ADT equivalents. The size of BinaryBasicBlock on x86-64 Linux is reduced from 232 bytes to 192 bytes. (cherry picked from FBD33081850)
2021-12-08[BOLT] Use more ADT data structures for BinaryFunctionMaksim Panchenko
Summary: Switched members of BinaryFunction to ADT where it was possible and made sense. As a result, the size of BinaryFunction on x86-64 Linux reduced from 1624 bytes to 1448. (cherry picked from FBD32981555)
2021-10-08Rebase: [NFC] Refactor sources to be buildable in shared modeRafael Auler
Summary: Moves source files into separate components, and make explicit component dependency on each other, so LLVM build system knows how to build BOLT in BUILD_SHARED_LIBS=ON. Please use the -c merge.renamelimit=230 git option when rebasing your work on top of this change. To achieve this, we create a new library to hold core IR files (most classes beginning with Binary in their names), a new library to hold Utils, some command line options shared across both RewriteInstance and core IR files, a new library called Rewrite to hold most classes concerned with running top-level functions coordinating the binary rewriting process, and a new library called Profile to hold classes dealing with profile reading and writing. To remove the dependency from BinaryContext into X86-specific classes, we do some refactoring on the BinaryContext constructor to receive a reference to the specific backend directly from RewriteInstance. Then, the dependency on X86 or AArch64-specific classes is transfered to the Rewrite library. We can't have the Core library depend on targets because targets depend on Core (which would create a cycle). Files implementing the entry point of a tool are transferred to the tools/ folder. All header files are transferred to the include/ folder. The src/ folder was renamed to lib/. (cherry picked from FBD32746834)