Skip to content

Commit ffafd15

Browse files
authored
Rollup merge of #71030 - petrochenkov:linkorder2, r=nagisa
rustc_target: Refactor target specifications related to Windows and UEFI - LLD support is improved. - Code is cleaned up. - Target specs are organized in a more hierarchical way. - Possible issues in UWP and UEFI platforms are identified (see FIXMEs). The code is better read per-commit.
2 parents 629e51b + 8392e47 commit ffafd15

38 files changed

+219
-225
lines changed

src/librustc_codegen_ssa/back/link.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_session::search_paths::PathKind;
1212
/// need out of the shared crate context before we get rid of it.
1313
use rustc_session::{filesearch, Session};
1414
use rustc_span::symbol::Symbol;
15-
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
15+
use rustc_target::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel};
1616

1717
use super::archive::ArchiveBuilder;
1818
use super::command::Command;
@@ -182,7 +182,9 @@ fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> Command {
182182
// To comply with the Windows App Certification Kit,
183183
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
184184
let t = &sess.target.target;
185-
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
185+
if (flavor == LinkerFlavor::Msvc || flavor == LinkerFlavor::Lld(LldFlavor::Link))
186+
&& t.target_vendor == "uwp"
187+
{
186188
if let Some(ref tool) = msvc_tool {
187189
let original_path = tool.path();
188190
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
@@ -1530,13 +1532,8 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
15301532
cmd.debuginfo();
15311533

15321534
// OBJECT-FILES-NO, AUDIT-ORDER
1533-
// We want to, by default, prevent the compiler from accidentally leaking in
1534-
// any system libraries, so we may explicitly ask linkers to not link to any
1535-
// libraries by default. Note that this does not happen for windows because
1536-
// windows pulls in some large number of libraries and I couldn't quite
1537-
// figure out which subset we wanted.
1538-
//
1539-
// This is all naturally configurable via the standard methods as well.
1535+
// We want to prevent the compiler from accidentally leaking in any system libraries,
1536+
// so by default we tell linkers not to link to any default libraries.
15401537
if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
15411538
&& sess.target.target.options.no_default_libraries
15421539
{

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,7 @@ impl<'a> Linker for MsvcLinker<'a> {
631631
}
632632

633633
fn no_default_libraries(&mut self) {
634-
// Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
635-
// as there's been trouble in the past of linking the C++ standard
636-
// library required by LLVM. This likely needs to happen one day, but
637-
// in general Windows is also a more controlled environment than
638-
// Unix, so it's not necessarily as critical that this be implemented.
639-
//
640-
// Note that there are also some licensing worries about statically
641-
// linking some libraries which require a specific agreement, so it may
642-
// not ever be possible for us to pass this flag.
634+
self.cmd.arg("/NODEFAULTLIB");
643635
}
644636

645637
fn include_path(&mut self, path: &Path) {

src/librustc_target/spec/armebv7r_none_eabi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Targets the Big endian Cortex-R4/R5 processor (ARMv7-R)
22

33
use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions, TargetResult};
4-
use std::default::Default;
54

65
pub fn target() -> TargetResult {
76
Ok(Target {

src/librustc_target/spec/armebv7r_none_eabihf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Targets the Cortex-R4F/R5F processor (ARMv7-R)
22

33
use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions, TargetResult};
4-
use std::default::Default;
54

65
pub fn target() -> TargetResult {
76
Ok(Target {

src/librustc_target/spec/armv7r_none_eabi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Targets the Little-endian Cortex-R4/R5 processor (ARMv7-R)
22

33
use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions, TargetResult};
4-
use std::default::Default;
54

65
pub fn target() -> TargetResult {
76
Ok(Target {

src/librustc_target/spec/armv7r_none_eabihf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Targets the Little-endian Cortex-R4F/R5F processor (ARMv7-R)
22

33
use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions, TargetResult};
4-
use std::default::Default;
54

65
pub fn target() -> TargetResult {
76
Ok(Target {

src/librustc_target/spec/dragonfly_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::spec::{LinkArgs, LinkerFlavor, RelroLevel, TargetOptions};
2-
use std::default::Default;
32

43
pub fn opts() -> TargetOptions {
54
let mut args = LinkArgs::new();

src/librustc_target/spec/freebsd_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::spec::{LinkArgs, LinkerFlavor, RelroLevel, TargetOptions};
2-
use std::default::Default;
32

43
pub fn opts() -> TargetOptions {
54
let mut args = LinkArgs::new();

src/librustc_target/spec/fuchsia_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
2-
use std::default::Default;
32

43
pub fn opts() -> TargetOptions {
54
let mut pre_link_args = LinkArgs::new();

src/librustc_target/spec/haiku_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::spec::{RelroLevel, TargetOptions};
2-
use std::default::Default;
32

43
pub fn opts() -> TargetOptions {
54
TargetOptions {

0 commit comments

Comments
 (0)