
Re-enables compact-unwind support in JITLink, which was reverted in b04847b427d due to buildbot failures. The underlying cause for the failures on the buildbots was the lack of compact-unwind registration support on older Darwin OSes. Since the CompactUnwindManager pass now removes eh-frames by default we were left with unwind-info that could not be registered. On x86-64, where eh-frame info is produced by default the solution is to fall back to using eh-frames. On arm64 we simply can't support exceptions on older OSes. This patch updates the EHFrameRegistrationPlugin to remove the compact-unwind section (__LD,__compact_unwind) when installed, forcing use of eh-frames when the EHFrameRegistrationPlugin is used. In LLJIT, the EHFrameRegistrationPlugin continues to be used for all non-Darwin platform, and will be added on Darwin platforms when the a CompactUnwindRegistrationPlugin instance can't be created (e.g. due to missing support for compact-unwind info registration). The lit.cfg.py script is updated to check whether the host OSes default unwind info supports JIT registration, allowing tests to be disabled for older Darwin OSes on arm64.
104 lines
3.5 KiB
C++
104 lines
3.5 KiB
C++
//=------- CompactUnwindSupport.cpp - Compact Unwind format support -------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Compact Unwind support.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "CompactUnwindSupport.h"
|
|
|
|
#include "llvm/ADT/Sequence.h"
|
|
|
|
#define DEBUG_TYPE "jitlink"
|
|
|
|
namespace llvm {
|
|
namespace jitlink {
|
|
|
|
Error splitCompactUnwindBlocks(LinkGraph &G, Section &CompactUnwindSection,
|
|
size_t RecordSize) {
|
|
|
|
std::vector<Block *> OriginalBlocks(CompactUnwindSection.blocks().begin(),
|
|
CompactUnwindSection.blocks().end());
|
|
LLVM_DEBUG({
|
|
dbgs() << "In " << G.getName() << " splitting compact unwind section "
|
|
<< CompactUnwindSection.getName() << " containing "
|
|
<< OriginalBlocks.size() << " initial blocks...\n";
|
|
});
|
|
|
|
while (!OriginalBlocks.empty()) {
|
|
auto *B = OriginalBlocks.back();
|
|
OriginalBlocks.pop_back();
|
|
|
|
if (B->getSize() == 0) {
|
|
LLVM_DEBUG({
|
|
dbgs() << " Skipping empty block at "
|
|
<< formatv("{0:x16}", B->getAddress()) << "\n";
|
|
});
|
|
continue;
|
|
}
|
|
|
|
unsigned NumBlocks = B->getSize() / RecordSize;
|
|
|
|
LLVM_DEBUG({
|
|
dbgs() << " Splitting block at " << formatv("{0:x16}", B->getAddress())
|
|
<< " into " << NumBlocks << " compact unwind record(s)\n";
|
|
});
|
|
|
|
if (B->getSize() % RecordSize)
|
|
return make_error<JITLinkError>(
|
|
"Error splitting compact unwind record in " + G.getName() +
|
|
": block at " + formatv("{0:x}", B->getAddress()) + " has size " +
|
|
formatv("{0:x}", B->getSize()) +
|
|
" (not a multiple of CU record size of " +
|
|
formatv("{0:x}", RecordSize) + ")");
|
|
|
|
auto Blocks =
|
|
G.splitBlock(*B, map_range(seq(1U, NumBlocks), [=](Edge::OffsetT Idx) {
|
|
return Idx * RecordSize;
|
|
}));
|
|
|
|
for (auto *CURec : Blocks) {
|
|
bool AddedKeepAlive = false;
|
|
|
|
for (auto &E : CURec->edges()) {
|
|
if (E.getOffset() == 0) {
|
|
LLVM_DEBUG({
|
|
dbgs() << " Updating compact unwind record at "
|
|
<< CURec->getAddress() << " to point to "
|
|
<< (E.getTarget().hasName() ? *E.getTarget().getName()
|
|
: StringRef())
|
|
<< " (at " << E.getTarget().getAddress() << ")\n";
|
|
});
|
|
|
|
if (E.getTarget().isExternal())
|
|
return make_error<JITLinkError>(
|
|
"Error adding keep-alive edge for compact unwind record at " +
|
|
formatv("{0:x}", CURec->getAddress()) + ": target " +
|
|
*E.getTarget().getName() + " is an external symbol");
|
|
auto &TgtBlock = E.getTarget().getBlock();
|
|
auto &CURecSym =
|
|
G.addAnonymousSymbol(*CURec, 0, RecordSize, false, false);
|
|
TgtBlock.addEdge(Edge::KeepAlive, 0, CURecSym, 0);
|
|
AddedKeepAlive = true;
|
|
}
|
|
}
|
|
|
|
if (!AddedKeepAlive)
|
|
return make_error<JITLinkError>(
|
|
"Error adding keep-alive edge for compact unwind record at " +
|
|
formatv("{0:x}", CURec->getAddress()) +
|
|
": no outgoing target edge at offset 0");
|
|
}
|
|
}
|
|
|
|
return Error::success();
|
|
}
|
|
|
|
} // end namespace jitlink
|
|
} // end namespace llvm
|