Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.83k stars 399 forks source link

Object size of the rfl drviers are larger than the corresponding C drivers especially when with debug symbols #1039

Open Richardhongyu opened 8 months ago

Richardhongyu commented 8 months ago

Recently I have a research project about comparing the RFL drivers with C drivers. I found that Rust drivers are bigger than C especially when they are compiled with symbols. From what I observed, the Rust drivers are 2X than C drivers without debug symbols and 4-6X with debug symbols. I use the binder driver from the earlier version as an example to show this. There are two object files of the binder driver on the C side. I just use one as an example to explain.

drivers/android/rust_binder.o  :
section              size   addr
.text               44744      0
.initcall6.init         4      0
.rodata              3089      0
.data                   8      0
.rodata.cst8           16      0
.rodata.cst32          32      0
.rodata.cst4           12      0
.bss                   24      0
.modinfo              148      0
.debug_loc         159816      0
.debug_abbrev        1430      0
.debug_info        401422      0
.debug_aranges        112      0
.debug_ranges       92784      0
.debug_str         466822      0
.debug_pubnames     58507      0
.debug_pubtypes    244866      0
.note.GNU-stack         0      0
.debug_frame         5504      0
.debug_line         38268      0
Total             1517608

drivers/android/binder.o  :
section                  size   addr
.text                   51504      0
.note.gnu.property         32      0
.initcall6.init             4      0
__ex_table                240      0
.rodata                  2504      0
.altinstructions          756      0
.init.text                196      0
__bug_table              1092      0
.rodata.str              2275      0
.data                     216      0
__param                   120      0
.modinfo                  119      0
.rodata.str1.1           9081      0
.bss                    20264      0
.discard.addressable        8      0
.debug_loclists         54436      0
.debug_abbrev            2165      0
.debug_info            126699      0
.debug_rnglists         12959      0
.debug_str_offsets      15136      0
.debug_str              47377      0
.debug_addr             14672      0
.comment                   38      0
.note.GNU-stack             0      0
.debug_frame             4472      0
.debug_line             35596      0
.debug_line_str          2322      0
.llvm_addrsig             114      0
Total                         404397

The extra size comes from two reasons.

Before optimizing this, I want to ask for advice/opinions from the community. Does the object size of the RFL drivers matter? Is there anyone working on this?

ojeda commented 8 months ago

Does the object size of the RFL drivers matter?

It does (especially if we end up with Rust used a lot, of course), but probably what matters the most are sections that take memory when loaded (e.g. .text, .data, .rodata, .bss and so on marked with SHF_ALLOC).

Richardhongyu commented 8 months ago

Thanks! I will take a look at these sections.

weihanglo commented 4 months ago

FWIW, 1.76.0 removes .debug_pubnames and .debug_pubtypes via https://github.com/rust-lang/rust/pull/117962.

ojeda commented 4 months ago

Thanks Weihang! I will check how much of a difference it makes for us and report it in our upgrade commit message if so.

ojeda commented 4 months ago

It reduces around a ~15% (uncompressed DWARFv4) or ~5% (compressed DWARFv4) of the original size of our kernel.o. :)

weihanglo commented 4 months ago

Not much, but still an improvement :)

Thanks for the update!