Skip to content

Commit

Permalink
Add cargo flag to compress debug sections on linux
Browse files Browse the repository at this point in the history
Before:
-rwxrwxr-x   2 lima lima 195M Dec  1 23:43 libvrl_bridge.so

$ bloaty target/release/libvrl_bridge.so
    FILE SIZE        VM SIZE
 --------------  --------------
  24.5%  47.7Mi   0.0%       0    .debug_info
  21.6%  42.0Mi   0.0%       0    .debug_loc
  12.2%  23.7Mi   0.0%       0    .debug_ranges
  10.4%  20.2Mi   0.0%       0    .debug_str
   9.9%  19.2Mi   0.0%       0    .debug_pubtypes
   9.0%  17.4Mi   0.0%       0    .debug_pubnames
   4.8%  9.27Mi   0.0%       0    .debug_line
   2.2%  4.35Mi  44.9%  4.35Mi    .text
   0.9%  1.83Mi   0.0%       0    .strtab
   0.9%  1.67Mi   0.0%       0    .symtab
   0.8%  1.52Mi  15.7%  1.52Mi    .data.rel.ro
   0.7%  1.44Mi  14.9%  1.44Mi    .rodata
   0.7%  1.39Mi  14.3%  1.39Mi    .rela.dyn
   0.4%   800Ki   0.0%       0    .debug_aranges
   0.4%   747Ki   0.0%       0    .debug_abbrev
   0.3%   616Ki   6.2%   616Ki    .eh_frame
   0.1%   258Ki   2.6%   258Ki    .gcc_except_table
   0.1%   107Ki   1.1%   107Ki    .eh_frame_hdr
   0.0%  20.6Ki   0.2%  20.6Ki    .data
   0.0%  10.8Ki   0.1%  12.3Ki    [23 Others]
   0.0%  2.50Ki   0.0%       0    [ELF Section Headers]
 100.0%   194Mi 100.0%  9.69Mi    TOTAL

After:
-rwxrwxr-x   2 lima lima  47M Dec  1 23:57 libvrl_bridge.so

$ bloaty target/release/libvrl_bridge.so
    FILE SIZE        VM SIZE
 --------------  --------------
  37.9%  17.7Mi   0.0%       0    .debug_info
   9.3%  4.35Mi  44.9%  4.35Mi    .text
   8.8%  4.12Mi   0.0%       0    .debug_loc
   6.0%  2.80Mi   0.0%       0    .debug_str
   5.9%  2.77Mi   0.0%       0    .debug_pubnames
   5.3%  2.49Mi   0.0%       0    .debug_pubtypes
   5.0%  2.34Mi   0.0%       0    .debug_line
   3.9%  1.83Mi   0.0%       0    .strtab
   3.6%  1.67Mi   0.0%       0    .symtab
   3.2%  1.52Mi  15.7%  1.52Mi    .data.rel.ro
   3.1%  1.44Mi  14.9%  1.44Mi    .rodata
   3.0%  1.39Mi  14.3%  1.39Mi    .rela.dyn
   2.4%  1.10Mi   0.0%       0    .debug_ranges
   1.3%   616Ki   6.2%   616Ki    .eh_frame
   0.5%   258Ki   2.6%   258Ki    .gcc_except_table
   0.3%   127Ki   0.0%       0    .debug_abbrev
   0.2%   119Ki   0.0%       0    .debug_aranges
   0.2%   107Ki   1.1%   107Ki    .eh_frame_hdr
   0.0%  20.6Ki   0.2%  20.6Ki    .data
   0.0%  10.6Ki   0.1%  12.3Ki    [23 Others]
   0.0%  2.50Ki   0.0%       0    [ELF Section Headers]
 100.0%  46.8Mi 100.0%  9.69Mi    TOTAL

Source/Inspiration:
benesch/materialize@a618135

`bloaty` refers to this tool https://github.com/google/bloaty
  • Loading branch information
scottopell committed Dec 2, 2022
1 parent 0803ff8 commit 2d46f2b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[target."aarch64-unknown-linux-gnu"]
# Compressing debug information can yield hundreds of megabytes of savings.
# The Rust toolchain does not currently perform dead code elimination on
# debug info.
#
# See: https://github.com/rust-lang/rust/issues/56068
# See: https://reviews.llvm.org/D74169#1990180
rustflags = ["-C", "link-arg=-Wl,--compress-debug-sections=zlib-gabi"]

0 comments on commit 2d46f2b

Please sign in to comment.