From 71f63d0b6899474df633764d7c830bc7999bf11a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 22 Sep 2020 13:47:06 +0200 Subject: [PATCH 1/2] [DO NOT MERGE] Measure cost of function section I was experimenting with using per function sections instead of a single `.text` section in cg_clif to see if it reduced binary size. It brings the size down for the test I used from 26MB to 15MB like the output of cg_llvm in debug mode. When I measured the linker time the result was a lot less positive: ~0.4s turned into ~0.7s. That is a 75% slowdown. It would be interesting to know what the cost is for cg_llvm over the full rustc-perf benchmark suite. --- compiler/rustc_codegen_llvm/src/back/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 937821e9d4fb2..4a06a77b47cfe 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -128,7 +128,7 @@ pub fn target_machine_factory( let (opt_level, _) = to_llvm_opt_settings(optlvl); let use_softfp = sess.opts.cg.soft_float; - let ffunction_sections = sess.target.target.options.function_sections; + let ffunction_sections = false; let fdata_sections = ffunction_sections; let code_model = to_llvm_code_model(sess.code_model()); From 6d1124e261b588c3f8b814f2d5886e5263155526 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 30 Sep 2020 21:02:46 +0200 Subject: [PATCH 2/2] Only enable -ffunction-sections in release mode --- compiler/rustc_codegen_llvm/src/back/write.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 4a06a77b47cfe..5ef2e2dbc2d47 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -128,7 +128,8 @@ pub fn target_machine_factory( let (opt_level, _) = to_llvm_opt_settings(optlvl); let use_softfp = sess.opts.cg.soft_float; - let ffunction_sections = false; + let ffunction_sections = + sess.target.target.options.function_sections && optlvl != config::OptLevel::No; let fdata_sections = ffunction_sections; let code_model = to_llvm_code_model(sess.code_model());