-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeExtractor] Resolving the Inconsistency of Compiled Binary Files #86497
Conversation
When the compiler enables ALSR by default, binary inconsistency occurs when the extractCodeRegion function is called. The reason is that the sequence of traversing ExitBlocks containers of the SmallPtrSet type is changed due to randomization of BasicBlock pointers. This fixes llvm#86427
@llvm/pr-subscribers-llvm-transforms Author: dong jianqiang (dongjianqiang2) ChangesWhen the compiler enables ALSR by default, binary inconsistency occurs when the extractCodeRegion function is called. The reason is that the sequence of traversing ExitBlocks containers of the SmallPtrSet type is changed due to randomization of BasicBlock pointers. Full diff: https://github.com/llvm/llvm-project/pull/86497.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Utils/CodeExtractor.h b/llvm/include/llvm/Transforms/Utils/CodeExtractor.h
index 27b34ef023db72..333ed6774d6c7e 100644
--- a/llvm/include/llvm/Transforms/Utils/CodeExtractor.h
+++ b/llvm/include/llvm/Transforms/Utils/CodeExtractor.h
@@ -249,7 +249,7 @@ class CodeExtractorAnalysisCache {
Instruction *Addr, BasicBlock *ExitBlock) const;
void severSplitPHINodesOfEntry(BasicBlock *&Header);
- void severSplitPHINodesOfExits(const SmallPtrSetImpl<BasicBlock *> &Exits);
+ void severSplitPHINodesOfExits(const SetVector<BasicBlock *> &Exits);
void splitReturnBlocks();
Function *constructFunction(const ValueSet &inputs,
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 3191751d92e176..6988292ac71561 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -745,7 +745,7 @@ void CodeExtractor::severSplitPHINodesOfEntry(BasicBlock *&Header) {
/// and other with remaining incoming blocks; then first PHIs are placed in
/// outlined region.
void CodeExtractor::severSplitPHINodesOfExits(
- const SmallPtrSetImpl<BasicBlock *> &Exits) {
+ const SetVector<BasicBlock *> &Exits) {
for (BasicBlock *ExitBB : Exits) {
BasicBlock *NewBB = nullptr;
@@ -1751,7 +1751,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
// Calculate the exit blocks for the extracted region and the total exit
// weights for each of those blocks.
DenseMap<BasicBlock *, BlockFrequency> ExitWeights;
- SmallPtrSet<BasicBlock *, 1> ExitBlocks;
+ SetVector<BasicBlock *> ExitBlocks;
for (BasicBlock *Block : Blocks) {
for (BasicBlock *Succ : successors(Block)) {
if (!Blocks.count(Succ)) {
|
✅ With the latest revision this PR passed the Python code formatter. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, we can't iterate over the elements if it affects the output. And this shouldn't even be slower.
https://llvm.org/docs/CodingStandards.html#beware-of-non-determinism-due-to-ordering-of-pointers Say beware of non-determinism! I see we use maybe have same problem. |
When the compiler enables ALSR by default, binary inconsistency occurs when the extractCodeRegion function is called. The reason is that the sequence of traversing ExitBlocks containers of the SmallPtrSet type is changed due to randomization of BasicBlock pointers.
This fixes #86427