Skip to content

Commit fcd07f8

Browse files
[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
1 parent 193c40e commit fcd07f8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ Block &LinkGraph::splitBlock(Block &B, size_t SplitIndex,
213213
// Transfer all symbols with offset less than SplitIndex to NewBlock.
214214
while (!BlockSymbols.empty() &&
215215
BlockSymbols.back()->getOffset() < SplitIndex) {
216-
BlockSymbols.back()->setBlock(NewBlock);
216+
auto *Sym = BlockSymbols.back();
217+
// If the symbol extends beyond the split, update the size to be within
218+
// the new block.
219+
if (Sym->getOffset() + Sym->getSize() > SplitIndex)
220+
Sym->setSize(SplitIndex - Sym->getOffset());
221+
Sym->setBlock(NewBlock);
217222
BlockSymbols.pop_back();
218223
}
219224

llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ TEST(LinkGraphTest, SplitBlock) {
493493
false, false);
494494
auto &S4 = G.addDefinedSymbol(B1, 12, "S4", 4, Linkage::Strong,
495495
Scope::Default, false, false);
496+
// Add a symbol that extends beyond the split.
497+
auto &S5 = G.addDefinedSymbol(B1, 0, "S5", 16, Linkage::Strong,
498+
Scope::Default, false, false);
496499

497500
// Add an extra block, EB, and target symbols, and use these to add edges
498501
// from B1 to EB.
@@ -538,6 +541,11 @@ TEST(LinkGraphTest, SplitBlock) {
538541
EXPECT_EQ(&S4.getBlock(), &B1);
539542
EXPECT_EQ(S4.getOffset(), 4U);
540543

544+
EXPECT_EQ(&S5.getBlock(), &B2);
545+
EXPECT_EQ(S5.getOffset(), 0U);
546+
// Size shrinks to fit.
547+
EXPECT_EQ(S5.getSize(), 8U);
548+
541549
// Check that edges in B1 have been transferred as expected:
542550
// Both blocks should now have two edges each at offsets 0 and 4.
543551
EXPECT_EQ(llvm::size(B1.edges()), 2);

0 commit comments

Comments
 (0)