From e9e1630cca6a788a5b9efed3df5e9a59506d54f2 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Sat, 10 Feb 2024 18:27:34 +0100 Subject: [PATCH] di: Make the decision about DI in one if-else statement Instead of doing that in two random places, keep just one if-else statement which either: * Sanitizes the debug info, when `--btf` is enabled. * Strips the debug info, when `--btf` is disabled. Also, there is no need to call `DISanitizer::run` in an unsafe block, it's a safe method. --- src/linker.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/linker.rs b/src/linker.rs index fddd6530..727839d6 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -450,12 +450,16 @@ impl Linker { // run optimizations. Will optionally remove noinline attributes, intern all non exported // programs and maps and remove dead code. - unsafe { + if self.options.btf { // if we want to emit BTF, we need to sanitize the debug information - if self.options.btf { - llvm::DISanitizer::new(self.context, self.module).run(&self.options.export_symbols); - } + llvm::DISanitizer::new(self.context, self.module).run(&self.options.export_symbols); + } else { + // if we don't need BTF emission, we can strip DI + let ok = unsafe { llvm::strip_debug_info(self.module) }; + debug!("Stripping DI, changed={}", ok); + } + unsafe { llvm::optimize( self.target_machine, self.module, @@ -466,12 +470,6 @@ impl Linker { } .map_err(LinkerError::OptimizeError)?; - // if we don't need BTF emission, we can strip DI - if !self.options.btf { - let ok = unsafe { llvm::strip_debug_info(self.module) }; - debug!("Stripping DI, changed={}", ok); - } - Ok(()) }