Skip to content

Commit

Permalink
Remove unnecessary symbols and sections from *_gnu import libs
Browse files Browse the repository at this point in the history
This cuts their size by more than 20% by removing what is essentially
dead-weight:
 crates/targets/i686_gnu/lib/libwindows.a   | Bin 14009016 -> 10937090 bytes
 crates/targets/x86_64_gnu/lib/libwindows.a | Bin 13879932 -> 10500116 bytes
  • Loading branch information
glandium committed Aug 17, 2022
1 parent fc2b4bf commit 7bc3c4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Binary file modified crates/targets/i686_gnu/lib/libwindows.a
Binary file not shown.
Binary file modified crates/targets/x86_64_gnu/lib/libwindows.a
Binary file not shown.
11 changes: 10 additions & 1 deletion crates/tools/gnu/src/main.rs
Expand Up @@ -91,10 +91,19 @@ EXPORTS
}
cmd.output().unwrap();

// Work around lack of determinism in dlltool output.
// Work around lack of determinism in dlltool output, and at the same time remove
// unnecessary sections and symbols.
std::fs::rename(output.join(format!("lib{}.a", library)), output.join("tmp.a")).unwrap();
let mut cmd = std::process::Command::new("objcopy");
cmd.current_dir(&output);
cmd.arg("--remove-section=.bss");
cmd.arg("--remove-section=.data");
cmd.arg("--strip-unneeded-symbol=.text");
cmd.arg("--strip-unneeded-symbol=.data");
cmd.arg("--strip-unneeded-symbol=.bss");
cmd.arg("--strip-unneeded-symbol=.idata$7");
cmd.arg("--strip-unneeded-symbol=.idata$5");
cmd.arg("--strip-unneeded-symbol=.idata$4");
cmd.arg("tmp.a");
cmd.arg(format!("lib{}.a", library));
cmd.output().unwrap();
Expand Down

0 comments on commit 7bc3c4f

Please sign in to comment.