@@ -30,7 +30,7 @@ use tracing::debug;
3030
3131use self :: metadata:: { UNKNOWN_COLUMN_NUMBER , UNKNOWN_LINE_NUMBER , file_metadata, type_di_node} ;
3232use self :: namespace:: mangled_name_of_instance;
33- use self :: utils:: { DIB , create_DIArray, debug_context , is_node_local_to_unit} ;
33+ use self :: utils:: { DIB , create_DIArray, is_node_local_to_unit} ;
3434use crate :: builder:: Builder ;
3535use crate :: common:: { AsCCharPtr , CodegenCx } ;
3636use crate :: llvm;
@@ -131,28 +131,20 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
131131}
132132
133133/// Creates any deferred debug metadata nodes
134- pub ( crate ) fn finalize ( cx : & mut CodegenCx < ' _ , ' _ > ) {
135- if cx. dbg_cx . is_none ( ) {
136- return ;
137- }
138-
139- debug ! ( "finalize" ) ;
140-
141- if gdb:: needs_gdb_debug_scripts_section ( cx) {
142- // Add a .debug_gdb_scripts section to this compile-unit. This will
143- // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
144- // which activates the Rust pretty printers for binary this section is
145- // contained in.
146- let section_var = gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
134+ pub ( crate ) fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
135+ if let Some ( dbg_cx) = & cx. dbg_cx {
136+ debug ! ( "finalize" ) ;
137+
138+ if gdb:: needs_gdb_debug_scripts_section ( cx) {
139+ // Add a .debug_gdb_scripts section to this compile-unit. This will
140+ // cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
141+ // which activates the Rust pretty printers for binary this section is
142+ // contained in.
143+ gdb:: get_or_insert_gdb_debug_scripts_section_global ( cx) ;
144+ }
147145
148- // Make sure that the linker doesn't optimize the global away. Adding
149- // it to `llvm.used` has the advantage that it works even in no_std
150- // binaries, where we don't have a main shim and thus don't emit a
151- // volatile load to preserve the global.
152- cx. add_used_global ( section_var) ;
146+ dbg_cx. finalize ( cx. sess ( ) ) ;
153147 }
154-
155- debug_context ( cx) . finalize ( cx. sess ( ) ) ;
156148}
157149
158150impl < ' ll > Builder < ' _ , ' ll , ' _ > {
@@ -622,7 +614,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
622614 metadata:: extend_scope_to_file ( self , scope_metadata, file)
623615 }
624616
625- fn debuginfo_finalize ( & mut self ) {
617+ fn debuginfo_finalize ( & self ) {
626618 finalize ( self )
627619 }
628620
0 commit comments