From a0f876525132d548bb051b44f9b683c4af3db11e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 23 Sep 2020 09:43:35 +0200 Subject: [PATCH] Add option to use a single section for each function --- Readme.md | 3 +++ src/backend.rs | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 24485058250..f5a38f0843b 100644 --- a/Readme.md +++ b/Readme.md @@ -70,6 +70,9 @@ function jit_calc() { object files when their content should have been changed by a change to cg_clif.
CG_CLIF_DISPLAY_CG_TIME
If "1", display the time it took to perform codegen for a crate
+
CG_CLIF_FUNCTION_SECTIONS
+
Use a single section for each function. This will often reduce the executable size at the + cost of making linking significantly slower.
## Not yet supported diff --git a/src/backend.rs b/src/backend.rs index bf4e8d6e02e..d9cb1d939f7 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -186,13 +186,17 @@ pub(crate) type Backend = impl cranelift_module::Backend; pub(crate) fn make_module(sess: &Session, name: String) -> Module { + let mut builder = ObjectBuilder::new( + crate::build_isa(sess, true), + name + ".o", + cranelift_module::default_libcall_names(), + ) + .unwrap(); + if std::env::var("CG_CLIF_FUNCTION_SECTIONS").is_ok() { + builder.per_function_section(true); + } let module: Module = Module::new( - ObjectBuilder::new( - crate::build_isa(sess, true), - name + ".o", - cranelift_module::default_libcall_names(), - ) - .unwrap(), + builder, ); module }