File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -1082,6 +1082,17 @@ fn link_args(sess: Session,
10821082 args. push ( metadata. as_str ( ) . unwrap ( ) . to_owned ( ) ) ;
10831083 }
10841084
1085+ // We want to prevent the compiler from accidentally leaking in any system
1086+ // libraries, so we explicitly ask gcc to not link to any libraries by
1087+ // default. Note that this does not happen for windows because windows pulls
1088+ // in some large number of libraries and I couldn't quite figure out which
1089+ // subset we wanted.
1090+ //
1091+ // FIXME(#11937) we should invoke the system linker directly
1092+ if sess. targ_cfg . os != abi:: OsWin32 {
1093+ args. push ( ~"-nodefaultlibs") ;
1094+ }
1095+
10851096 if sess. targ_cfg . os == abi:: OsLinux {
10861097 // GNU-style linkers will use this to omit linking to libraries which
10871098 // don't actually fulfill any relocations, but only for libraries which
Original file line number Diff line number Diff line change @@ -143,6 +143,16 @@ mod libunwind {
143143 pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn ( unwind_code : _Unwind_Reason_Code ,
144144 exception : * _Unwind_Exception ) ;
145145
146+ #[ cfg( target_os = "linux" ) ]
147+ #[ cfg( target_os = "freebsd" ) ]
148+ #[ cfg( target_os = "win32" ) ]
149+ #[ link( name = "gcc_s" ) ]
150+ extern { }
151+
152+ #[ cfg( target_os = "android" ) ]
153+ #[ link( name = "gcc" ) ]
154+ extern { }
155+
146156 extern "C" {
147157 pub fn _Unwind_RaiseException ( exception : * _Unwind_Exception ) -> _Unwind_Reason_Code ;
148158 pub fn _Unwind_DeleteException ( exception : * _Unwind_Exception ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ extern {}
2222// On linux librt and libdl are indirect dependencies via rustrt,
2323// and binutils 2.22+ won't add them automatically
2424#[ cfg( target_os = "linux" ) ]
25+ #[ link( name = "c" ) ]
2526#[ link( name = "dl" ) ]
2627#[ link( name = "m" ) ]
2728#[ link( name = "pthread" ) ]
@@ -31,6 +32,7 @@ extern {}
3132#[ link( name = "dl" ) ]
3233#[ link( name = "log" ) ]
3334#[ link( name = "m" ) ]
35+ #[ link( name = "c" ) ]
3436extern { }
3537
3638#[ cfg( target_os = "freebsd" ) ]
@@ -39,5 +41,5 @@ extern {}
3941extern { }
4042
4143#[ cfg( target_os = "macos" ) ]
42- #[ link( name = "pthread " ) ]
44+ #[ link( name = "System " ) ]
4345extern { }
You can’t perform that action at this time.
0 commit comments