Skip to content

Commit 28fa81a

Browse files
committed
Invoke gcc with -nodefaultlibs
This will hopefully bring us closer to rust-lang#11937. We're still using gcc's idea of "startup files", but this should prevent us from leaking in dependencies that we don't quite want (libgcc for example once compiler-rt is what we use).
1 parent 18477ac commit 28fa81a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/librustc/back/link.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,17 @@ fn link_args(sess: Session,
10841084
args.push(metadata.as_str().unwrap().to_owned());
10851085
}
10861086

1087+
// We want to prevent the compiler from accidentally leaking in any system
1088+
// libraries, so we explicitly ask gcc to not link to any libraries by
1089+
// default. Note that this does not happen for windows because windows pulls
1090+
// in some large number of libraries and I couldn't quite figure out which
1091+
// subset we wanted.
1092+
//
1093+
// FIXME(#11937) we should invoke the system linker directly
1094+
if sess.targ_cfg.os != abi::OsWin32 {
1095+
args.push(~"-nodefaultlibs");
1096+
}
1097+
10871098
if sess.targ_cfg.os == abi::OsLinux {
10881099
// GNU-style linkers will use this to omit linking to libraries which
10891100
// don't actually fulfill any relocations, but only for libraries which

src/libstd/rt/unwind.rs

+10
Original file line numberDiff line numberDiff 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);

src/libstd/rtdeps.rs

+3-1
Original file line numberDiff line numberDiff 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")]
3436
extern {}
3537

3638
#[cfg(target_os = "freebsd")]
@@ -39,5 +41,5 @@ extern {}
3941
extern {}
4042

4143
#[cfg(target_os = "macos")]
42-
#[link(name = "pthread")]
44+
#[link(name = "System")]
4345
extern {}

0 commit comments

Comments
 (0)