Rollup merge of #72782 - petrochenkov:crtargs, r=varkor

rustc_target: Remove `pre_link_args_crt`

To regain some more control over the definition of `+crt-static` (https://github.com/rust-lang/rust/pull/71586).

After https://github.com/rust-lang/rust/pull/71769 this target option wasn't used anywhere except for VxWorks, and I suspect that for VxWorks its use may be redundant as well.
This commit is contained in:
Dylan DPC 2020-06-04 12:12:45 +02:00 committed by GitHub
commit adc321a1e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 21 deletions

View File

@ -1253,20 +1253,10 @@ fn add_post_link_objects(
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
/// FIXME: Determine where exactly these args need to be inserted.
fn add_pre_link_args(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
crate_type: CrateType,
) {
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
cmd.args(args);
}
if let Some(args) = sess.target.target.options.pre_link_args_crt.get(&flavor) {
if sess.crt_static(Some(crate_type)) {
cmd.args(args);
}
}
cmd.args(&sess.opts.debugging_opts.pre_link_args);
}
@ -1502,7 +1492,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
let crt_objects_fallback = crt_objects_fallback(sess, crate_type);
// NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
add_pre_link_args(cmd, sess, flavor, crate_type);
add_pre_link_args(cmd, sess, flavor);
// NO-OPT-OUT
add_link_script(cmd, sess, tmpdir, crate_type);

View File

@ -315,6 +315,21 @@ impl<'a> Linker for GccLinker<'a> {
self.build_dylib(out_filename);
}
}
// VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
// it switches linking for libc and similar system libraries to static without using
// any `#[link]` attributes in the `libc` crate, see #72782 for details.
// FIXME: Switch to using `#[link]` attributes in the `libc` crate
// similarly to other targets.
if self.sess.target.target.target_os == "vxworks"
&& matches!(
output_kind,
LinkOutputKind::StaticNoPicExe
| LinkOutputKind::StaticPicExe
| LinkOutputKind::StaticDylib
)
{
self.cmd.arg("--static-crt");
}
}
fn link_dylib(&mut self, lib: Symbol) {

View File

@ -733,8 +733,7 @@ pub struct TargetOptions {
pub lld_flavor: LldFlavor,
/// Linker arguments that are passed *before* any user-defined libraries.
pub pre_link_args: LinkArgs, // ... unconditionally
pub pre_link_args_crt: LinkArgs, // ... when linking with a bundled crt
pub pre_link_args: LinkArgs,
/// Objects to link before and after all other object code.
pub pre_link_objects: CrtObjects,
pub post_link_objects: CrtObjects,
@ -997,7 +996,6 @@ impl Default for TargetOptions {
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()),
lld_flavor: LldFlavor::Ld,
pre_link_args: LinkArgs::new(),
pre_link_args_crt: LinkArgs::new(),
post_link_args: LinkArgs::new(),
link_script: None,
asm_args: Vec::new(),
@ -1397,7 +1395,6 @@ impl Target {
key!(post_link_objects_fallback, link_objects);
key!(crt_objects_fallback, crt_objects_fallback)?;
key!(pre_link_args, link_args);
key!(pre_link_args_crt, link_args);
key!(late_link_args, link_args);
key!(late_link_args_dynamic, link_args);
key!(late_link_args_static, link_args);
@ -1629,7 +1626,6 @@ impl ToJson for Target {
target_option_val!(post_link_objects_fallback);
target_option_val!(crt_objects_fallback);
target_option_val!(link_args - pre_link_args);
target_option_val!(link_args - pre_link_args_crt);
target_option_val!(link_args - late_link_args);
target_option_val!(link_args - late_link_args_dynamic);
target_option_val!(link_args - late_link_args_static);

View File

@ -25,7 +25,6 @@ impl Target {
);
for args in &[
&self.options.pre_link_args,
&self.options.pre_link_args_crt,
&self.options.late_link_args,
&self.options.late_link_args_dynamic,
&self.options.late_link_args_static,

View File

@ -1,8 +1,6 @@
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
pub fn opts() -> TargetOptions {
let mut args_crt = LinkArgs::new();
args_crt.insert(LinkerFlavor::Gcc, vec!["--static-crt".to_string()]);
let mut args = LinkArgs::new();
args.insert(
LinkerFlavor::Gcc,
@ -29,7 +27,6 @@ pub fn opts() -> TargetOptions {
pre_link_args: args,
position_independent_executables: false,
has_elf_tls: true,
pre_link_args_crt: args_crt,
crt_static_default: true,
crt_static_respected: true,
crt_static_allows_dylibs: true,