Description
Good day!
I have found, that if a library contains code that may panic (slices, unwraps, etc.), then a filename of such source file will be included in a binary. Release build doesn't change this behavior, neither debug symbols stripping do.
I have tried to turn on "abort" for panic in release profile. Even though this resulted in a smaller binary size, it doesn't wipe out source file names from the binary.
Here is a small reproducible code.
// "engine" library, file lib.rs
pub fn print_message() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
}
// "main" program, file main.rs
fn main() {
engine::print_message();
}
// main Cargo.toml
[package]
name = "symbols_test"
version = "0.1.0"
authors = ["Name Soname <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
panic = "abort"
[dependencies]
engine = { path = "../engine" }
If I build this example with a command cargo build --release
on Windows, then a symbols_test.exe
will contain a string engine\src\lib.rs
.
==============================
So what should I do, if I want to distribute my program to the clients and do not want them to find out file names of my source files (which are a business secret)? How to strip source file names from the binary?
UPD: How to reproduce the problem on Windows:
git clone https://github.com/dmitry-zakablukov/rust-lang-issue-75263.git
cd rust-lang-issue-75263\symbols_test
cargo build --release
strings target\release\symbols_test.exe | grep "engine\src"
On *nix systems change slashes to '/' and remove '.exe' in the last command.