File tree 3 files changed +30
-2
lines changed
librustc_codegen_llvm/back
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -605,6 +605,13 @@ fn run_pass_manager(cgcx: &CodegenContext,
605
605
}
606
606
} ) ;
607
607
608
+ // We always generate bitcode through ThinLTOBuffers,
609
+ // which do not support anonymous globals
610
+ if config. bitcode_needed ( ) {
611
+ let pass = llvm:: LLVMRustFindAndCreatePass ( "name-anon-globals\0 " . as_ptr ( ) as * const _ ) ;
612
+ llvm:: LLVMRustAddPass ( pm, pass. unwrap ( ) ) ;
613
+ }
614
+
608
615
if config. verify_llvm_ir {
609
616
let pass = llvm:: LLVMRustFindAndCreatePass ( "verify\0 " . as_ptr ( ) as * const _ ) ;
610
617
llvm:: LLVMRustAddPass ( pm, pass. unwrap ( ) ) ;
Original file line number Diff line number Diff line change @@ -337,6 +337,11 @@ impl ModuleConfig {
337
337
self . merge_functions = sess. opts . optimize == config:: OptLevel :: Default ||
338
338
sess. opts . optimize == config:: OptLevel :: Aggressive ;
339
339
}
340
+
341
+ pub fn bitcode_needed ( & self ) -> bool {
342
+ self . emit_bc || self . obj_is_bitcode
343
+ || self . emit_bc_compressed || self . embed_bitcode
344
+ }
340
345
}
341
346
342
347
/// Assembler name and command used by codegen when no_integrated_as is enabled
@@ -564,8 +569,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
564
569
// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
565
570
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
566
571
// we'll get errors in LLVM.
567
- let using_thin_buffers = config. emit_bc || config. obj_is_bitcode
568
- || config. emit_bc_compressed || config. embed_bitcode ;
572
+ let using_thin_buffers = config. bitcode_needed ( ) ;
569
573
let mut have_name_anon_globals_pass = false ;
570
574
if !config. no_prepopulate_passes {
571
575
llvm:: LLVMRustAddAnalysisPasses ( tm, fpm, llmod) ;
Original file line number Diff line number Diff line change
1
+ // compile-pass
2
+
3
+ #![ crate_type = "lib" ]
4
+ #![ feature( linkage) ]
5
+
6
+ // MergeFunctions will merge these via an anonymous internal
7
+ // backing function, which must be named if ThinLTO buffers are used
8
+
9
+ #[ linkage = "weak" ]
10
+ pub fn fn1 ( a : u32 , b : u32 , c : u32 ) -> u32 {
11
+ a + b + c
12
+ }
13
+
14
+ #[ linkage = "weak" ]
15
+ pub fn fn2 ( a : u32 , b : u32 , c : u32 ) -> u32 {
16
+ a + b + c
17
+ }
You can’t perform that action at this time.
0 commit comments