[llvm] fcd07f8 - [JITLink] Fix splitBlock if there are symbols span across the boundary
Steven Wu via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 15 13:55:39 PST 2021
Author: Steven Wu
Date: 2021-11-15T13:55:21-08:00
New Revision: fcd07f810781c1754c2e7e9641fd18b95fa1368c
URL: https://github.com/llvm/llvm-project/commit/fcd07f810781c1754c2e7e9641fd18b95fa1368c
DIFF: https://github.com/llvm/llvm-project/commit/fcd07f810781c1754c2e7e9641fd18b95fa1368c.diff
LOG: [JITLink] Fix splitBlock if there are symbols span across the boundary
Fix `splitBlock` so that it can handle the case when the block being
split has symbols span across the split boundary. This is an error
case in general but for EHFrame splitting on macho platforms, there is an
anonymous symbol that marks the entire block. Current implementation
will leave a symbol that is out of bound of the underlying block. Fix
the problem by dropping such symbols when the block is split.
Reviewed By: lhames
Differential Revision: https://reviews.llvm.org/D113912
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 5c4210ddcdba6..51dcc1c35fad4 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -213,7 +213,12 @@ Block &LinkGraph::splitBlock(Block &B, size_t SplitIndex,
// Transfer all symbols with offset less than SplitIndex to NewBlock.
while (!BlockSymbols.empty() &&
BlockSymbols.back()->getOffset() < SplitIndex) {
- BlockSymbols.back()->setBlock(NewBlock);
+ auto *Sym = BlockSymbols.back();
+ // If the symbol extends beyond the split, update the size to be within
+ // the new block.
+ if (Sym->getOffset() + Sym->getSize() > SplitIndex)
+ Sym->setSize(SplitIndex - Sym->getOffset());
+ Sym->setBlock(NewBlock);
BlockSymbols.pop_back();
}
diff --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index 4851f642e85a5..3cc6a8ad0fe65 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -493,6 +493,9 @@ TEST(LinkGraphTest, SplitBlock) {
false, false);
auto &S4 = G.addDefinedSymbol(B1, 12, "S4", 4, Linkage::Strong,
Scope::Default, false, false);
+ // Add a symbol that extends beyond the split.
+ auto &S5 = G.addDefinedSymbol(B1, 0, "S5", 16, Linkage::Strong,
+ Scope::Default, false, false);
// Add an extra block, EB, and target symbols, and use these to add edges
// from B1 to EB.
@@ -538,6 +541,11 @@ TEST(LinkGraphTest, SplitBlock) {
EXPECT_EQ(&S4.getBlock(), &B1);
EXPECT_EQ(S4.getOffset(), 4U);
+ EXPECT_EQ(&S5.getBlock(), &B2);
+ EXPECT_EQ(S5.getOffset(), 0U);
+ // Size shrinks to fit.
+ EXPECT_EQ(S5.getSize(), 8U);
+
// Check that edges in B1 have been transferred as expected:
// Both blocks should now have two edges each at offsets 0 and 4.
EXPECT_EQ(llvm::size(B1.edges()), 2);
More information about the llvm-commits
mailing list