Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Richardhongyu opened this issue Oct 17, 2023 · 6 comments
Labels
• toolchain Related to `rustc`, `bindgen`, `rustdoc`, LLVM, Clippy...

Comments

@Richardhongyu
Copy link

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.

  • Currently, Rust generates some unnecessary sections such as debug_pubnames, debug_pubtypes, and debug_ranges. There is a PR, but it is not landing due to the CI problems.
  • Some sections are larger than the C side, such as debug_str and debug_info. These are caused by generic programming and the wrapping functions. It is hard to optimize them for now.

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 ojeda added the • toolchain Related to `rustc`, `bindgen`, `rustdoc`, LLVM, Clippy... label Oct 17, 2023
@ojeda
Copy link
Member

ojeda commented Oct 17, 2023

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
Copy link
Author

Thanks! I will take a look at these sections.

@weihanglo
Copy link

FWIW, 1.76.0 removes .debug_pubnames and .debug_pubtypes via rust-lang/rust#117962.

@ojeda
Copy link
Member

ojeda commented Feb 9, 2024

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
Copy link
Member

ojeda commented Feb 12, 2024

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

@weihanglo
Copy link

Not much, but still an improvement :)

Thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
• toolchain Related to `rustc`, `bindgen`, `rustdoc`, LLVM, Clippy...
Development

No branches or pull requests

3 participants