Skip to content

Commit

Permalink
Rollup merge of rust-lang#72782 - petrochenkov:crtargs, r=varkor
Browse files Browse the repository at this point in the history
rustc_target: Remove `pre_link_args_crt`

To regain some more control over the definition of `+crt-static` (rust-lang#71586).

After rust-lang#71769 this target option wasn't used anywhere except for VxWorks, and I suspect that for VxWorks its use may be redundant as well.
  • Loading branch information
Dylan-DPC authored Jun 4, 2020
2 parents 21ac561 + b628358 commit adc321a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
14 changes: 2 additions & 12 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/librustc_target/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_target/spec/vxworks_base.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit adc321a

Please sign in to comment.