Auto merge of #123656 - lqd:linker-features, r=petrochenkov
Linker flavors next steps: linker features This is my understanding of the first step towards `@petrochenkov's` vision for the future of linker flavors, described in https://github.com/rust-lang/rust/pull/119906#issuecomment-1895693162 and the discussion that followed. To summarize: having `Cc` and `Lld` embedded in linker flavors creates tension about naming, and a combinatorial explosion of flavors for each new linker feature we'd want to use. Linker features are an extension mechanism that is complementary to principal flavors, with benefits described in #119906. The most immediate use of this flag would be to turn self-contained linking on and off via features instead of flavors. For example, `-Clinker-features=+/-lld` would toggle using lld instead of selecting a precise flavor, and would be "generic" and work cross-platform (whereas linker flavors are currently more tied to targets). Under this scheme, MCP510 is expected to be `-Clink-self-contained=+linker -Zlinker-features=+lld -Zunstable-options` (though for the time being, the original flags using lld-cc flavors still work). I purposefully didn't add or document CLI support for `+/-cc`, as it would be a noop right now. I only expect that we'd initially want to stabilize `+/-lld` to begin with. r? `@petrochenkov` You had requested that minimal churn would be done to the 230 target specs and this does none yet: the linker features are inferred from the flavor since they're currently isomorphic. We of course expect this to change sooner rather than later. In the future, we can allow targets to define linker features independently from their flavor, and remove the cc and lld components from the flavors to use the features instead, this actually doesn't need to block stabilization, as we discussed. (Best reviewed per commit)
This commit is contained in:
commit
7106800e16
6 changed files with 223 additions and 27 deletions
|
@ -448,6 +448,28 @@ impl LinkerFlavor {
|
|||
| LinkerFlavor::Ptx => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// For flavors with an `Lld` component, ensure it's enabled. Otherwise, returns the given
|
||||
/// flavor unmodified.
|
||||
pub fn with_lld_enabled(self) -> LinkerFlavor {
|
||||
match self {
|
||||
LinkerFlavor::Gnu(cc, Lld::No) => LinkerFlavor::Gnu(cc, Lld::Yes),
|
||||
LinkerFlavor::Darwin(cc, Lld::No) => LinkerFlavor::Darwin(cc, Lld::Yes),
|
||||
LinkerFlavor::Msvc(Lld::No) => LinkerFlavor::Msvc(Lld::Yes),
|
||||
_ => self,
|
||||
}
|
||||
}
|
||||
|
||||
/// For flavors with an `Lld` component, ensure it's disabled. Otherwise, returns the given
|
||||
/// flavor unmodified.
|
||||
pub fn with_lld_disabled(self) -> LinkerFlavor {
|
||||
match self {
|
||||
LinkerFlavor::Gnu(cc, Lld::Yes) => LinkerFlavor::Gnu(cc, Lld::No),
|
||||
LinkerFlavor::Darwin(cc, Lld::Yes) => LinkerFlavor::Darwin(cc, Lld::No),
|
||||
LinkerFlavor::Msvc(Lld::Yes) => LinkerFlavor::Msvc(Lld::No),
|
||||
_ => self,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! linker_flavor_cli_impls {
|
||||
|
@ -698,6 +720,58 @@ impl ToJson for LinkSelfContainedComponents {
|
|||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// The `-Z linker-features` components that can individually be enabled or disabled.
|
||||
///
|
||||
/// They are feature flags intended to be a more flexible mechanism than linker flavors, and
|
||||
/// also to prevent a combinatorial explosion of flavors whenever a new linker feature is
|
||||
/// required. These flags are "generic", in the sense that they can work on multiple targets on
|
||||
/// the CLI. Otherwise, one would have to select different linkers flavors for each target.
|
||||
///
|
||||
/// Here are some examples of the advantages they offer:
|
||||
/// - default feature sets for principal flavors, or for specific targets.
|
||||
/// - flavor-specific features: for example, clang offers automatic cross-linking with
|
||||
/// `--target`, which gcc-style compilers don't support. The *flavor* is still a C/C++
|
||||
/// compiler, and we don't need to multiply the number of flavors for this use-case. Instead,
|
||||
/// we can have a single `+target` feature.
|
||||
/// - umbrella features: for example if clang accumulates more features in the future than just
|
||||
/// the `+target` above. That could be modeled as `+clang`.
|
||||
/// - niche features for resolving specific issues: for example, on Apple targets the linker
|
||||
/// flag implementing the `as-needed` native link modifier (#99424) is only possible on
|
||||
/// sufficiently recent linker versions.
|
||||
/// - still allows for discovery and automation, for example via feature detection. This can be
|
||||
/// useful in exotic environments/build systems.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct LinkerFeatures: u8 {
|
||||
/// Invoke the linker via a C/C++ compiler (e.g. on most unix targets).
|
||||
const CC = 1 << 0;
|
||||
/// Use the lld linker, either the system lld or the self-contained linker `rust-lld`.
|
||||
const LLD = 1 << 1;
|
||||
}
|
||||
}
|
||||
rustc_data_structures::external_bitflags_debug! { LinkerFeatures }
|
||||
|
||||
impl LinkerFeatures {
|
||||
/// Parses a single `-Z linker-features` well-known feature, not a set of flags.
|
||||
pub fn from_str(s: &str) -> Option<LinkerFeatures> {
|
||||
Some(match s {
|
||||
"cc" => LinkerFeatures::CC,
|
||||
"lld" => LinkerFeatures::LLD,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns whether the `lld` linker feature is enabled.
|
||||
pub fn is_lld_enabled(self) -> bool {
|
||||
self.contains(LinkerFeatures::LLD)
|
||||
}
|
||||
|
||||
/// Returns whether the `cc` linker feature is enabled.
|
||||
pub fn is_cc_enabled(self) -> bool {
|
||||
self.contains(LinkerFeatures::CC)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
|
||||
pub enum PanicStrategy {
|
||||
Unwind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue