@@ -698,18 +698,26 @@ static Expected<orc::ThreadSafeModule> validateExternRelocations(orc::ThreadSafe
698
698
auto Err = TSM.withModuleDo ([isIntrinsicFunction](Module &M) JL_NOTSAFEPOINT {
699
699
Error Err = Error::success ();
700
700
for (auto &GO : make_early_inc_range (M.global_objects ())) {
701
- if (GO.isDeclaration ()) {
702
- if (GO.use_empty ())
703
- GO.eraseFromParent ();
704
- else if (!isIntrinsicFunction (GO) &&
705
- !jl_ExecutionEngine->findUnmangledSymbol (GO.getName ()) &&
706
- !SectionMemoryManager::getSymbolAddressInProcess (
701
+ if (!GO.isDeclarationForLinker ())
702
+ continue ;
703
+ if (GO.use_empty ()) {
704
+ GO.eraseFromParent ();
705
+ continue ;
706
+ }
707
+ if (isIntrinsicFunction (GO))
708
+ continue ;
709
+ auto sym = jl_ExecutionEngine->findUnmangledSymbol (GO.getName ());
710
+ if (sym)
711
+ continue ;
712
+ // TODO have we ever run into this check? It's been guaranteed to not
713
+ // fire in an assert build, since previously LLVM would abort due to
714
+ // not handling the error if we didn't find the unmangled symbol
715
+ if (SectionMemoryManager::getSymbolAddressInProcess (
707
716
jl_ExecutionEngine->getMangledName (GO.getName ()))) {
708
- Err = joinErrors (std::move (Err), make_error<StringError>(
709
- " Symbol \" " + GO.getName ().str () + " \" not found" ,
710
- inconvertibleErrorCode ()));
711
- }
717
+ consumeError (sym.takeError ());
718
+ continue ;
712
719
}
720
+ Err = joinErrors (std::move (Err), sym.takeError ());
713
721
}
714
722
return Err;
715
723
});
@@ -750,6 +758,18 @@ static Expected<orc::ThreadSafeModule> selectOptLevel(orc::ThreadSafeModule TSM,
750
758
return std::move (TSM);
751
759
}
752
760
761
+ static void recordDebugTSM (orc::MaterializationResponsibility &, orc::ThreadSafeModule TSM) JL_NOTSAFEPOINT {
762
+ auto ptr = TSM.withModuleDo ([](Module &M) JL_NOTSAFEPOINT {
763
+ auto md = M.getModuleFlag (" julia.__jit_debug_tsm_addr" );
764
+ if (!md)
765
+ return static_cast <orc::ThreadSafeModule *>(nullptr );
766
+ return reinterpret_cast <orc::ThreadSafeModule *>(cast<ConstantInt>(cast<ConstantAsMetadata>(md)->getValue ())->getZExtValue ());
767
+ });
768
+ if (ptr) {
769
+ *ptr = std::move (TSM);
770
+ }
771
+ }
772
+
753
773
void jl_register_jit_object (const object::ObjectFile &debugObj,
754
774
std::function<uint64_t (const StringRef &)> getLoadAddress,
755
775
std::function<void *(void *)> lookupWriteAddress);
@@ -1287,7 +1307,6 @@ namespace {
1287
1307
{
1288
1308
JL_TIMING (LLVM_JIT, JIT_Opt);
1289
1309
// Run the optimization
1290
- assert (!verifyLLVMIR (M));
1291
1310
(****PMs[PoolIdx]).run (M);
1292
1311
assert (!verifyLLVMIR (M));
1293
1312
}
@@ -1506,6 +1525,7 @@ JuliaOJIT::JuliaOJIT()
1506
1525
registerRTDyldJITObject (Object, LO, MemMgr);
1507
1526
});
1508
1527
#endif
1528
+ CompileLayer.setNotifyCompiled (recordDebugTSM);
1509
1529
1510
1530
std::string ErrorStr;
1511
1531
@@ -1616,22 +1636,46 @@ void JuliaOJIT::addModule(orc::ThreadSafeModule TSM)
1616
1636
JL_TIMING (LLVM_JIT, JIT_Total);
1617
1637
++ModulesAdded;
1618
1638
orc::SymbolLookupSet NewExports;
1639
+ orc::ThreadSafeModule CurrentlyCompiling;
1619
1640
TSM.withModuleDo ([&](Module &M) JL_NOTSAFEPOINT {
1620
1641
for (auto &F : M.global_values ()) {
1621
1642
if (!F.isDeclaration () && F.getLinkage () == GlobalValue::ExternalLinkage) {
1622
1643
auto Name = ES.intern (getMangledName (F.getName ()));
1623
1644
NewExports.add (std::move (Name));
1624
1645
}
1625
1646
}
1647
+ assert (!verifyLLVMIR (M));
1648
+ auto jit_debug_tsm_addr = ConstantInt::get (Type::getIntNTy (M.getContext (), sizeof (void *) * CHAR_BIT), (uintptr_t ) &CurrentlyCompiling);
1649
+ M.addModuleFlag (Module::Error, " julia.__jit_debug_tsm_addr" , jit_debug_tsm_addr);
1626
1650
});
1627
1651
1628
1652
// TODO: what is the performance characteristics of this?
1629
- cantFail (OptSelLayer.add (JD, std::move (TSM)));
1653
+ auto Err = DepsVerifyLayer.add (JD, std::move (TSM));
1654
+ if (Err) {
1655
+ ES.reportError (std::move (Err));
1656
+ errs () << " Failed to add module to JIT!\n " ;
1657
+ if (CurrentlyCompiling) {
1658
+ CurrentlyCompiling.withModuleDo ([](Module &M) JL_NOTSAFEPOINT { errs () << " Dumping failing module\n " << M << " \n " ; });
1659
+ } else {
1660
+ errs () << " Module unavailable to be printed\n " ;
1661
+ }
1662
+ abort ();
1663
+ }
1630
1664
// force eager compilation (for now), due to memory management specifics
1631
1665
// (can't handle compilation recursion)
1632
- for (auto &sym : cantFail (ES.lookup ({{&JD, orc::JITDylibLookupFlags::MatchExportedSymbolsOnly}}, NewExports))) {
1633
- assert (sym.second );
1634
- (void ) sym;
1666
+ auto Lookups = ES.lookup ({{&JD, orc::JITDylibLookupFlags::MatchExportedSymbolsOnly}}, NewExports);
1667
+ if (!Lookups) {
1668
+ ES.reportError (Lookups.takeError ());
1669
+ errs () << " Failed to lookup symbols in module!" ;
1670
+ if (CurrentlyCompiling) {
1671
+ CurrentlyCompiling.withModuleDo ([](Module &M) JL_NOTSAFEPOINT { errs () << " Dumping failing module\n " << M << " \n " ; });
1672
+ } else {
1673
+ errs () << " Module unavailable to be printed\n " ;
1674
+ }
1675
+ }
1676
+ for (auto &Sym : *Lookups) {
1677
+ assert (Sym.second );
1678
+ (void ) Sym;
1635
1679
}
1636
1680
}
1637
1681
0 commit comments