@@ -117,6 +117,9 @@ pub struct CodegenCx<'gcc, 'tcx> {
117117 /// A counter that is used for generating local symbol names
118118 local_gen_sym_counter : Cell < usize > ,
119119
120+ /// A counter that is used for generating global symbol names
121+ global_gen_sym_counter : Cell < usize > ,
122+
120123 eh_personality : Cell < Option < Function < ' gcc > > > ,
121124 #[ cfg( feature = "master" ) ]
122125 pub rust_try_fn : Cell < Option < ( Type < ' gcc > , Function < ' gcc > ) > > ,
@@ -296,6 +299,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
296299 tcx,
297300 struct_types : Default :: default ( ) ,
298301 local_gen_sym_counter : Cell :: new ( 0 ) ,
302+ global_gen_sym_counter : Cell :: new ( 0 ) ,
299303 eh_personality : Cell :: new ( None ) ,
300304 #[ cfg( feature = "master" ) ]
301305 rust_try_fn : Cell :: new ( None ) ,
@@ -595,6 +599,24 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
595599 name. push_str ( & ( idx as u64 + ALPHANUMERIC_ONLY as u64 ) . to_base ( ALPHANUMERIC_ONLY ) ) ;
596600 name
597601 }
602+
603+ /// Generates a new global symbol name with the given prefix. This symbol name must
604+ /// only be used for definitions with `internal` or `private` linkage.
605+ pub fn generate_global_symbol_name ( & self ) -> String {
606+ let idx = self . global_gen_sym_counter . get ( ) ;
607+ self . global_gen_sym_counter . set ( idx + 1 ) ;
608+
609+ let sym = self . codegen_unit . symbol_name ( ) ;
610+ let prefix = sym. as_str ( ) ;
611+ let mut name = String :: with_capacity ( prefix. len ( ) + 6 ) ;
612+ name. push_str ( prefix) ;
613+ name. push ( '.' ) ;
614+ // Offset the index by the base so that always at least two characters
615+ // are generated. This avoids cases where the suffix is interpreted as
616+ // size by the assembler (for m68k: .b, .w, .l).
617+ name. push_str ( & ( idx as u64 + ALPHANUMERIC_ONLY as u64 ) . to_base ( ALPHANUMERIC_ONLY ) ) ;
618+ name
619+ }
598620}
599621
600622fn to_gcc_tls_mode ( tls_model : TlsModel ) -> gccjit:: TlsModel {
0 commit comments