Skip to content

Commit

Permalink
di: Make the decision about DI in one if-else statement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadorovsky committed Feb 10, 2024
1 parent 574031c commit e9e1630
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(())
}

Expand Down

0 comments on commit e9e1630

Please sign in to comment.