@@ -1918,16 +1918,14 @@ ExecutionSession::~ExecutionSession() {
1918
1918
Error ExecutionSession::endSession () {
1919
1919
LLVM_DEBUG (dbgs () << " Ending ExecutionSession " << this << " \n " );
1920
1920
1921
- std::vector<JITDylibSP> JITDylibsToClose = runSessionLocked ([&] {
1921
+ auto JDsToRemove = runSessionLocked ([&] {
1922
1922
SessionOpen = false ;
1923
- return std::move ( JDs) ;
1923
+ return JDs;
1924
1924
});
1925
1925
1926
- // TODO: notifiy platform? run static deinits?
1926
+ std::reverse (JDsToRemove. begin (), JDsToRemove. end ());
1927
1927
1928
- Error Err = Error::success ();
1929
- for (auto &JD : reverse (JITDylibsToClose))
1930
- Err = joinErrors (std::move (Err), JD->clear ());
1928
+ auto Err = removeJITDylibs (std::move (JDsToRemove));
1931
1929
1932
1930
Err = joinErrors (std::move (Err), EPC->disconnect ());
1933
1931
@@ -1977,42 +1975,45 @@ Expected<JITDylib &> ExecutionSession::createJITDylib(std::string Name) {
1977
1975
return JD;
1978
1976
}
1979
1977
1980
- Error ExecutionSession::removeJITDylib (JITDylib &JD) {
1981
- // Keep JD alive throughout this routine, even if all other references
1982
- // have been dropped.
1983
- JITDylibSP JDKeepAlive = &JD;
1978
+ Error ExecutionSession::removeJITDylibs (std::vector<JITDylibSP> JDsToRemove) {
1984
1979
1985
1980
// Set JD to 'Closing' state and remove JD from the ExecutionSession.
1986
1981
runSessionLocked ([&] {
1987
- assert (JD.State == JITDylib::Open && " JD already closed" );
1988
- JD.State = JITDylib::Closing;
1989
- auto I = llvm::find (JDs, &JD);
1990
- assert (I != JDs.end () && " JD does not appear in session JDs" );
1991
- JDs.erase (I);
1982
+ for (auto &JD : JDsToRemove) {
1983
+ assert (JD->State == JITDylib::Open && " JD already closed" );
1984
+ JD->State = JITDylib::Closing;
1985
+ auto I = llvm::find (JDs, JD);
1986
+ assert (I != JDs.end () && " JD does not appear in session JDs" );
1987
+ JDs.erase (I);
1988
+ }
1992
1989
});
1993
1990
1994
- // Clear the JITDylib. Hold on to any error while we clean up the
1995
- // JITDylib members below.
1996
- auto Err = JD.clear ();
1997
-
1998
- // Notify the platform of the teardown.
1999
- if (P)
2000
- Err = joinErrors (std::move (Err), P->teardownJITDylib (JD));
1991
+ // Clear JITDylibs and notify the platform.
1992
+ Error Err = Error::success ();
1993
+ for (auto JD : JDsToRemove) {
1994
+ dbgs () << " ---REMOVING--- " << JD->getName () << " \n " ;
1995
+ Err = joinErrors (std::move (Err), JD->clear ());
1996
+ if (P)
1997
+ Err = joinErrors (std::move (Err), P->teardownJITDylib (*JD));
1998
+ }
2001
1999
2002
2000
// Set JD to closed state. Clear remaining data structures.
2003
2001
runSessionLocked ([&] {
2004
- assert (JD.State == JITDylib::Closing && " JD should be closing" );
2005
- JD.State = JITDylib::Closed;
2006
- assert (JD.Symbols .empty () && " JD.Symbols is not empty after clear" );
2007
- assert (JD.UnmaterializedInfos .empty () &&
2008
- " JD.UnmaterializedInfos is not empty after clear" );
2009
- assert (JD.MaterializingInfos .empty () &&
2010
- " JD.MaterializingInfos is not empty after clear" );
2011
- assert (JD.TrackerSymbols .empty () &&
2012
- " TrackerSymbols is not empty after clear" );
2013
- JD.DefGenerators .clear ();
2014
- JD.LinkOrder .clear ();
2002
+ for (auto &JD : JDsToRemove) {
2003
+ assert (JD->State == JITDylib::Closing && " JD should be closing" );
2004
+ JD->State = JITDylib::Closed;
2005
+ assert (JD->Symbols .empty () && " JD.Symbols is not empty after clear" );
2006
+ assert (JD->UnmaterializedInfos .empty () &&
2007
+ " JD.UnmaterializedInfos is not empty after clear" );
2008
+ assert (JD->MaterializingInfos .empty () &&
2009
+ " JD.MaterializingInfos is not empty after clear" );
2010
+ assert (JD->TrackerSymbols .empty () &&
2011
+ " TrackerSymbols is not empty after clear" );
2012
+ JD->DefGenerators .clear ();
2013
+ JD->LinkOrder .clear ();
2014
+ }
2015
2015
});
2016
+
2016
2017
return Err;
2017
2018
}
2018
2019
0 commit comments