Skip to content
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

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

dongjianqiang2
Copy link
Contributor

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

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
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 25, 2024

@llvm/pr-subscribers-llvm-transforms

Author: dong jianqiang (dongjianqiang2)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/86497.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Utils/CodeExtractor.h (+1-1)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-2)
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)) {

Copy link

✅ With the latest revision this PR passed the Python code formatter.

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@adrian-prantl adrian-prantl left a 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.

@hstk30-hw hstk30-hw merged commit ce73b16 into llvm:main Mar 26, 2024
6 checks passed
@hstk30-hw
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Clang][IPO] Binary inconsistency occurs when compiling for multiple times in ASLR self-enabled Clang.
4 participants