mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-14 07:53:24 +00:00
Add no_default_libraries
target linker option
If set to false, `-nodefaultlibs` is not passed to the linker. This was the default behavior on Windows, but it should be configurable per target. This is a [breaking-change] for target specifications that have the `is_like_windows` option set to true. Such targets need to set `no_default_libraries` to false in order to restore the old behavior.
This commit is contained in:
parent
7e8d19b24d
commit
920f32becd
@ -157,6 +157,9 @@ pub struct TargetOptions {
|
||||
/// Whether to disable linking to compiler-rt. Defaults to false, as LLVM
|
||||
/// will emit references to the functions that compiler-rt provides.
|
||||
pub no_compiler_rt: bool,
|
||||
/// Whether to disable linking to the default libraries, typically corresponds
|
||||
/// to `-nodefaultlibs`. Defaults to true.
|
||||
pub no_default_libraries: bool,
|
||||
/// Dynamically linked executables can be compiled as position independent
|
||||
/// if the default relocation model of position independent code is not
|
||||
/// changed. This is a requirement to take advantage of ASLR, as otherwise
|
||||
@ -212,6 +215,7 @@ impl Default for TargetOptions {
|
||||
linker_is_gnu: false,
|
||||
has_rpath: false,
|
||||
no_compiler_rt: false,
|
||||
no_default_libraries: true,
|
||||
position_independent_executables: false,
|
||||
pre_link_objects: Vec::new(),
|
||||
post_link_objects: Vec::new(),
|
||||
@ -319,6 +323,7 @@ impl Target {
|
||||
key!(linker_is_gnu, bool);
|
||||
key!(has_rpath, bool);
|
||||
key!(no_compiler_rt, bool);
|
||||
key!(no_default_libraries, bool);
|
||||
key!(pre_link_args, list);
|
||||
key!(post_link_args, list);
|
||||
key!(allow_asm, bool);
|
||||
|
@ -23,6 +23,10 @@ pub fn opts() -> TargetOptions {
|
||||
exe_suffix: ".exe".to_string(),
|
||||
staticlib_prefix: "".to_string(),
|
||||
staticlib_suffix: ".lib".to_string(),
|
||||
// Unfortunately right now passing -nodefaultlibs to gcc on windows
|
||||
// doesn't work so hot (in terms of native dependencies). This flag
|
||||
// should hopefully be removed one day though!
|
||||
no_default_libraries: false,
|
||||
is_like_windows: true,
|
||||
archive_format: "gnu".to_string(),
|
||||
pre_link_args: vec!(
|
||||
|
@ -970,7 +970,9 @@ fn link_args(cmd: &mut Linker,
|
||||
// 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.
|
||||
cmd.no_default_libraries();
|
||||
if t.options.no_default_libraries {
|
||||
cmd.no_default_libraries();
|
||||
}
|
||||
|
||||
// Take careful note of the ordering of the arguments we pass to the linker
|
||||
// here. Linkers will assume that things on the left depend on things to the
|
||||
|
@ -159,12 +159,7 @@ impl<'a> Linker for GnuLinker<'a> {
|
||||
}
|
||||
|
||||
fn no_default_libraries(&mut self) {
|
||||
// Unfortunately right now passing -nodefaultlibs to gcc on windows
|
||||
// doesn't work so hot (in terms of native dependencies). This if
|
||||
// statement should hopefully be removed one day though!
|
||||
if !self.sess.target.target.options.is_like_windows {
|
||||
self.cmd.arg("-nodefaultlibs");
|
||||
}
|
||||
self.cmd.arg("-nodefaultlibs");
|
||||
}
|
||||
|
||||
fn build_dylib(&mut self, out_filename: &Path) {
|
||||
|
Loading…
Reference in New Issue
Block a user