diff --git a/src/librustc_codegen_llvm/back/linker.rs b/src/librustc_codegen_llvm/back/linker.rs index 5f2f3733ec7f0..7253b5346b9ab 100644 --- a/src/librustc_codegen_llvm/back/linker.rs +++ b/src/librustc_codegen_llvm/back/linker.rs @@ -1006,6 +1006,18 @@ impl<'a> Linker for WasmLd<'a> { OptLevel::Size => "-O2", OptLevel::SizeMin => "-O2" }); + match self.sess.opts.optimize { + OptLevel::No => (), + OptLevel::Less | + OptLevel::Default | + OptLevel::Aggressive | + OptLevel::Size | + OptLevel::SizeMin => { + // LLD generates incorrect debugging information when + // optimization is applied: strip debug sections. + self.cmd.arg("--strip-debug"); + } + } } fn pgo_gen(&mut self) {