Skip to content

Commit 3dddf6a

Browse files
committed
Auto merge of #78414 - nox:function-sections, r=nagisa,bjorn3
Implement -Z function-sections=yes|no This lets rustc users tweak whether all functions should be put in their own TEXT section, using whatever default value the target defines if the flag is missing. I'm having fun experimenting with musl libc and trying to implement the start symbol in Rust, that means avoiding code that requires relocations, and AFAIK putting everything in its own section makes the toolchain generate `GOTPCREL` relocations for symbols that could use plain old PC-relative addressing (at least on `x86_64`) if they were all in the same section.
2 parents 717eb6c + 0569422 commit 3dddf6a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ pub fn target_machine_factory(
128128
let (opt_level, _) = to_llvm_opt_settings(optlvl);
129129
let use_softfp = sess.opts.cg.soft_float;
130130

131-
let ffunction_sections = sess.target.options.function_sections;
131+
let ffunction_sections =
132+
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.options.function_sections);
132133
let fdata_sections = ffunction_sections;
133134

134135
let code_model = to_llvm_code_model(sess.code_model());

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ fn test_debugging_options_tracking_hash() {
550550
tracked!(force_overflow_checks, Some(true));
551551
tracked!(force_unstable_if_unmarked, true);
552552
tracked!(fuel, Some(("abc".to_string(), 99)));
553+
tracked!(function_sections, Some(false));
553554
tracked!(human_readable_cgu_names, true);
554555
tracked!(inline_in_all_cgus, Some(true));
555556
tracked!(insert_sideeffect, true);

compiler/rustc_session/src/options.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
717717
// This list is in alphabetical order.
718718
//
719719
// If you add a new option, please update:
720-
// - src/librustc_interface/tests.rs
720+
// - compiler/rustc_interface/src/tests.rs
721721
// - src/doc/rustc/src/codegen-options/index.md
722722

723723
ar: String = (String::new(), parse_string, [UNTRACKED],
@@ -814,7 +814,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
814814
// This list is in alphabetical order.
815815
//
816816
// If you add a new option, please update:
817-
// - src/librustc_interface/tests.rs
817+
// - compiler/rustc_interface/src/tests.rs
818818
// - src/doc/rustc/src/codegen-options/index.md
819819
}
820820

@@ -825,7 +825,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
825825
// This list is in alphabetical order.
826826
//
827827
// If you add a new option, please update:
828-
// - src/librustc_interface/tests.rs
828+
// - compiler/rustc_interface/src/tests.rs
829829

830830
allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
831831
"only allow the listed language features to be enabled in code (space separated)"),
@@ -904,6 +904,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
904904
"force all crates to be `rustc_private` unstable (default: no)"),
905905
fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
906906
"set the optimization fuel quota for a crate"),
907+
function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
908+
"whether each function should go in its own section"),
907909
graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
908910
"use dark-themed colors in graphviz output (default: no)"),
909911
graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],

0 commit comments

Comments
 (0)