Skip to content

Commit b37700c

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 ef53b7a commit b37700c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/librustc/back/link.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,17 @@ fn link_args(sess: Session,
10911091
args.push(metadata.as_str().unwrap().to_owned());
10921092
}
10931093

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

src/libstd/rt/unwind.rs

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ mod libunwind {
142142
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
143143
exception: *_Unwind_Exception);
144144

145+
#[cfg(target_os = "linux")]
146+
#[cfg(target_os = "freebsd")]
147+
#[cfg(target_os = "win32")]
148+
#[link(name = "gcc_s")]
149+
extern {}
150+
145151
extern "C" {
146152
pub fn _Unwind_RaiseException(exception: *_Unwind_Exception) -> _Unwind_Reason_Code;
147153
pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);

src/libstd/rtdeps.rs

+2-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")]
@@ -39,5 +40,5 @@ extern {}
3940
extern {}
4041

4142
#[cfg(target_os = "macos")]
42-
#[link(name = "pthread")]
43+
#[link(name = "System")]
4344
extern {}

0 commit comments

Comments
 (0)