mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #114974 - nbdd0121:vtable, r=b-naber
Add an (perma-)unstable option to disable vtable vptr This flag is intended for evaluation of trait upcasting space cost for embedded use cases. Compared to the approach in #112355, this option provides a way to evaluate end-to-end cost of trait upcasting. Rationale: https://github.com/rust-lang/rust/issues/112355#issuecomment-1658207769 ## How this flag should be used (after merge) Build your project with and without `-Zno-trait-vptr` flag. If you are using cargo, set `RUSTFLAGS="-Zno-trait-vptr"` in the environment variable. You probably also want to use `-Zbuild-std` or the binary built may be broken. Save both binaries somewhere. ### Evaluate the space cost The option has a direct and indirect impact on vtable space usage. Directly, it gets rid of the trait vptr entry needed to store a pointer to a vtable of a supertrait. (IMO) this is a small saving usually. The larger saving usually comes with the indirect saving by eliminating the vtable of the supertrait (and its parent). Both impacts only affects vtables (notably the number of functions monomorphized should , however where vtable reside can depend on your relocation model. If the relocation model is static, then vtable is rodata (usually stored in Flash/ROM together with text in embedded scenario). If the binary is relocatable, however, the vtable will live in `.data` (more specifically, `.data.rel.ro`), and this will need to reside in RAM (which may be a more scarce resource in some cases), together with dynamic relocation info living in readonly segment. For evaluation, you should run `size` on both binaries, with and without the flag. `size` would output three columns, `text`, `data`, `bss` and the sum `dec` (and it's hex version). As explained above, both `text` and `data` may change. `bss` shouldn't usually change. It'll be useful to see: * Percentage change in text + data (indicating required flash/ROM size) * Percentage change in data + bss (indicating required RAM size)
This commit is contained in:
commit
8dfbc76f34
@ -807,6 +807,7 @@ fn test_unstable_options_tracking_hash() {
|
||||
tracked!(no_jump_tables, true);
|
||||
tracked!(no_link, true);
|
||||
tracked!(no_profiler_runtime, true);
|
||||
tracked!(no_trait_vptr, true);
|
||||
tracked!(no_unique_section_names, true);
|
||||
tracked!(oom, OomStrategy::Panic);
|
||||
tracked!(osx_rpath_install_name, true);
|
||||
|
@ -1631,6 +1631,8 @@ options! {
|
||||
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
|
||||
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
|
||||
"prevent automatic injection of the profiler_builtins crate"),
|
||||
no_trait_vptr: bool = (false, parse_no_flag, [TRACKED],
|
||||
"disable generation of trait vptr in vtable for upcasting"),
|
||||
no_unique_section_names: bool = (false, parse_bool, [TRACKED],
|
||||
"do not use unique names for text and data sections when -Z function-sections is used"),
|
||||
normalize_docs: bool = (false, parse_bool, [TRACKED],
|
||||
|
@ -152,7 +152,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
|
||||
while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() {
|
||||
segment_visitor(VtblSegment::TraitOwnEntries {
|
||||
trait_ref: inner_most_trait_ref,
|
||||
emit_vptr,
|
||||
emit_vptr: emit_vptr && !tcx.sess.opts.unstable_opts.no_trait_vptr,
|
||||
})?;
|
||||
|
||||
// If we've emitted (fed to `segment_visitor`) a trait that has methods present in the vtable,
|
||||
|
Loading…
Reference in New Issue
Block a user