|
9 | 9 | #include "llvm/ExecutionEngine/Orc/MachOPlatform.h" |
10 | 10 |
|
11 | 11 | #include "llvm/BinaryFormat/MachO.h" |
| 12 | +#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h" |
12 | 13 | #include "llvm/ExecutionEngine/JITLink/MachO.h" |
13 | 14 | #include "llvm/ExecutionEngine/JITLink/aarch64.h" |
14 | 15 | #include "llvm/ExecutionEngine/JITLink/x86_64.h" |
@@ -1257,58 +1258,37 @@ MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo( |
1257 | 1258 | // that section points to to the CodeBlocks vector. |
1258 | 1259 | SmallVector<Block *> CodeBlocks; |
1259 | 1260 | auto ScanUnwindInfoSection = [&](Section &Sec, ExecutorAddrRange &SecRange, |
1260 | | - auto GetCodeForRecord) { |
| 1261 | + auto AddCodeBlocks) { |
1261 | 1262 | if (Sec.blocks().empty()) |
1262 | 1263 | return; |
1263 | 1264 | SecRange = (*Sec.blocks().begin())->getRange(); |
1264 | 1265 | for (auto *B : Sec.blocks()) { |
1265 | 1266 | auto R = B->getRange(); |
1266 | 1267 | SecRange.Start = std::min(SecRange.Start, R.Start); |
1267 | 1268 | SecRange.End = std::max(SecRange.End, R.End); |
1268 | | - if (auto *CodeBlock = GetCodeForRecord(*B)) |
1269 | | - CodeBlocks.push_back(CodeBlock); |
| 1269 | + AddCodeBlocks(*B); |
1270 | 1270 | } |
1271 | 1271 | }; |
1272 | 1272 |
|
1273 | 1273 | if (Section *EHFrameSec = G.findSectionByName(MachOEHFrameSectionName)) { |
1274 | | - ScanUnwindInfoSection( |
1275 | | - *EHFrameSec, US.DwarfSection, [&](Block &B) -> Block * { |
1276 | | - // Filter out CIE, personality, etc. edges. |
1277 | | - SmallVector<Edge *, 4> BEdges; |
1278 | | - for (auto &E : B.edges()) |
1279 | | - BEdges.push_back(&E); |
1280 | | - llvm::sort(BEdges, [](const Edge *LHS, const Edge *RHS) { |
1281 | | - return LHS->getOffset() < RHS->getOffset(); |
1282 | | - }); |
1283 | | - if (BEdges.size() < 2) |
1284 | | - return nullptr; |
1285 | | - auto &TargetBlock = BEdges[1]->getTarget().getBlock(); |
1286 | | -#ifndef NDEBUG |
1287 | | - auto &TargetSection = TargetBlock.getSection(); |
1288 | | - assert(&TargetSection != EHFrameSec && |
1289 | | - (TargetSection.getMemProt() & MemProt::Exec) == |
1290 | | - MemProt::Exec && |
1291 | | - "Invalid eh-frame function target"); |
1292 | | -#endif // NDEBUG |
1293 | | - return &TargetBlock; |
1294 | | - }); |
| 1274 | + ScanUnwindInfoSection(*EHFrameSec, US.DwarfSection, [&](Block &B) { |
| 1275 | + if (auto *Fn = jitlink::EHFrameCFIBlockInspector::FromEdgeScan(B) |
| 1276 | + .getPCBeginEdge()) |
| 1277 | + if (Fn->getTarget().isDefined()) |
| 1278 | + CodeBlocks.push_back(&Fn->getTarget().getBlock()); |
| 1279 | + }); |
1295 | 1280 | } |
1296 | 1281 |
|
1297 | 1282 | if (Section *CUInfoSec = G.findSectionByName(MachOUnwindInfoSectionName)) { |
1298 | 1283 | ScanUnwindInfoSection( |
1299 | | - *CUInfoSec, US.CompactUnwindSection, [&](Block &B) -> Block * { |
1300 | | - // Compact unwind records should just have a keep-alive pointing to |
1301 | | - // the target function. |
1302 | | - assert(B.edges_size() == 1 && |
1303 | | - "unwind-info record should only have one edge"); |
| 1284 | + *CUInfoSec, US.CompactUnwindSection, [&](Block &B) { |
1304 | 1285 | for (auto &E : B.edges()) { |
1305 | 1286 | assert(E.getTarget().isDefined() && |
1306 | 1287 | "unwind-info record edge has external target"); |
1307 | 1288 | assert(E.getKind() == Edge::KeepAlive && |
1308 | 1289 | "unwind-info record has unexpected edge kind"); |
1309 | | - return &E.getTarget().getBlock(); |
| 1290 | + CodeBlocks.push_back(&E.getTarget().getBlock()); |
1310 | 1291 | } |
1311 | | - return nullptr; |
1312 | 1292 | }); |
1313 | 1293 | } |
1314 | 1294 |
|
|
0 commit comments