@@ -190,63 +190,8 @@ pub mod rustc_trans {
190190}
191191
192192fn load_backend_from_dylib ( sess : & Session , backend_name : & str ) -> Box < TransCrate > {
193- use std:: sync:: mpsc;
194193 use std:: path:: Path ;
195- use syntax:: symbol:: Symbol ;
196- use rustc:: session:: config:: OutputFilenames ;
197- use rustc:: ty:: TyCtxt ;
198- use rustc:: ty:: maps:: Providers ;
199- use rustc:: middle:: cstore:: MetadataLoader ;
200- use rustc:: dep_graph:: DepGraph ;
201194 use rustc_metadata:: dynamic_lib:: DynamicLibrary ;
202- /// This prevents the dylib from being unloaded when there is still a TransCrate open
203- struct ExternTransCrate {
204- _lib : DynamicLibrary ,
205- trans : Box < TransCrate > ,
206- }
207-
208- impl Drop for ExternTransCrate {
209- fn drop ( & mut self ) {
210- // Make sure trans gets dropped before _lib as bad things happen otherwise
211- self . trans = Box :: new ( :: rustc_trans_utils:: trans_crate:: DummyTransCrate )
212- }
213- }
214-
215- impl TransCrate for ExternTransCrate {
216- fn print ( & self , req : PrintRequest , sess : & Session ) {
217- self . trans . print ( req, sess) ;
218- }
219- fn target_features ( & self , sess : & Session ) -> Vec < Symbol > {
220- self . trans . target_features ( ( sess) )
221- }
222-
223- fn metadata_loader ( & self ) -> Box < MetadataLoader > {
224- self . trans . metadata_loader ( )
225- }
226- fn provide ( & self , providers : & mut Providers ) {
227- self . trans . provide ( providers)
228- }
229- fn provide_extern ( & self , providers : & mut Providers ) {
230- self . trans . provide_extern ( providers)
231- }
232- fn trans_crate < ' a , ' tcx > (
233- & self ,
234- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
235- rx : mpsc:: Receiver < Box < Any + Send > >
236- ) -> Box < Any > {
237- self . trans . trans_crate ( tcx, rx)
238- }
239-
240- fn join_trans_and_link (
241- & self ,
242- trans : Box < Any > ,
243- sess : & Session ,
244- dep_graph : & DepGraph ,
245- outputs : & OutputFilenames ,
246- ) -> Result < ( ) , CompileIncomplete > {
247- self . trans . join_trans_and_link ( trans, sess, dep_graph, outputs)
248- }
249- }
250195
251196 match DynamicLibrary :: open ( Some ( Path :: new ( backend_name) ) ) {
252197 Ok ( lib) => {
@@ -260,10 +205,8 @@ fn load_backend_from_dylib(sess: &Session, backend_name: &str) -> Box<TransCrate
260205 } ;
261206 __rustc_codegen_backend ( sess)
262207 } ;
263- Box :: new ( ExternTransCrate {
264- _lib : lib,
265- trans
266- } )
208+ :: std:: mem:: forget ( lib) ;
209+ trans
267210 }
268211 }
269212 Err ( err) => {
0 commit comments