File tree Expand file tree Collapse file tree
compiler/rustc_codegen_ssa/src/mir
src/tools/run-make-support/src/external_deps
tests/run-make/naked-dead-code-elimination Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -295,7 +295,8 @@ fn prefix_and_suffix<'tcx>(
295295 if let Some ( section) = & link_section {
296296 writeln ! ( begin, ".section {section},\" xr\" " ) . unwrap ( )
297297 } else if !function_sections {
298- // Function sections are enabled by default on MSVC, but disabled by default on GNU.
298+ // Function sections are enabled by default on MSVC and windows-gnullvm,
299+ // but disabled by default on GNU.
299300 writeln ! ( begin, ".text" ) . unwrap ( ) ;
300301 } else {
301302 // LLVM uses an extension to the section directive to support defining multiple
Original file line number Diff line number Diff line change @@ -449,6 +449,16 @@ impl Rustc {
449449 self . cmd . arg ( "-Zcodegen-source-order" ) ;
450450 self
451451 }
452+
453+ /// Specify `-Z function-sections={yes, no}`.
454+ pub fn function_sections ( & mut self , enable : bool ) -> & mut Self {
455+ let flag = match enable {
456+ true => "-Zfunction-sections=yes" ,
457+ false => "-Zfunction-sections=no" ,
458+ } ;
459+ self . cmd . arg ( flag) ;
460+ self
461+ }
452462}
453463
454464/// Query the sysroot path corresponding `rustc --print=sysroot`.
Original file line number Diff line number Diff line change 1+ #![ feature( cfg_target_object_format) ]
12use std:: arch:: naked_asm;
23
34#[ unsafe( naked) ]
@@ -6,19 +7,36 @@ extern "C" fn used() {
67 naked_asm ! ( "ret" )
78}
89
10+ #[ unsafe( no_mangle) ]
11+ extern "C" fn unused_clothed ( ) -> i32 {
12+ 42
13+ }
14+
915#[ unsafe( naked) ]
1016#[ unsafe( no_mangle) ]
1117extern "C" fn unused ( ) {
1218 naked_asm ! ( "ret" )
1319}
1420
1521#[ unsafe( naked) ]
16- #[ unsafe( link_section = "foobar" ) ]
22+ #[ unsafe( link_section = cfg_select!(
23+ target_object_format = "mach-o" => "__TEXT,foobar" ,
24+ _ => ".foobar" ,
25+ ) ) ]
1726#[ unsafe( no_mangle) ]
1827extern "C" fn unused_link_section ( ) {
1928 naked_asm ! ( "ret" )
2029}
2130
31+ #[ unsafe( link_section = cfg_select!(
32+ target_object_format = "mach-o" => "__TEXT,baz" ,
33+ _ => ".baz" ,
34+ ) ) ]
35+ #[ unsafe( no_mangle) ]
36+ extern "C" fn unused_link_section_clothed ( ) -> i32 {
37+ 43
38+ }
39+
2240fn main ( ) {
2341 used ( ) ;
2442}
Original file line number Diff line number Diff line change @@ -4,7 +4,19 @@ use run_make_support::symbols::object_contains_any_symbol;
44use run_make_support:: { bin_name, rustc} ;
55
66fn main ( ) {
7- rustc ( ) . input ( "main.rs" ) . opt ( ) . run ( ) ;
8- let mut unused = vec ! [ "unused" , "unused_link_section" ] ;
9- assert ! ( !object_contains_any_symbol( bin_name( "main" ) , & unused) ) ;
7+ rustc ( ) . input ( "main.rs" ) . opt ( ) . function_sections ( true ) . run ( ) ;
8+
9+ let bin = bin_name ( "main" ) ;
10+
11+ // Check that the naked symbol is eliminated when the "clothed" one is.
12+
13+ assert_eq ! (
14+ object_contains_any_symbol( & bin, & [ "unused_clothed" ] ) ,
15+ object_contains_any_symbol( & bin, & [ "unused" ] )
16+ ) ;
17+
18+ assert_eq ! (
19+ object_contains_any_symbol( & bin, & [ "unused_link_section_clothed" ] ) ,
20+ object_contains_any_symbol( & bin, & [ "unused_link_section" ] )
21+ ) ;
1022}
You can’t perform that action at this time.
0 commit comments