Skip to content

Commit

Permalink
[JITLink] Fix splitBlock if there are symbols span across the boundary
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cachemeifyoucan committed Nov 15, 2021
1 parent 193c40e commit fcd07f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
Expand Up @@ -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();
}

Expand Down
8 changes: 8 additions & 0 deletions llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fcd07f8

Please sign in to comment.