Skip to content

Commit

Permalink
Invoke gcc with -nodefaultlibs
Browse files Browse the repository at this point in the history
This will hopefully bring us closer to #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).
  • Loading branch information
alexcrichton committed Feb 4, 2014
1 parent ef53b7a commit b37700c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,17 @@ fn link_args(sess: Session,
args.push(metadata.as_str().unwrap().to_owned());
}

// We want to prevent the compiler from accidentally leaking in any system
// libraries, so we explicitly ask gcc to not link to any libraries by
// default. Note that this does not happen for windows because windows pulls
// in some large number of libraries and I couldn't quite figure out which
// subset we wanted.
//
// FIXME(#11937) we should invoke the system linker directly
if sess.targ_cfg.os != abi::OsWin32 {
args.push(~"-nodefaultlibs");
}

if sess.targ_cfg.os == abi::OsLinux {
// GNU-style linkers will use this to omit linking to libraries which
// don't actually fulfill any relocations, but only for libraries which
Expand Down
6 changes: 6 additions & 0 deletions src/libstd/rt/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ mod libunwind {
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
exception: *_Unwind_Exception);

#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "win32")]
#[link(name = "gcc_s")]
extern {}

extern "C" {
pub fn _Unwind_RaiseException(exception: *_Unwind_Exception) -> _Unwind_Reason_Code;
pub fn _Unwind_DeleteException(exception: *_Unwind_Exception);
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/rtdeps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern {}
// On linux librt and libdl are indirect dependencies via rustrt,
// and binutils 2.22+ won't add them automatically
#[cfg(target_os = "linux")]
#[link(name = "c")]
#[link(name = "dl")]
#[link(name = "m")]
#[link(name = "pthread")]
Expand All @@ -39,5 +40,5 @@ extern {}
extern {}

#[cfg(target_os = "macos")]
#[link(name = "pthread")]
#[link(name = "System")]
extern {}

12 comments on commit b37700c

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@b37700c

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/nodefaultlibs = b37700c into auto

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/nodefaultlibs = b37700c merged ok, testing candidate = b656a9bc

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@b37700c

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/nodefaultlibs = b37700c into auto

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/nodefaultlibs = b37700c merged ok, testing candidate = 5a45b94c

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 13, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@b37700c

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/nodefaultlibs = b37700c into auto

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/nodefaultlibs = b37700c merged ok, testing candidate = ee275436

@bors
Copy link
Contributor

@bors bors commented on b37700c Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.