@@ -21,7 +21,7 @@ use std::fs::{self, File};
21
21
use std:: path:: { Path , PathBuf } ;
22
22
use std:: sync:: Arc ;
23
23
24
- use gccjit:: { Context , OutputKind } ;
24
+ use gccjit:: { Context , FnAttribute , FunctionType , GlobalKind , OutputKind } ;
25
25
use object:: read:: archive:: ArchiveFile ;
26
26
use rustc_codegen_ssa:: back:: lto:: { LtoModuleCodegen , SerializedModule , ThinModule , ThinShared } ;
27
27
use rustc_codegen_ssa:: back:: symbol_export;
@@ -178,8 +178,6 @@ pub(crate) fn run_fat(
178
178
let dcx = cgcx. create_dcx ( ) ;
179
179
let dcx = dcx. handle ( ) ;
180
180
let lto_data = prepare_lto ( cgcx, dcx) ?;
181
- let symbols_below_threshold =
182
- lto_data. symbols_below_threshold . iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
183
181
fat_lto (
184
182
cgcx,
185
183
dcx,
@@ -315,11 +313,28 @@ fn fat_lto(
315
313
}
316
314
save_temp_bitcode ( cgcx, & module, "lto.input" ) ;
317
315
316
+ let int_type = module. module_llvm . context . new_type :: < i32 > ( ) ;
318
317
for symbol in symbols_below_threshold {
319
- println ! ( "Internalize {}" , symbol) ;
318
+ println ! ( "*** Keeping symbol: {}" , symbol) ;
319
+ module. module_llvm . context . new_global ( None , GlobalKind :: Imported , int_type, symbol) ;
320
320
// TODO: Create a function that is always_inline and that calls the symbol here (e.g.
321
321
// main)?
322
322
}
323
+ let void_type = module. module_llvm . context . new_type :: < ( ) > ( ) ;
324
+ let main_func = module. module_llvm . context . new_function ( None , FunctionType :: Extern , void_type, & [ ] , "main" , false ) ;
325
+ main_func. add_attribute ( FnAttribute :: Used ) ;
326
+
327
+ // NOTE: look at the code from 64b30d344ce54f8ee496cb3590b4c7cf3cb30447 to see previous
328
+ // attemps.
329
+ let func = module. module_llvm . context . new_function ( None , FunctionType :: Exported , void_type, & [ ] , "__my_call_main" , false ) ;
330
+ func. add_attribute ( FnAttribute :: AlwaysInline ) ;
331
+ func. add_attribute ( FnAttribute :: Inline ) ;
332
+ func. add_attribute ( FnAttribute :: Used ) ;
333
+ let block = func. new_block ( "start" ) ;
334
+ let call = module. module_llvm . context . new_call ( None , main_func, & [ ] ) ;
335
+ block. add_eval ( None , call) ;
336
+ block. end_with_void_return ( None ) ;
337
+
323
338
// Internalize everything below threshold to help strip out more modules and such.
324
339
/*unsafe {
325
340
let ptr = symbols_below_threshold.as_ptr();
0 commit comments