2014-07-23 11:56:36 -07:00
|
|
|
//! [Flexible target specification.](https://github.com/rust-lang/rfcs/pull/131)
|
|
|
|
//!
|
|
|
|
//! Rust targets a wide variety of usecases, and in the interest of flexibility,
|
|
|
|
//! allows new target triples to be defined in configuration files. Most users
|
|
|
|
//! will not need to care about these, but this is invaluable when porting Rust
|
|
|
|
//! to a new platform, and allows for an unprecedented level of control over how
|
|
|
|
//! the compiler works.
|
|
|
|
//!
|
|
|
|
//! # Using custom targets
|
|
|
|
//!
|
|
|
|
//! A target triple, as passed via `rustc --target=TRIPLE`, will first be
|
|
|
|
//! compared against the list of built-in targets. This is to ease distributing
|
|
|
|
//! rustc (no need for configuration files) and also to hold these built-in
|
|
|
|
//! targets as immutable and sacred. If `TRIPLE` is not one of the built-in
|
|
|
|
//! targets, rustc will check if a file named `TRIPLE` exists. If it does, it
|
|
|
|
//! will be loaded as the target configuration. If the file does not exist,
|
|
|
|
//! rustc will search each directory in the environment variable
|
|
|
|
//! `RUST_TARGET_PATH` for a file named `TRIPLE.json`. The first one found will
|
|
|
|
//! be loaded. If no file is found in any of those directories, a fatal error
|
2016-04-09 09:39:22 -05:00
|
|
|
//! will be given.
|
2014-07-23 11:56:36 -07:00
|
|
|
//!
|
|
|
|
//! Projects defining their own targets should use
|
|
|
|
//! `--target=path/to/my-awesome-platform.json` instead of adding to
|
|
|
|
//! `RUST_TARGET_PATH`.
|
|
|
|
//!
|
|
|
|
//! # Defining a new target
|
|
|
|
//!
|
2021-06-23 16:26:46 -04:00
|
|
|
//! Targets are defined using [JSON](https://json.org/). The `Target` struct in
|
2014-07-23 11:56:36 -07:00
|
|
|
//! this module defines the format the JSON file should take, though each
|
|
|
|
//! underscore in the field names should be replaced with a hyphen (`-`) in the
|
|
|
|
//! JSON file. Some fields are required in every target specification, such as
|
2016-04-18 15:38:45 +03:00
|
|
|
//! `llvm-target`, `target-endian`, `target-pointer-width`, `data-layout`,
|
|
|
|
//! `arch`, and `os`. In general, options passed to rustc with `-C` override
|
|
|
|
//! the target's settings, though `target-feature` and `link-args` will *add*
|
|
|
|
//! to the list specified by the target, rather than replace.
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2021-01-05 01:01:29 +00:00
|
|
|
use crate::abi::Endian;
|
2021-06-03 17:45:09 +02:00
|
|
|
use crate::json::{Json, ToJson};
|
2019-02-08 21:00:07 +09:00
|
|
|
use crate::spec::abi::{lookup as lookup_abi, Abi};
|
2020-04-29 20:47:07 +03:00
|
|
|
use crate::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
|
2021-02-07 23:47:03 +02:00
|
|
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
2022-06-18 10:48:46 +00:00
|
|
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
2020-07-25 19:02:49 +01:00
|
|
|
use rustc_span::symbol::{sym, Symbol};
|
2021-06-03 17:45:09 +02:00
|
|
|
use serde_json::Value;
|
2022-03-22 11:43:05 +01:00
|
|
|
use std::borrow::Cow;
|
2016-04-07 22:29:01 -05:00
|
|
|
use std::collections::BTreeMap;
|
2021-01-09 16:54:20 +02:00
|
|
|
use std::convert::TryFrom;
|
2022-06-18 10:48:46 +00:00
|
|
|
use std::hash::{Hash, Hasher};
|
2021-09-03 12:36:33 +02:00
|
|
|
use std::iter::FromIterator;
|
2020-11-08 14:27:51 +03:00
|
|
|
use std::ops::{Deref, DerefMut};
|
2018-03-14 15:27:06 +01:00
|
|
|
use std::path::{Path, PathBuf};
|
2017-12-08 17:07:47 +02:00
|
|
|
use std::str::FromStr;
|
2019-02-08 21:00:07 +09:00
|
|
|
use std::{fmt, io};
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2019-11-09 23:32:17 +01:00
|
|
|
use rustc_macros::HashStable_Generic;
|
|
|
|
|
2018-04-25 19:30:39 +03:00
|
|
|
pub mod abi;
|
2020-04-29 20:47:07 +03:00
|
|
|
pub mod crt_objects;
|
|
|
|
|
2015-04-29 10:53:01 -07:00
|
|
|
mod android_base;
|
2014-07-23 11:56:36 -07:00
|
|
|
mod apple_base;
|
2020-02-14 16:05:45 -08:00
|
|
|
mod apple_sdk_base;
|
2020-07-26 23:58:37 +12:00
|
|
|
mod avr_gnu_base;
|
2020-11-30 19:41:57 +00:00
|
|
|
mod bpf_base;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod dragonfly_base;
|
|
|
|
mod freebsd_base;
|
2016-10-18 13:43:18 -07:00
|
|
|
mod fuchsia_base;
|
2016-09-25 16:55:40 -05:00
|
|
|
mod haiku_base;
|
2018-07-30 15:50:51 +02:00
|
|
|
mod hermit_base;
|
2020-04-13 23:37:22 +00:00
|
|
|
mod illumos_base;
|
2017-08-03 10:37:11 +02:00
|
|
|
mod l4re_base;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod linux_base;
|
2020-11-10 23:32:58 +03:00
|
|
|
mod linux_gnu_base;
|
2019-08-31 15:13:16 -04:00
|
|
|
mod linux_kernel_base;
|
2016-05-01 17:41:28 -04:00
|
|
|
mod linux_musl_base;
|
2020-10-08 21:47:22 +03:00
|
|
|
mod linux_uclibc_base;
|
2020-04-11 17:30:09 +03:00
|
|
|
mod msvc_base;
|
2015-06-30 20:37:11 -07:00
|
|
|
mod netbsd_base;
|
2015-01-29 08:19:28 +01:00
|
|
|
mod openbsd_base;
|
2016-12-12 19:53:51 -07:00
|
|
|
mod redox_base;
|
2016-01-28 14:02:31 +03:00
|
|
|
mod solaris_base;
|
Add SOLID targets
SOLID[1] is an embedded development platform provided by Kyoto
Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support
for SOLID.
# New Targets
The following targets are added:
- `aarch64-kmc-solid_asp3`
- `armv7a-kmc-solid_asp3-eabi`
- `armv7a-kmc-solid_asp3-eabihf`
SOLID's target software system can be divided into two parts: an
RTOS kernel, which is responsible for threading and synchronization,
and Core Services, which provides filesystems, networking, and other
things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on
the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems
(more precisely, systems where only one processor core is allocated for
SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is
traditionally only specified at the source-code level, the ABI is
unique to each implementation, which is why `asp3` is included in the
target names.
More targets could be added later, as we support other base kernels
(there are at least three at the point of writing) and are interested
in supporting other processor architectures in the future.
# C Compiler
Although SOLID provides its own supported C/C++ build toolchain, GNU Arm
Embedded Toolchain seems to work for the purpose of building Rust.
# Unresolved Questions
A μITRON4 kernel can support `Thread::unpark` natively, but it's not
used by this commit's implementation because the underlying kernel
feature is also used to implement `Condvar`, and it's unclear whether
`std` should guarantee that parking tokens are not clobbered by other
synchronization primitives.
# Unsupported or Unimplemented Features
Most features are implemented. The following features are not
implemented due to the lack of native support:
- `fs::File::{file_attr, truncate, duplicate, set_permissions}`
- `fs::{symlink, link, canonicalize}`
- Process creation
- Command-line arguments
Backtrace generation is not really a good fit for embedded targets, so
it's intentionally left unimplemented. Unwinding is functional, however.
## Dynamic Linking
Dynamic linking is not supported. The target platform supports dynamic
linking, but enabling this in Rust causes several problems.
- The linker invocation used to build the shared object of `std` is
too long for the platform-provided linker to handle.
- A linker script with specific requirements is required for the
compiled shared object to be actually loadable.
As such, we decided to disable dynamic linking for now. Regardless, the
users can try to create shared objects by manually invoking the linker.
## Executable
Building an executable is not supported as the notion of "executable
files" isn't well-defined for these targets.
[1] https://solid.kmckk.com/SOLID/
[2] http://ertl.jp/ITRON/SPEC/mitron4-e.html
[3] https://en.wikipedia.org/wiki/ITRON_project
[4] https://toppers.jp/
2021-09-28 11:20:46 +09:00
|
|
|
mod solid_base;
|
2016-09-15 20:46:04 -05:00
|
|
|
mod thumb_base;
|
2020-04-11 16:04:18 +03:00
|
|
|
mod uefi_msvc_base;
|
2019-07-15 23:57:53 -07:00
|
|
|
mod vxworks_base;
|
2020-12-30 12:52:21 -06:00
|
|
|
mod wasm_base;
|
2020-04-11 16:04:18 +03:00
|
|
|
mod windows_gnu_base;
|
2022-03-06 15:12:50 +01:00
|
|
|
mod windows_gnullvm_base;
|
2015-05-08 14:44:17 -07:00
|
|
|
mod windows_msvc_base;
|
2020-04-11 16:04:18 +03:00
|
|
|
mod windows_uwp_gnu_base;
|
2019-07-31 15:00:34 +07:00
|
|
|
mod windows_uwp_msvc_base;
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2019-10-20 15:54:53 +11:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
2017-12-08 17:07:47 +02:00
|
|
|
pub enum LinkerFlavor {
|
|
|
|
Em,
|
|
|
|
Gcc,
|
2018-04-03 14:53:13 +02:00
|
|
|
L4Bender,
|
2017-12-08 17:07:47 +02:00
|
|
|
Ld,
|
|
|
|
Msvc,
|
|
|
|
Lld(LldFlavor),
|
2019-01-19 21:59:34 +01:00
|
|
|
PtxLinker,
|
2020-11-30 19:41:57 +00:00
|
|
|
BpfLinker,
|
2017-12-08 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
2019-10-20 15:54:53 +11:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
2017-12-08 17:07:47 +02:00
|
|
|
pub enum LldFlavor {
|
|
|
|
Wasm,
|
|
|
|
Ld64,
|
|
|
|
Ld,
|
|
|
|
Link,
|
|
|
|
}
|
|
|
|
|
2018-08-18 20:16:04 +02:00
|
|
|
impl LldFlavor {
|
2022-05-24 23:29:15 +03:00
|
|
|
pub fn as_str(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
LldFlavor::Wasm => "wasm",
|
|
|
|
LldFlavor::Ld64 => "darwin",
|
|
|
|
LldFlavor::Ld => "gnu",
|
|
|
|
LldFlavor::Link => "link",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 20:16:04 +02:00
|
|
|
fn from_str(s: &str) -> Option<Self> {
|
|
|
|
Some(match s {
|
|
|
|
"darwin" => LldFlavor::Ld64,
|
|
|
|
"gnu" => LldFlavor::Ld,
|
|
|
|
"link" => LldFlavor::Link,
|
|
|
|
"wasm" => LldFlavor::Wasm,
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for LldFlavor {
|
|
|
|
fn to_json(&self) -> Json {
|
2022-05-24 23:29:15 +03:00
|
|
|
self.as_str().to_json()
|
2018-08-18 20:16:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 17:07:47 +02:00
|
|
|
impl ToJson for LinkerFlavor {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
self.desc().to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
macro_rules! flavor_mappings {
|
|
|
|
($((($($flavor:tt)*), $string:expr),)*) => (
|
|
|
|
impl LinkerFlavor {
|
|
|
|
pub const fn one_of() -> &'static str {
|
2019-05-29 20:05:43 +02:00
|
|
|
concat!("one of: ", $($string, " ",)*)
|
2017-12-08 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(s: &str) -> Option<Self> {
|
|
|
|
Some(match s {
|
2019-05-29 20:05:43 +02:00
|
|
|
$($string => $($flavor)*,)*
|
2017-12-08 17:07:47 +02:00
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
2019-05-29 20:05:43 +02:00
|
|
|
$($($flavor)* => $string,)*
|
2017-12-08 17:07:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
flavor_mappings! {
|
|
|
|
((LinkerFlavor::Em), "em"),
|
|
|
|
((LinkerFlavor::Gcc), "gcc"),
|
2018-04-03 14:53:13 +02:00
|
|
|
((LinkerFlavor::L4Bender), "l4-bender"),
|
2017-12-08 17:07:47 +02:00
|
|
|
((LinkerFlavor::Ld), "ld"),
|
|
|
|
((LinkerFlavor::Msvc), "msvc"),
|
2019-01-19 21:59:34 +01:00
|
|
|
((LinkerFlavor::PtxLinker), "ptx-linker"),
|
2020-11-30 19:41:57 +00:00
|
|
|
((LinkerFlavor::BpfLinker), "bpf-linker"),
|
2017-12-08 17:07:47 +02:00
|
|
|
((LinkerFlavor::Lld(LldFlavor::Wasm)), "wasm-ld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Ld64)), "ld64.lld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Ld)), "ld.lld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"),
|
|
|
|
}
|
|
|
|
|
2020-06-11 15:49:57 +01:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)]
|
2017-12-08 17:07:47 +02:00
|
|
|
pub enum PanicStrategy {
|
|
|
|
Unwind,
|
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PanicStrategy {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
PanicStrategy::Unwind => "unwind",
|
|
|
|
PanicStrategy::Abort => "abort",
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 19:02:49 +01:00
|
|
|
|
2022-02-25 16:10:26 +01:00
|
|
|
pub const fn desc_symbol(&self) -> Symbol {
|
2020-07-25 19:02:49 +01:00
|
|
|
match *self {
|
|
|
|
PanicStrategy::Unwind => sym::unwind,
|
|
|
|
PanicStrategy::Abort => sym::abort,
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 16:10:26 +01:00
|
|
|
|
|
|
|
pub const fn all() -> [Symbol; 2] {
|
|
|
|
[Self::Abort.desc_symbol(), Self::Unwind.desc_symbol()]
|
|
|
|
}
|
2017-12-08 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for PanicStrategy {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
PanicStrategy::Abort => "abort".to_json(),
|
|
|
|
PanicStrategy::Unwind => "unwind".to_json(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:16:05 +02:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
|
2017-12-08 17:07:47 +02:00
|
|
|
pub enum RelroLevel {
|
|
|
|
Full,
|
|
|
|
Partial,
|
|
|
|
Off,
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RelroLevel {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
RelroLevel::Full => "full",
|
|
|
|
RelroLevel::Partial => "partial",
|
|
|
|
RelroLevel::Off => "off",
|
|
|
|
RelroLevel::None => "none",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for RelroLevel {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<RelroLevel, ()> {
|
|
|
|
match s {
|
|
|
|
"full" => Ok(RelroLevel::Full),
|
|
|
|
"partial" => Ok(RelroLevel::Partial),
|
|
|
|
"off" => Ok(RelroLevel::Off),
|
|
|
|
"none" => Ok(RelroLevel::None),
|
|
|
|
_ => Err(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for RelroLevel {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
RelroLevel::Full => "full".to_json(),
|
|
|
|
RelroLevel::Partial => "partial".to_json(),
|
|
|
|
RelroLevel::Off => "off".to_json(),
|
|
|
|
RelroLevel::None => "None".to_json(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 11:16:05 +02:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
|
2018-12-31 10:58:13 -08:00
|
|
|
pub enum MergeFunctions {
|
|
|
|
Disabled,
|
|
|
|
Trampolines,
|
|
|
|
Aliases,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MergeFunctions {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
MergeFunctions::Disabled => "disabled",
|
|
|
|
MergeFunctions::Trampolines => "trampolines",
|
|
|
|
MergeFunctions::Aliases => "aliases",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for MergeFunctions {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<MergeFunctions, ()> {
|
|
|
|
match s {
|
|
|
|
"disabled" => Ok(MergeFunctions::Disabled),
|
|
|
|
"trampolines" => Ok(MergeFunctions::Trampolines),
|
|
|
|
"aliases" => Ok(MergeFunctions::Aliases),
|
|
|
|
_ => Err(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for MergeFunctions {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
MergeFunctions::Disabled => "disabled".to_json(),
|
|
|
|
MergeFunctions::Trampolines => "trampolines".to_json(),
|
|
|
|
MergeFunctions::Aliases => "aliases".to_json(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 00:46:45 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
|
|
|
pub enum RelocModel {
|
|
|
|
Static,
|
|
|
|
Pic,
|
2021-09-10 15:11:56 +02:00
|
|
|
Pie,
|
2020-04-23 00:46:45 +03:00
|
|
|
DynamicNoPic,
|
|
|
|
Ropi,
|
|
|
|
Rwpi,
|
|
|
|
RopiRwpi,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for RelocModel {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<RelocModel, ()> {
|
|
|
|
Ok(match s {
|
|
|
|
"static" => RelocModel::Static,
|
|
|
|
"pic" => RelocModel::Pic,
|
2021-09-10 15:11:56 +02:00
|
|
|
"pie" => RelocModel::Pie,
|
2020-04-23 00:46:45 +03:00
|
|
|
"dynamic-no-pic" => RelocModel::DynamicNoPic,
|
|
|
|
"ropi" => RelocModel::Ropi,
|
|
|
|
"rwpi" => RelocModel::Rwpi,
|
|
|
|
"ropi-rwpi" => RelocModel::RopiRwpi,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for RelocModel {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
RelocModel::Static => "static",
|
|
|
|
RelocModel::Pic => "pic",
|
2021-09-10 15:11:56 +02:00
|
|
|
RelocModel::Pie => "pie",
|
2020-04-23 00:46:45 +03:00
|
|
|
RelocModel::DynamicNoPic => "dynamic-no-pic",
|
|
|
|
RelocModel::Ropi => "ropi",
|
|
|
|
RelocModel::Rwpi => "rwpi",
|
|
|
|
RelocModel::RopiRwpi => "ropi-rwpi",
|
|
|
|
}
|
|
|
|
.to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 03:34:27 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
|
|
|
pub enum CodeModel {
|
|
|
|
Tiny,
|
|
|
|
Small,
|
|
|
|
Kernel,
|
|
|
|
Medium,
|
|
|
|
Large,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for CodeModel {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<CodeModel, ()> {
|
|
|
|
Ok(match s {
|
2020-05-20 23:09:19 +03:00
|
|
|
"tiny" => CodeModel::Tiny,
|
2020-05-07 03:34:27 +03:00
|
|
|
"small" => CodeModel::Small,
|
|
|
|
"kernel" => CodeModel::Kernel,
|
|
|
|
"medium" => CodeModel::Medium,
|
|
|
|
"large" => CodeModel::Large,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for CodeModel {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
CodeModel::Tiny => "tiny",
|
|
|
|
CodeModel::Small => "small",
|
|
|
|
CodeModel::Kernel => "kernel",
|
|
|
|
CodeModel::Medium => "medium",
|
|
|
|
CodeModel::Large => "large",
|
|
|
|
}
|
|
|
|
.to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 21:45:21 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
|
|
|
pub enum TlsModel {
|
|
|
|
GeneralDynamic,
|
|
|
|
LocalDynamic,
|
|
|
|
InitialExec,
|
|
|
|
LocalExec,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for TlsModel {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<TlsModel, ()> {
|
|
|
|
Ok(match s {
|
|
|
|
// Note the difference "general" vs "global" difference. The model name is "general",
|
|
|
|
// but the user-facing option name is "global" for consistency with other compilers.
|
|
|
|
"global-dynamic" => TlsModel::GeneralDynamic,
|
|
|
|
"local-dynamic" => TlsModel::LocalDynamic,
|
|
|
|
"initial-exec" => TlsModel::InitialExec,
|
|
|
|
"local-exec" => TlsModel::LocalExec,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for TlsModel {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
TlsModel::GeneralDynamic => "global-dynamic",
|
|
|
|
TlsModel::LocalDynamic => "local-dynamic",
|
|
|
|
TlsModel::InitialExec => "initial-exec",
|
|
|
|
TlsModel::LocalExec => "local-exec",
|
|
|
|
}
|
|
|
|
.to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 20:47:07 +03:00
|
|
|
/// Everything is flattened to a single enum to make the json encoding/decoding less annoying.
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
|
|
|
pub enum LinkOutputKind {
|
|
|
|
/// Dynamically linked non position-independent executable.
|
|
|
|
DynamicNoPicExe,
|
|
|
|
/// Dynamically linked position-independent executable.
|
|
|
|
DynamicPicExe,
|
|
|
|
/// Statically linked non position-independent executable.
|
|
|
|
StaticNoPicExe,
|
|
|
|
/// Statically linked position-independent executable.
|
|
|
|
StaticPicExe,
|
|
|
|
/// Regular dynamic library ("dynamically linked").
|
|
|
|
DynamicDylib,
|
|
|
|
/// Dynamic library with bundled libc ("statically linked").
|
|
|
|
StaticDylib,
|
2020-12-12 21:38:23 -06:00
|
|
|
/// WASI module with a lifetime past the _initialize entry point
|
|
|
|
WasiReactorExe,
|
2020-04-29 20:47:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LinkOutputKind {
|
|
|
|
fn as_str(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
LinkOutputKind::DynamicNoPicExe => "dynamic-nopic-exe",
|
|
|
|
LinkOutputKind::DynamicPicExe => "dynamic-pic-exe",
|
|
|
|
LinkOutputKind::StaticNoPicExe => "static-nopic-exe",
|
|
|
|
LinkOutputKind::StaticPicExe => "static-pic-exe",
|
|
|
|
LinkOutputKind::DynamicDylib => "dynamic-dylib",
|
|
|
|
LinkOutputKind::StaticDylib => "static-dylib",
|
2020-12-12 21:38:23 -06:00
|
|
|
LinkOutputKind::WasiReactorExe => "wasi-reactor-exe",
|
2020-04-29 20:47:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn from_str(s: &str) -> Option<LinkOutputKind> {
|
|
|
|
Some(match s {
|
|
|
|
"dynamic-nopic-exe" => LinkOutputKind::DynamicNoPicExe,
|
|
|
|
"dynamic-pic-exe" => LinkOutputKind::DynamicPicExe,
|
|
|
|
"static-nopic-exe" => LinkOutputKind::StaticNoPicExe,
|
|
|
|
"static-pic-exe" => LinkOutputKind::StaticPicExe,
|
|
|
|
"dynamic-dylib" => LinkOutputKind::DynamicDylib,
|
|
|
|
"static-dylib" => LinkOutputKind::StaticDylib,
|
2020-12-12 21:38:23 -06:00
|
|
|
"wasi-reactor-exe" => LinkOutputKind::WasiReactorExe,
|
2020-04-29 20:47:07 +03:00
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for LinkOutputKind {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.write_str(self.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 18:42:39 +02:00
|
|
|
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<StaticCow<str>>>;
|
2016-07-24 11:47:39 -05:00
|
|
|
|
2020-11-30 08:39:08 -08:00
|
|
|
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
|
|
|
|
pub enum SplitDebuginfo {
|
|
|
|
/// Split debug-information is disabled, meaning that on supported platforms
|
|
|
|
/// you can find all debug information in the executable itself. This is
|
|
|
|
/// only supported for ELF effectively.
|
|
|
|
///
|
|
|
|
/// * Windows - not supported
|
|
|
|
/// * macOS - don't run `dsymutil`
|
|
|
|
/// * ELF - `.dwarf_*` sections
|
|
|
|
Off,
|
|
|
|
|
|
|
|
/// Split debug-information can be found in a "packed" location separate
|
|
|
|
/// from the final artifact. This is supported on all platforms.
|
|
|
|
///
|
|
|
|
/// * Windows - `*.pdb`
|
|
|
|
/// * macOS - `*.dSYM` (run `dsymutil`)
|
|
|
|
/// * ELF - `*.dwp` (run `rust-llvm-dwp`)
|
|
|
|
Packed,
|
|
|
|
|
|
|
|
/// Split debug-information can be found in individual object files on the
|
|
|
|
/// filesystem. The main executable may point to the object files.
|
|
|
|
///
|
|
|
|
/// * Windows - not supported
|
|
|
|
/// * macOS - supported, scattered object files
|
sess/cg: re-introduce split dwarf kind
In #79570, `-Z split-dwarf-kind={none,single,split}` was replaced by `-C
split-debuginfo={off,packed,unpacked}`. `-C split-debuginfo`'s packed
and unpacked aren't exact parallels to single and split, respectively.
On Unix, `-C split-debuginfo=packed` will put debuginfo into object
files and package debuginfo into a DWARF package file (`.dwp`) and
`-C split-debuginfo=unpacked` will put debuginfo into dwarf object files
and won't package it.
In the initial implementation of Split DWARF, split mode wrote sections
which did not require relocation into a DWARF object (`.dwo`) file which
was ignored by the linker and then packaged those DWARF objects into
DWARF packages (`.dwp`). In single mode, sections which did not require
relocation were written into object files but ignored by the linker and
were not packaged. However, both split and single modes could be
packaged or not, the primary difference in behaviour was where the
debuginfo sections that did not require link-time relocation were
written (in a DWARF object or the object file).
This commit re-introduces a `-Z split-dwarf-kind` flag, which can be
used to pick between split and single modes when `-C split-debuginfo` is
used to enable Split DWARF (either packed or unpacked).
Signed-off-by: David Wood <david.wood@huawei.com>
2021-10-08 16:10:17 +00:00
|
|
|
/// * ELF - supported, scattered `*.dwo` or `*.o` files (see `SplitDwarfKind`)
|
2020-11-30 08:39:08 -08:00
|
|
|
Unpacked,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SplitDebuginfo {
|
|
|
|
fn as_str(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
SplitDebuginfo::Off => "off",
|
|
|
|
SplitDebuginfo::Packed => "packed",
|
|
|
|
SplitDebuginfo::Unpacked => "unpacked",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for SplitDebuginfo {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<SplitDebuginfo, ()> {
|
|
|
|
Ok(match s {
|
|
|
|
"off" => SplitDebuginfo::Off,
|
|
|
|
"unpacked" => SplitDebuginfo::Unpacked,
|
|
|
|
"packed" => SplitDebuginfo::Packed,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for SplitDebuginfo {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
self.as_str().to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SplitDebuginfo {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.write_str(self.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 16:54:20 +02:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum StackProbeType {
|
|
|
|
/// Don't emit any stack probes.
|
|
|
|
None,
|
|
|
|
/// It is harmless to use this option even on targets that do not have backend support for
|
|
|
|
/// stack probes as the failure mode is the same as if no stack-probe option was specified in
|
|
|
|
/// the first place.
|
|
|
|
Inline,
|
|
|
|
/// Call `__rust_probestack` whenever stack needs to be probed.
|
|
|
|
Call,
|
|
|
|
/// Use inline option for LLVM versions later than specified in `min_llvm_version_for_inline`
|
|
|
|
/// and call `__rust_probestack` otherwise.
|
|
|
|
InlineOrCall { min_llvm_version_for_inline: (u32, u32, u32) },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StackProbeType {
|
|
|
|
fn from_json(json: &Json) -> Result<Self, String> {
|
|
|
|
let object = json.as_object().ok_or_else(|| "expected a JSON object")?;
|
|
|
|
let kind = object
|
|
|
|
.get("kind")
|
2021-06-03 17:45:09 +02:00
|
|
|
.and_then(|o| o.as_str())
|
2021-01-09 16:54:20 +02:00
|
|
|
.ok_or_else(|| "expected `kind` to be a string")?;
|
|
|
|
match kind {
|
|
|
|
"none" => Ok(StackProbeType::None),
|
|
|
|
"inline" => Ok(StackProbeType::Inline),
|
|
|
|
"call" => Ok(StackProbeType::Call),
|
|
|
|
"inline-or-call" => {
|
|
|
|
let min_version = object
|
|
|
|
.get("min-llvm-version-for-inline")
|
|
|
|
.and_then(|o| o.as_array())
|
|
|
|
.ok_or_else(|| "expected `min-llvm-version-for-inline` to be an array")?;
|
|
|
|
let mut iter = min_version.into_iter().map(|v| {
|
|
|
|
let int = v.as_u64().ok_or_else(
|
|
|
|
|| "expected `min-llvm-version-for-inline` values to be integers",
|
|
|
|
)?;
|
|
|
|
u32::try_from(int)
|
|
|
|
.map_err(|_| "`min-llvm-version-for-inline` values don't convert to u32")
|
|
|
|
});
|
|
|
|
let min_llvm_version_for_inline = (
|
|
|
|
iter.next().unwrap_or(Ok(11))?,
|
|
|
|
iter.next().unwrap_or(Ok(0))?,
|
|
|
|
iter.next().unwrap_or(Ok(0))?,
|
|
|
|
);
|
|
|
|
Ok(StackProbeType::InlineOrCall { min_llvm_version_for_inline })
|
|
|
|
}
|
|
|
|
_ => Err(String::from(
|
2021-02-11 20:33:16 +01:00
|
|
|
"`kind` expected to be one of `none`, `inline`, `call` or `inline-or-call`",
|
2021-01-09 16:54:20 +02:00
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for StackProbeType {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
Json::Object(match self {
|
|
|
|
StackProbeType::None => {
|
2021-12-17 18:36:18 +11:00
|
|
|
[(String::from("kind"), "none".to_json())].into_iter().collect()
|
2021-01-09 16:54:20 +02:00
|
|
|
}
|
|
|
|
StackProbeType::Inline => {
|
2021-12-17 18:36:18 +11:00
|
|
|
[(String::from("kind"), "inline".to_json())].into_iter().collect()
|
2021-01-09 16:54:20 +02:00
|
|
|
}
|
|
|
|
StackProbeType::Call => {
|
2021-12-17 18:36:18 +11:00
|
|
|
[(String::from("kind"), "call".to_json())].into_iter().collect()
|
2021-01-09 16:54:20 +02:00
|
|
|
}
|
2021-06-03 17:45:09 +02:00
|
|
|
StackProbeType::InlineOrCall { min_llvm_version_for_inline: (maj, min, patch) } => [
|
2021-01-09 16:54:20 +02:00
|
|
|
(String::from("kind"), "inline-or-call".to_json()),
|
|
|
|
(
|
|
|
|
String::from("min-llvm-version-for-inline"),
|
2021-06-03 17:45:09 +02:00
|
|
|
Json::Array(vec![maj.to_json(), min.to_json(), patch.to_json()]),
|
2021-01-09 16:54:20 +02:00
|
|
|
),
|
|
|
|
]
|
|
|
|
.into_iter()
|
|
|
|
.collect(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 23:47:03 +02:00
|
|
|
bitflags::bitflags! {
|
|
|
|
#[derive(Default, Encodable, Decodable)]
|
|
|
|
pub struct SanitizerSet: u8 {
|
|
|
|
const ADDRESS = 1 << 0;
|
|
|
|
const LEAK = 1 << 1;
|
|
|
|
const MEMORY = 1 << 2;
|
|
|
|
const THREAD = 1 << 3;
|
|
|
|
const HWADDRESS = 1 << 4;
|
2021-10-07 15:33:13 -07:00
|
|
|
const CFI = 1 << 5;
|
2021-12-03 16:11:13 -05:00
|
|
|
const MEMTAG = 1 << 6;
|
2021-02-07 23:47:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 22:00:07 +02:00
|
|
|
impl SanitizerSet {
|
|
|
|
/// Return sanitizer's name
|
|
|
|
///
|
|
|
|
/// Returns none if the flags is a set of sanitizers numbering not exactly one.
|
2022-02-25 16:10:26 +01:00
|
|
|
pub fn as_str(self) -> Option<&'static str> {
|
2021-02-13 22:00:07 +02:00
|
|
|
Some(match self {
|
|
|
|
SanitizerSet::ADDRESS => "address",
|
2021-10-07 15:33:13 -07:00
|
|
|
SanitizerSet::CFI => "cfi",
|
2021-02-13 22:00:07 +02:00
|
|
|
SanitizerSet::LEAK => "leak",
|
|
|
|
SanitizerSet::MEMORY => "memory",
|
2021-12-03 16:11:13 -05:00
|
|
|
SanitizerSet::MEMTAG => "memtag",
|
2021-02-13 22:00:07 +02:00
|
|
|
SanitizerSet::THREAD => "thread",
|
|
|
|
SanitizerSet::HWADDRESS => "hwaddress",
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 23:47:03 +02:00
|
|
|
/// Formats a sanitizer set as a comma separated list of sanitizers' names.
|
|
|
|
impl fmt::Display for SanitizerSet {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
let mut first = true;
|
|
|
|
for s in *self {
|
2021-02-13 22:00:07 +02:00
|
|
|
let name = s.as_str().unwrap_or_else(|| panic!("unrecognized sanitizer {:?}", s));
|
2021-02-07 23:47:03 +02:00
|
|
|
if !first {
|
2021-02-08 00:49:00 +02:00
|
|
|
f.write_str(", ")?;
|
2021-02-07 23:47:03 +02:00
|
|
|
}
|
|
|
|
f.write_str(name)?;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoIterator for SanitizerSet {
|
|
|
|
type Item = SanitizerSet;
|
|
|
|
type IntoIter = std::vec::IntoIter<SanitizerSet>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
2021-02-13 22:00:07 +02:00
|
|
|
[
|
|
|
|
SanitizerSet::ADDRESS,
|
2021-10-07 15:33:13 -07:00
|
|
|
SanitizerSet::CFI,
|
2021-02-13 22:00:07 +02:00
|
|
|
SanitizerSet::LEAK,
|
|
|
|
SanitizerSet::MEMORY,
|
2021-12-03 16:11:13 -05:00
|
|
|
SanitizerSet::MEMTAG,
|
2021-02-13 22:00:07 +02:00
|
|
|
SanitizerSet::THREAD,
|
|
|
|
SanitizerSet::HWADDRESS,
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.copied()
|
|
|
|
.filter(|&s| self.contains(s))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.into_iter()
|
2021-02-07 23:47:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<CTX> HashStable<CTX> for SanitizerSet {
|
|
|
|
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
|
|
|
self.bits().hash_stable(ctx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 22:00:07 +02:00
|
|
|
impl ToJson for SanitizerSet {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
self.into_iter()
|
|
|
|
.map(|v| Some(v.as_str()?.to_json()))
|
|
|
|
.collect::<Option<Vec<_>>>()
|
2021-08-31 00:54:48 +02:00
|
|
|
.unwrap_or_default()
|
2021-02-13 22:00:07 +02:00
|
|
|
.to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-26 23:53:35 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
|
|
|
pub enum FramePointer {
|
|
|
|
/// Forces the machine code generator to always preserve the frame pointers.
|
|
|
|
Always,
|
|
|
|
/// Forces the machine code generator to preserve the frame pointers except for the leaf
|
|
|
|
/// functions (i.e. those that don't call other functions).
|
|
|
|
NonLeaf,
|
|
|
|
/// Allows the machine code generator to omit the frame pointers.
|
|
|
|
///
|
|
|
|
/// This option does not guarantee that the frame pointers will be omitted.
|
|
|
|
MayOmit,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for FramePointer {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, ()> {
|
|
|
|
Ok(match s {
|
|
|
|
"always" => Self::Always,
|
|
|
|
"non-leaf" => Self::NonLeaf,
|
|
|
|
"may-omit" => Self::MayOmit,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for FramePointer {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
Self::Always => "always",
|
|
|
|
Self::NonLeaf => "non-leaf",
|
|
|
|
Self::MayOmit => "may-omit",
|
|
|
|
}
|
|
|
|
.to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
|
|
|
/// Controls use of stack canaries.
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, Eq)]
|
|
|
|
pub enum StackProtector {
|
|
|
|
/// Disable stack canary generation.
|
|
|
|
None,
|
|
|
|
|
|
|
|
/// On LLVM, mark all generated LLVM functions with the `ssp` attribute (see
|
|
|
|
/// llvm/docs/LangRef.rst). This triggers stack canary generation in
|
|
|
|
/// functions which contain an array of a byte-sized type with more than
|
|
|
|
/// eight elements.
|
|
|
|
Basic,
|
|
|
|
|
|
|
|
/// On LLVM, mark all generated LLVM functions with the `sspstrong`
|
|
|
|
/// attribute (see llvm/docs/LangRef.rst). This triggers stack canary
|
|
|
|
/// generation in functions which either contain an array, or which take
|
|
|
|
/// the address of a local variable.
|
|
|
|
Strong,
|
|
|
|
|
|
|
|
/// Generate stack canaries in all functions.
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StackProtector {
|
|
|
|
fn as_str(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
StackProtector::None => "none",
|
|
|
|
StackProtector::Basic => "basic",
|
|
|
|
StackProtector::Strong => "strong",
|
|
|
|
StackProtector::All => "all",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for StackProtector {
|
|
|
|
type Err = ();
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<StackProtector, ()> {
|
|
|
|
Ok(match s {
|
|
|
|
"none" => StackProtector::None,
|
|
|
|
"basic" => StackProtector::Basic,
|
|
|
|
"strong" => StackProtector::Strong,
|
|
|
|
"all" => StackProtector::All,
|
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for StackProtector {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.write_str(self.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 23:47:03 +02:00
|
|
|
macro_rules! supported_targets {
|
|
|
|
( $(($( $triple:literal, )+ $module:ident ),)+ ) => {
|
|
|
|
$(mod $module;)+
|
|
|
|
|
|
|
|
/// List of supported targets
|
|
|
|
pub const TARGETS: &[&str] = &[$($($triple),+),+];
|
|
|
|
|
|
|
|
fn load_builtin(target: &str) -> Option<Target> {
|
|
|
|
let mut t = match target {
|
|
|
|
$( $($triple)|+ => $module::target(), )+
|
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
t.is_builtin = true;
|
|
|
|
debug!("got builtin target: {:?}", t);
|
|
|
|
Some(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
mod tests_impl;
|
|
|
|
|
|
|
|
// Cannot put this into a separate file without duplication, make an exception.
|
|
|
|
$(
|
|
|
|
#[test] // `#[test]`
|
|
|
|
fn $module() {
|
|
|
|
tests_impl::test_target(super::$module::target());
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
supported_targets! {
|
|
|
|
("x86_64-unknown-linux-gnu", x86_64_unknown_linux_gnu),
|
2017-10-11 16:15:42 -03:00
|
|
|
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
|
2016-02-12 10:11:58 -05:00
|
|
|
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
|
2016-02-13 17:03:00 +01:00
|
|
|
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
|
2021-08-25 07:45:06 +00:00
|
|
|
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
|
2016-02-12 10:11:58 -05:00
|
|
|
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
|
2016-08-26 17:06:13 -05:00
|
|
|
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),
|
|
|
|
("mips64el-unknown-linux-gnuabi64", mips64el_unknown_linux_gnuabi64),
|
2019-03-05 23:28:15 +08:00
|
|
|
("mipsisa32r6-unknown-linux-gnu", mipsisa32r6_unknown_linux_gnu),
|
|
|
|
("mipsisa32r6el-unknown-linux-gnu", mipsisa32r6el_unknown_linux_gnu),
|
|
|
|
("mipsisa64r6-unknown-linux-gnuabi64", mipsisa64r6_unknown_linux_gnuabi64),
|
|
|
|
("mipsisa64r6el-unknown-linux-gnuabi64", mipsisa64r6el_unknown_linux_gnuabi64),
|
2016-02-12 10:11:58 -05:00
|
|
|
("mipsel-unknown-linux-gnu", mipsel_unknown_linux_gnu),
|
|
|
|
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
|
2018-02-23 22:18:40 +01:00
|
|
|
("powerpc-unknown-linux-gnuspe", powerpc_unknown_linux_gnuspe),
|
2018-09-10 01:35:35 +00:00
|
|
|
("powerpc-unknown-linux-musl", powerpc_unknown_linux_musl),
|
2016-02-12 10:11:58 -05:00
|
|
|
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
|
2018-08-07 21:59:15 -05:00
|
|
|
("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
|
2016-02-12 10:11:58 -05:00
|
|
|
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
|
2018-06-18 16:28:01 +00:00
|
|
|
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
|
2016-08-26 21:05:16 -05:00
|
|
|
("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
|
2021-02-16 00:46:14 +00:00
|
|
|
("s390x-unknown-linux-musl", s390x_unknown_linux_musl),
|
2018-02-17 15:48:05 +01:00
|
|
|
("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
|
2018-01-04 14:55:04 -02:00
|
|
|
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
|
2016-02-12 10:11:58 -05:00
|
|
|
("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),
|
|
|
|
("arm-unknown-linux-gnueabihf", arm_unknown_linux_gnueabihf),
|
2016-04-27 18:02:31 -07:00
|
|
|
("arm-unknown-linux-musleabi", arm_unknown_linux_musleabi),
|
|
|
|
("arm-unknown-linux-musleabihf", arm_unknown_linux_musleabihf),
|
2017-12-26 13:05:03 -02:00
|
|
|
("armv4t-unknown-linux-gnueabi", armv4t_unknown_linux_gnueabi),
|
2016-11-06 13:06:01 +01:00
|
|
|
("armv5te-unknown-linux-gnueabi", armv5te_unknown_linux_gnueabi),
|
2018-05-04 08:47:24 +02:00
|
|
|
("armv5te-unknown-linux-musleabi", armv5te_unknown_linux_musleabi),
|
2020-11-30 09:47:09 +01:00
|
|
|
("armv5te-unknown-linux-uclibceabi", armv5te_unknown_linux_uclibceabi),
|
2019-07-29 18:28:36 +03:00
|
|
|
("armv7-unknown-linux-gnueabi", armv7_unknown_linux_gnueabi),
|
2016-02-12 10:11:58 -05:00
|
|
|
("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf),
|
2018-06-04 11:44:30 +03:00
|
|
|
("thumbv7neon-unknown-linux-gnueabihf", thumbv7neon_unknown_linux_gnueabihf),
|
2019-11-04 21:48:22 -06:00
|
|
|
("thumbv7neon-unknown-linux-musleabihf", thumbv7neon_unknown_linux_musleabihf),
|
2019-07-29 18:28:36 +03:00
|
|
|
("armv7-unknown-linux-musleabi", armv7_unknown_linux_musleabi),
|
2016-04-27 18:02:31 -07:00
|
|
|
("armv7-unknown-linux-musleabihf", armv7_unknown_linux_musleabihf),
|
2016-02-12 10:11:58 -05:00
|
|
|
("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu),
|
2017-09-05 16:55:25 +00:00
|
|
|
("aarch64-unknown-linux-musl", aarch64_unknown_linux_musl),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl),
|
|
|
|
("i686-unknown-linux-musl", i686_unknown_linux_musl),
|
2018-01-04 14:55:04 -02:00
|
|
|
("i586-unknown-linux-musl", i586_unknown_linux_musl),
|
2016-02-12 10:11:58 -05:00
|
|
|
("mips-unknown-linux-musl", mips_unknown_linux_musl),
|
|
|
|
("mipsel-unknown-linux-musl", mipsel_unknown_linux_musl),
|
2019-07-28 11:46:47 +08:00
|
|
|
("mips64-unknown-linux-muslabi64", mips64_unknown_linux_muslabi64),
|
|
|
|
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
|
2018-08-10 12:01:18 -05:00
|
|
|
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),
|
2018-01-04 14:55:04 -02:00
|
|
|
|
2016-08-16 17:07:55 -05:00
|
|
|
("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
|
|
|
|
("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),
|
2016-02-12 10:11:58 -05:00
|
|
|
|
|
|
|
("i686-linux-android", i686_linux_android),
|
2017-04-20 14:02:42 -03:00
|
|
|
("x86_64-linux-android", x86_64_linux_android),
|
2016-02-12 10:11:58 -05:00
|
|
|
("arm-linux-androideabi", arm_linux_androideabi),
|
2016-05-05 01:08:14 +03:00
|
|
|
("armv7-linux-androideabi", armv7_linux_androideabi),
|
2018-06-04 11:44:30 +03:00
|
|
|
("thumbv7neon-linux-androideabi", thumbv7neon_linux_androideabi),
|
2016-02-12 10:11:58 -05:00
|
|
|
("aarch64-linux-android", aarch64_linux_android),
|
|
|
|
|
2020-10-11 18:01:32 -04:00
|
|
|
("x86_64-unknown-none-linuxkernel", x86_64_unknown_none_linuxkernel),
|
2019-08-31 15:13:16 -04:00
|
|
|
|
2017-01-25 21:09:18 +01:00
|
|
|
("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
|
2019-02-02 16:41:38 +01:00
|
|
|
("armv6-unknown-freebsd", armv6_unknown_freebsd),
|
|
|
|
("armv7-unknown-freebsd", armv7_unknown_freebsd),
|
2016-02-12 10:11:58 -05:00
|
|
|
("i686-unknown-freebsd", i686_unknown_freebsd),
|
2021-07-22 17:29:33 +02:00
|
|
|
("powerpc-unknown-freebsd", powerpc_unknown_freebsd),
|
2019-01-21 18:50:54 +01:00
|
|
|
("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd),
|
2021-03-27 17:02:06 +01:00
|
|
|
("powerpc64le-unknown-freebsd", powerpc64le_unknown_freebsd),
|
2021-11-27 07:23:55 +01:00
|
|
|
("riscv64gc-unknown-freebsd", riscv64gc_unknown_freebsd),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
|
|
|
|
|
|
|
|
("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly),
|
|
|
|
|
2018-05-12 09:45:35 +02:00
|
|
|
("aarch64-unknown-openbsd", aarch64_unknown_openbsd),
|
2016-11-29 18:49:09 +01:00
|
|
|
("i686-unknown-openbsd", i686_unknown_openbsd),
|
2019-08-15 15:34:23 +02:00
|
|
|
("sparc64-unknown-openbsd", sparc64_unknown_openbsd),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
|
2021-03-03 21:17:17 +01:00
|
|
|
("powerpc-unknown-openbsd", powerpc_unknown_openbsd),
|
2016-11-29 18:49:09 +01:00
|
|
|
|
2018-08-04 16:53:52 -05:00
|
|
|
("aarch64-unknown-netbsd", aarch64_unknown_netbsd),
|
2018-05-18 09:26:53 -05:00
|
|
|
("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf),
|
2018-05-18 09:26:53 -05:00
|
|
|
("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf),
|
2017-02-06 08:49:16 -06:00
|
|
|
("i686-unknown-netbsd", i686_unknown_netbsd),
|
2018-02-16 14:29:24 -06:00
|
|
|
("powerpc-unknown-netbsd", powerpc_unknown_netbsd),
|
2016-12-03 08:53:13 -06:00
|
|
|
("sparc64-unknown-netbsd", sparc64_unknown_netbsd),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
|
|
|
|
|
2016-09-30 13:17:22 -05:00
|
|
|
("i686-unknown-haiku", i686_unknown_haiku),
|
|
|
|
("x86_64-unknown-haiku", x86_64_unknown_haiku),
|
2016-09-24 23:38:56 -05:00
|
|
|
|
2020-07-11 14:50:03 -04:00
|
|
|
("aarch64-apple-darwin", aarch64_apple_darwin),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-apple-darwin", x86_64_apple_darwin),
|
|
|
|
("i686-apple-darwin", i686_apple_darwin),
|
|
|
|
|
2018-07-26 17:57:20 -07:00
|
|
|
("aarch64-fuchsia", aarch64_fuchsia),
|
|
|
|
("x86_64-fuchsia", x86_64_fuchsia),
|
2016-10-18 13:43:18 -07:00
|
|
|
|
2020-07-26 23:58:37 +12:00
|
|
|
("avr-unknown-gnu-atmega328", avr_unknown_gnu_atmega328),
|
2016-05-06 09:32:10 -04:00
|
|
|
|
2017-08-03 10:37:11 +02:00
|
|
|
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
|
|
|
|
|
2019-04-07 08:39:54 -06:00
|
|
|
("aarch64-unknown-redox", aarch64_unknown_redox),
|
2016-12-12 19:53:51 -07:00
|
|
|
("x86_64-unknown-redox", x86_64_unknown_redox),
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
("i386-apple-ios", i386_apple_ios),
|
|
|
|
("x86_64-apple-ios", x86_64_apple_ios),
|
|
|
|
("aarch64-apple-ios", aarch64_apple_ios),
|
|
|
|
("armv7-apple-ios", armv7_apple_ios),
|
|
|
|
("armv7s-apple-ios", armv7s_apple_ios),
|
2019-08-11 20:31:01 +02:00
|
|
|
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
|
2020-10-03 14:46:58 +02:00
|
|
|
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
|
2021-02-04 09:26:02 -05:00
|
|
|
("aarch64-apple-ios-sim", aarch64_apple_ios_sim),
|
2020-01-10 18:48:37 -08:00
|
|
|
("aarch64-apple-tvos", aarch64_apple_tvos),
|
|
|
|
("x86_64-apple-tvos", x86_64_apple_tvos),
|
2016-02-12 10:11:58 -05:00
|
|
|
|
2022-03-23 14:54:58 +00:00
|
|
|
("armv7k-apple-watchos", armv7k_apple_watchos),
|
|
|
|
("arm64_32-apple-watchos", arm64_32_apple_watchos),
|
|
|
|
("x86_64-apple-watchos-sim", x86_64_apple_watchos_sim),
|
|
|
|
("aarch64-apple-watchos-sim", aarch64_apple_watchos_sim),
|
|
|
|
|
2018-08-24 19:32:49 +02:00
|
|
|
("armebv7r-none-eabi", armebv7r_none_eabi),
|
2018-05-16 21:58:26 +02:00
|
|
|
("armebv7r-none-eabihf", armebv7r_none_eabihf),
|
2018-08-24 19:16:20 +02:00
|
|
|
("armv7r-none-eabi", armv7r_none_eabi),
|
2018-08-24 19:32:49 +02:00
|
|
|
("armv7r-none-eabihf", armv7r_none_eabihf),
|
2018-05-16 21:58:26 +02:00
|
|
|
|
2021-02-16 15:02:04 +01:00
|
|
|
("x86_64-pc-solaris", x86_64_pc_solaris),
|
|
|
|
("x86_64-sun-solaris", x86_64_sun_solaris),
|
2017-02-16 21:19:43 -08:00
|
|
|
("sparcv9-sun-solaris", sparcv9_sun_solaris),
|
2016-02-12 10:11:58 -05:00
|
|
|
|
2020-04-13 23:37:22 +00:00
|
|
|
("x86_64-unknown-illumos", x86_64_unknown_illumos),
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
|
|
|
|
("i686-pc-windows-gnu", i686_pc_windows_gnu),
|
2019-05-27 17:18:14 +02:00
|
|
|
("i686-uwp-windows-gnu", i686_uwp_windows_gnu),
|
|
|
|
("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu),
|
2016-02-12 10:11:58 -05:00
|
|
|
|
2022-03-06 15:12:50 +01:00
|
|
|
("aarch64-pc-windows-gnullvm", aarch64_pc_windows_gnullvm),
|
|
|
|
("x86_64-pc-windows-gnullvm", x86_64_pc_windows_gnullvm),
|
|
|
|
|
2018-07-16 16:38:56 -07:00
|
|
|
("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
|
2019-07-31 15:00:34 +07:00
|
|
|
("aarch64-uwp-windows-msvc", aarch64_uwp_windows_msvc),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
|
2019-07-31 15:00:34 +07:00
|
|
|
("x86_64-uwp-windows-msvc", x86_64_uwp_windows_msvc),
|
2016-02-12 10:11:58 -05:00
|
|
|
("i686-pc-windows-msvc", i686_pc_windows_msvc),
|
2019-07-31 15:00:34 +07:00
|
|
|
("i686-uwp-windows-msvc", i686_uwp_windows_msvc),
|
2016-03-03 17:23:00 -08:00
|
|
|
("i586-pc-windows-msvc", i586_pc_windows_msvc),
|
2018-06-26 09:44:19 -07:00
|
|
|
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
|
2020-05-12 16:33:41 +08:00
|
|
|
("thumbv7a-uwp-windows-msvc", thumbv7a_uwp_windows_msvc),
|
2016-02-12 10:11:58 -05:00
|
|
|
|
2016-09-06 00:41:50 +00:00
|
|
|
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
|
2016-09-15 20:46:04 -05:00
|
|
|
("wasm32-unknown-emscripten", wasm32_unknown_emscripten),
|
2017-10-22 20:01:00 -07:00
|
|
|
("wasm32-unknown-unknown", wasm32_unknown_unknown),
|
2019-04-30 19:37:25 -07:00
|
|
|
("wasm32-wasi", wasm32_wasi),
|
2020-12-30 12:52:21 -06:00
|
|
|
("wasm64-unknown-unknown", wasm64_unknown_unknown),
|
2016-09-15 20:46:04 -05:00
|
|
|
|
|
|
|
("thumbv6m-none-eabi", thumbv6m_none_eabi),
|
|
|
|
("thumbv7m-none-eabi", thumbv7m_none_eabi),
|
|
|
|
("thumbv7em-none-eabi", thumbv7em_none_eabi),
|
|
|
|
("thumbv7em-none-eabihf", thumbv7em_none_eabihf),
|
2018-10-19 04:51:02 +00:00
|
|
|
("thumbv8m.base-none-eabi", thumbv8m_base_none_eabi),
|
2018-11-13 15:00:51 +00:00
|
|
|
("thumbv8m.main-none-eabi", thumbv8m_main_none_eabi),
|
|
|
|
("thumbv8m.main-none-eabihf", thumbv8m_main_none_eabihf),
|
2017-07-06 15:15:44 -05:00
|
|
|
|
2020-01-15 16:39:08 +01:00
|
|
|
("armv7a-none-eabi", armv7a_none_eabi),
|
|
|
|
("armv7a-none-eabihf", armv7a_none_eabihf),
|
|
|
|
|
2017-07-06 15:15:44 -05:00
|
|
|
("msp430-none-elf", msp430_none_elf),
|
2017-12-22 09:37:02 +01:00
|
|
|
|
2018-07-30 15:50:51 +02:00
|
|
|
("aarch64-unknown-hermit", aarch64_unknown_hermit),
|
|
|
|
("x86_64-unknown-hermit", x86_64_unknown_hermit),
|
2020-10-11 18:01:32 -04:00
|
|
|
|
2019-07-18 18:37:23 +03:00
|
|
|
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
|
2022-02-07 12:49:03 -08:00
|
|
|
("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf),
|
2018-08-30 14:19:48 +02:00
|
|
|
("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
|
2021-07-29 20:18:22 +03:00
|
|
|
("riscv32imc-esp-espidf", riscv32imc_esp_espidf),
|
2018-07-26 14:01:24 +02:00
|
|
|
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
|
2022-05-31 16:15:40 +08:00
|
|
|
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
|
2020-07-07 13:35:55 -07:00
|
|
|
("riscv32gc-unknown-linux-gnu", riscv32gc_unknown_linux_gnu),
|
2021-02-16 16:18:53 -08:00
|
|
|
("riscv32gc-unknown-linux-musl", riscv32gc_unknown_linux_musl),
|
2019-02-12 19:05:41 +03:00
|
|
|
("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
|
2019-02-12 19:15:00 +03:00
|
|
|
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
|
2019-11-23 14:15:27 +07:00
|
|
|
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
|
2021-02-16 16:18:53 -08:00
|
|
|
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
|
2018-08-09 22:04:55 +02:00
|
|
|
|
|
|
|
("aarch64-unknown-none", aarch64_unknown_none),
|
2019-09-18 15:38:02 +02:00
|
|
|
("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
|
2018-11-19 15:05:28 +05:30
|
|
|
|
|
|
|
("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx),
|
Add x86_64-unknown-uefi target
This adds a new rustc target-configuration called 'x86_64-unknown_uefi'.
Furthermore, it adds a UEFI base-configuration to be used with other
targets supported by UEFI (e.g., i386, armv7hl, aarch64, itanium, ...).
UEFI systems provide a very basic operating-system environment, meant
to unify how systems are booted. It is tailored for simplicity and fast
setup, as it is only meant to bootstrap other systems. For instance, it
copies most of the ABI from Microsoft Windows, rather than inventing
anything on its own. Furthermore, any complex CPU features are
disabled. Only one CPU is allowed to be up, no interrupts other than
the timer-interrupt are allowed, no process-separation is performed,
page-tables are identity-mapped, ...
Nevertheless, UEFI has an application model. Its main purpose is to
allow operating-system vendors to write small UEFI applications that
load their kernel and terminate the UEFI system. However, many other
UEFI applications have emerged in the past, including network-boot,
debug-consoles, and more.
This UEFI target allows to compile rust code natively as UEFI
applications. No standard library support is added, but libcore can be
used out-of-the-box if a panic-handler is provided. Furthermore,
liballoc works as well, if a `GlobalAlloc` handler is provided. Both
have been tested with this target-configuration.
Note that full libstd support is unlikely to happen. While UEFI does
have standardized interfaces for networking and alike, none of these
are mandatory and they are unlikely to be shipped in common consumer
firmwares. Furthermore, several features like process-separation are
not available (or only in very limited fashion). Those parts of libstd
would have to be masked.
2018-12-13 10:08:20 +01:00
|
|
|
|
|
|
|
("x86_64-unknown-uefi", x86_64_unknown_uefi),
|
Add i686-unknown-uefi target
This adds a new rustc target-configuration called 'i686-unknown_uefi'.
This is similar to existing x86_64-unknown_uefi target.
The i686-unknown-uefi target can be used to build Intel Architecture
32bit UEFI application. The ABI defined in UEFI environment (aka IA32)
is similar to cdecl.
We choose i686-unknown-uefi-gnu instead of i686-unknown-uefi to avoid
the intrinsics generated by LLVM. The detail of root-cause and solution
analysis is added as comment in the code.
For x86_64-unknown-uefi, we cannot use -gnu, because the ABI between
MSVC and GNU is totally different, and UEFI chooses ABI similar to MSVC.
For i686-unknown-uefi, the UEFI chooses cdecl ABI, which is same as
MSVC and GNU. According to LLVM code, the only differences between MSVC
and GNU are fmodf(f32), longjmp() and TLS, which have no impact to UEFI.
As such, using i686-unknown-uefi-gnu is the simplest way to pass the build.
Adding the undefined symbols, such as _aulldiv() to rust compiler-builtins
is out of scope. But it may be considered later.
The scope of this patch is limited to support target-configuration.
No standard library support is added in this patch. Such work can be
done in future enhancement.
Cc: Josh Triplett <josh.triplett@intel.com>
Reviewed-by: Josh Triplett <josh.triplett@intel.com>
2019-08-29 11:44:37 +08:00
|
|
|
("i686-unknown-uefi", i686_unknown_uefi),
|
2021-05-16 13:28:16 +10:00
|
|
|
("aarch64-unknown-uefi", aarch64_unknown_uefi),
|
2019-01-19 21:59:34 +01:00
|
|
|
|
|
|
|
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),
|
2019-07-15 23:57:53 -07:00
|
|
|
|
|
|
|
("i686-wrs-vxworks", i686_wrs_vxworks),
|
2019-08-12 10:46:57 -07:00
|
|
|
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
|
|
|
|
("armv7-wrs-vxworks-eabihf", armv7_wrs_vxworks_eabihf),
|
2019-07-15 23:57:53 -07:00
|
|
|
("aarch64-wrs-vxworks", aarch64_wrs_vxworks),
|
|
|
|
("powerpc-wrs-vxworks", powerpc_wrs_vxworks),
|
|
|
|
("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe),
|
|
|
|
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),
|
2020-05-09 15:41:49 -04:00
|
|
|
|
Add SOLID targets
SOLID[1] is an embedded development platform provided by Kyoto
Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support
for SOLID.
# New Targets
The following targets are added:
- `aarch64-kmc-solid_asp3`
- `armv7a-kmc-solid_asp3-eabi`
- `armv7a-kmc-solid_asp3-eabihf`
SOLID's target software system can be divided into two parts: an
RTOS kernel, which is responsible for threading and synchronization,
and Core Services, which provides filesystems, networking, and other
things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on
the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems
(more precisely, systems where only one processor core is allocated for
SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is
traditionally only specified at the source-code level, the ABI is
unique to each implementation, which is why `asp3` is included in the
target names.
More targets could be added later, as we support other base kernels
(there are at least three at the point of writing) and are interested
in supporting other processor architectures in the future.
# C Compiler
Although SOLID provides its own supported C/C++ build toolchain, GNU Arm
Embedded Toolchain seems to work for the purpose of building Rust.
# Unresolved Questions
A μITRON4 kernel can support `Thread::unpark` natively, but it's not
used by this commit's implementation because the underlying kernel
feature is also used to implement `Condvar`, and it's unclear whether
`std` should guarantee that parking tokens are not clobbered by other
synchronization primitives.
# Unsupported or Unimplemented Features
Most features are implemented. The following features are not
implemented due to the lack of native support:
- `fs::File::{file_attr, truncate, duplicate, set_permissions}`
- `fs::{symlink, link, canonicalize}`
- Process creation
- Command-line arguments
Backtrace generation is not really a good fit for embedded targets, so
it's intentionally left unimplemented. Unwinding is functional, however.
## Dynamic Linking
Dynamic linking is not supported. The target platform supports dynamic
linking, but enabling this in Rust causes several problems.
- The linker invocation used to build the shared object of `std` is
too long for the platform-provided linker to handle.
- A linker script with specific requirements is required for the
compiled shared object to be actually loadable.
As such, we decided to disable dynamic linking for now. Regardless, the
users can try to create shared objects by manually invoking the linker.
## Executable
Building an executable is not supported as the notion of "executable
files" isn't well-defined for these targets.
[1] https://solid.kmckk.com/SOLID/
[2] http://ertl.jp/ITRON/SPEC/mitron4-e.html
[3] https://en.wikipedia.org/wiki/ITRON_project
[4] https://toppers.jp/
2021-09-28 11:20:46 +09:00
|
|
|
("aarch64-kmc-solid_asp3", aarch64_kmc_solid_asp3),
|
|
|
|
("armv7a-kmc-solid_asp3-eabi", armv7a_kmc_solid_asp3_eabi),
|
|
|
|
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),
|
|
|
|
|
2020-05-09 15:41:49 -04:00
|
|
|
("mipsel-sony-psp", mipsel_sony_psp),
|
2020-11-02 19:11:24 +01:00
|
|
|
("mipsel-unknown-none", mipsel_unknown_none),
|
2020-07-17 18:59:24 -06:00
|
|
|
("thumbv4t-none-eabi", thumbv4t_none_eabi),
|
2021-01-20 17:13:49 +00:00
|
|
|
|
|
|
|
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
|
|
|
|
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),
|
|
|
|
("aarch64_be-unknown-linux-gnu_ilp32", aarch64_be_unknown_linux_gnu_ilp32),
|
2020-11-30 19:41:57 +00:00
|
|
|
|
|
|
|
("bpfeb-unknown-none", bpfeb_unknown_none),
|
|
|
|
("bpfel-unknown-none", bpfel_unknown_none),
|
2021-08-31 13:23:59 +02:00
|
|
|
|
|
|
|
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
|
2021-09-14 20:50:35 -04:00
|
|
|
|
2022-02-01 14:52:59 -07:00
|
|
|
("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
|
2021-09-14 20:50:35 -04:00
|
|
|
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),
|
2021-09-17 23:03:59 -06:00
|
|
|
|
2021-09-19 12:05:58 -07:00
|
|
|
("x86_64-unknown-none", x86_64_unknown_none),
|
2022-01-31 03:03:06 -05:00
|
|
|
|
|
|
|
("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
|
2016-02-12 10:11:58 -05:00
|
|
|
}
|
|
|
|
|
2022-03-28 01:08:17 +02:00
|
|
|
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
|
|
|
|
macro_rules! cvs {
|
|
|
|
() => {
|
|
|
|
::std::borrow::Cow::Borrowed(&[])
|
|
|
|
};
|
|
|
|
($($x:expr),+ $(,)?) => {
|
2022-04-03 18:42:39 +02:00
|
|
|
::std::borrow::Cow::Borrowed(&[
|
|
|
|
$(
|
|
|
|
::std::borrow::Cow::Borrowed($x),
|
|
|
|
)*
|
|
|
|
])
|
2022-03-28 01:08:17 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) use cvs;
|
|
|
|
|
2021-05-27 10:21:53 +02:00
|
|
|
/// Warnings encountered when parsing the target `json`.
|
|
|
|
///
|
|
|
|
/// Includes fields that weren't recognized and fields that don't have the expected type.
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct TargetWarnings {
|
|
|
|
unused_fields: Vec<String>,
|
|
|
|
incorrect_type: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetWarnings {
|
|
|
|
pub fn empty() -> Self {
|
|
|
|
Self { unused_fields: Vec::new(), incorrect_type: Vec::new() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn warning_messages(&self) -> Vec<String> {
|
|
|
|
let mut warnings = vec![];
|
|
|
|
if !self.unused_fields.is_empty() {
|
|
|
|
warnings.push(format!(
|
|
|
|
"target json file contains unused fields: {}",
|
|
|
|
self.unused_fields.join(", ")
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if !self.incorrect_type.is_empty() {
|
|
|
|
warnings.push(format!(
|
|
|
|
"target json file contains fields whose value doesn't have the correct json type: {}",
|
|
|
|
self.incorrect_type.join(", ")
|
|
|
|
));
|
|
|
|
}
|
|
|
|
warnings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Everything `rustc` knows about how to compile for a specific target.
|
|
|
|
///
|
|
|
|
/// Every field here must be specified, and has no default value.
|
2016-07-23 07:22:58 -05:00
|
|
|
#[derive(PartialEq, Clone, Debug)]
|
2014-07-23 11:56:36 -07:00
|
|
|
pub struct Target {
|
|
|
|
/// Target triple to pass to LLVM.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub llvm_target: StaticCow<str>,
|
2020-10-14 18:22:10 +02:00
|
|
|
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
|
|
|
|
pub pointer_width: u32,
|
2019-07-01 17:31:52 -04:00
|
|
|
/// Architecture to use for ABI considerations. Valid options include: "x86",
|
|
|
|
/// "x86_64", "arm", "aarch64", "mips", "powerpc", "powerpc64", and others.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub arch: StaticCow<str>,
|
2021-06-23 16:26:46 -04:00
|
|
|
/// [Data layout](https://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub data_layout: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Optional settings with defaults.
|
|
|
|
pub options: TargetOptions,
|
|
|
|
}
|
|
|
|
|
2018-11-03 22:57:53 +02:00
|
|
|
pub trait HasTargetSpec {
|
2018-04-18 16:01:26 +03:00
|
|
|
fn target_spec(&self) -> &Target;
|
|
|
|
}
|
|
|
|
|
2018-11-03 22:57:53 +02:00
|
|
|
impl HasTargetSpec for Target {
|
2021-06-01 00:00:00 +00:00
|
|
|
#[inline]
|
2018-04-18 16:01:26 +03:00
|
|
|
fn target_spec(&self) -> &Target {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 18:42:39 +02:00
|
|
|
type StaticCow<T> = Cow<'static, T>;
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Optional aspects of a target specification.
|
|
|
|
///
|
|
|
|
/// This has an implementation of `Default`, see each field for what the default is. In general,
|
|
|
|
/// these try to take "minimal defaults" that don't assume anything about the runtime they run in.
|
2020-11-08 14:27:51 +03:00
|
|
|
///
|
|
|
|
/// `TargetOptions` as a separate structure is mostly an implementation detail of `Target`
|
|
|
|
/// construction, all its fields logically belong to `Target` and available from `Target`
|
|
|
|
/// through `Deref` impls.
|
2016-07-23 07:22:58 -05:00
|
|
|
#[derive(PartialEq, Clone, Debug)]
|
2014-07-23 11:56:36 -07:00
|
|
|
pub struct TargetOptions {
|
2016-04-18 15:38:45 +03:00
|
|
|
/// Whether the target is built-in or loaded from a custom target specification.
|
|
|
|
pub is_builtin: bool,
|
|
|
|
|
2021-01-05 01:01:29 +00:00
|
|
|
/// Used as the `target_endian` `cfg` variable. Defaults to little endian.
|
|
|
|
pub endian: Endian,
|
2020-10-08 19:57:41 +03:00
|
|
|
/// Width of c_int type. Defaults to "32".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub c_int_width: StaticCow<str>,
|
2020-11-11 20:40:51 +03:00
|
|
|
/// OS name to use for conditional compilation (`target_os`). Defaults to "none".
|
2020-11-11 20:10:15 +03:00
|
|
|
/// "none" implies a bare metal target without `std` library.
|
|
|
|
/// A couple of targets having `std` also use "unknown" as an `os` value,
|
|
|
|
/// but they are exceptions.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub os: StaticCow<str>,
|
2020-11-11 20:40:51 +03:00
|
|
|
/// Environment name to use for conditional compilation (`target_env`). Defaults to "".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub env: StaticCow<str>,
|
2021-07-06 20:54:54 -07:00
|
|
|
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
|
|
|
|
/// or `"eabihf"`. Defaults to "".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub abi: StaticCow<str>,
|
2020-11-11 20:40:51 +03:00
|
|
|
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub vendor: StaticCow<str>,
|
2020-10-08 22:22:28 +03:00
|
|
|
/// Default linker flavor used if `-C linker-flavor` or `-C linker` are not passed
|
|
|
|
/// on the command line. Defaults to `LinkerFlavor::Gcc`.
|
|
|
|
pub linker_flavor: LinkerFlavor,
|
2020-10-08 19:36:11 +03:00
|
|
|
|
2018-02-10 12:09:25 -08:00
|
|
|
/// Linker to invoke
|
2022-04-03 18:42:39 +02:00
|
|
|
pub linker: Option<StaticCow<str>>,
|
2015-10-18 14:32:50 -07:00
|
|
|
|
2020-04-11 02:52:34 +03:00
|
|
|
/// LLD flavor used if `lld` (or `rust-lld`) is specified as a linker
|
|
|
|
/// without clarifying its flavor in any way.
|
2018-08-18 16:31:36 +02:00
|
|
|
pub lld_flavor: LldFlavor,
|
|
|
|
|
2018-04-29 11:17:54 +02:00
|
|
|
/// Linker arguments that are passed *before* any user-defined libraries.
|
2020-05-30 17:03:50 +03:00
|
|
|
pub pre_link_args: LinkArgs,
|
2020-04-29 20:47:07 +03:00
|
|
|
/// Objects to link before and after all other object code.
|
|
|
|
pub pre_link_objects: CrtObjects,
|
|
|
|
pub post_link_objects: CrtObjects,
|
|
|
|
/// Same as `(pre|post)_link_objects`, but when we fail to pull the objects with help of the
|
|
|
|
/// target's native gcc and fall back to the "self-contained" mode and pull them manually.
|
|
|
|
/// See `crt_objects.rs` for some more detailed documentation.
|
|
|
|
pub pre_link_objects_fallback: CrtObjects,
|
|
|
|
pub post_link_objects_fallback: CrtObjects,
|
|
|
|
/// Which logic to use to determine whether to fall back to the "self-contained" mode or not.
|
|
|
|
pub crt_objects_fallback: Option<CrtObjectsFallback>,
|
|
|
|
|
2015-10-18 14:32:50 -07:00
|
|
|
/// Linker arguments that are unconditionally passed after any
|
2020-04-29 20:47:07 +03:00
|
|
|
/// user-defined but before post-link objects. Standard platform
|
2015-10-18 14:32:50 -07:00
|
|
|
/// libraries that should be always be linked to, usually go here.
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
pub late_link_args: LinkArgs,
|
2020-03-03 20:41:37 +00:00
|
|
|
/// Linker arguments used in addition to `late_link_args` if at least one
|
|
|
|
/// Rust dependency is dynamically linked.
|
|
|
|
pub late_link_args_dynamic: LinkArgs,
|
2022-03-30 15:14:15 -04:00
|
|
|
/// Linker arguments used in addition to `late_link_args` if all Rust
|
2020-03-03 20:41:37 +00:00
|
|
|
/// dependencies are statically linked.
|
|
|
|
pub late_link_args_static: LinkArgs,
|
2015-04-21 18:00:16 -07:00
|
|
|
/// Linker arguments that are unconditionally passed *after* any
|
|
|
|
/// user-defined libraries.
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
pub post_link_args: LinkArgs,
|
2020-05-10 17:39:57 -04:00
|
|
|
/// Optional link script applied to `dylib` and `executable` crate types.
|
|
|
|
/// This is a string containing the script, not a path. Can only be applied
|
|
|
|
/// to linkers where `linker_is_gnu` is true.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub link_script: Option<StaticCow<str>>,
|
2015-10-18 14:32:50 -07:00
|
|
|
|
2019-09-12 13:47:17 +03:00
|
|
|
/// Environment variables to be set for the linker invocation.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub link_env: StaticCow<[(StaticCow<str>, StaticCow<str>)]>,
|
2019-09-12 13:47:17 +03:00
|
|
|
/// Environment variables to be removed for the linker invocation.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub link_env_remove: StaticCow<[StaticCow<str>]>,
|
2017-06-22 15:16:54 -07:00
|
|
|
|
2016-12-18 22:25:46 -05:00
|
|
|
/// Extra arguments to pass to the external assembler (when used)
|
2022-04-03 18:42:39 +02:00
|
|
|
pub asm_args: StaticCow<[StaticCow<str>]>,
|
2016-12-18 22:25:46 -05:00
|
|
|
|
2015-04-21 18:00:16 -07:00
|
|
|
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
|
2016-05-05 14:23:43 +02:00
|
|
|
/// to "generic".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub cpu: StaticCow<str>,
|
2015-04-21 18:00:16 -07:00
|
|
|
/// Default target features to pass to LLVM. These features will *always* be
|
|
|
|
/// passed, and cannot be disabled even via `-C`. Corresponds to `llc
|
|
|
|
/// -mattr=$features`.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub features: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Whether dynamic linking is available on this target. Defaults to false.
|
|
|
|
pub dynamic_linking: bool,
|
2017-10-22 20:01:00 -07:00
|
|
|
/// If dynamic linking is available, whether only cdylibs are supported.
|
|
|
|
pub only_cdylib: bool,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Whether executables are available on this target. iOS, for example, only allows static
|
|
|
|
/// libraries. Defaults to false.
|
|
|
|
pub executables: bool,
|
|
|
|
/// Relocation model to use in object file. Corresponds to `llc
|
2020-04-23 00:46:45 +03:00
|
|
|
/// -relocation-model=$relocation_model`. Defaults to `Pic`.
|
|
|
|
pub relocation_model: RelocModel,
|
2018-01-22 17:01:36 -08:00
|
|
|
/// Code model to use. Corresponds to `llc -code-model=$code_model`.
|
2020-05-07 03:34:27 +03:00
|
|
|
/// Defaults to `None` which means "inherited from the base LLVM target".
|
|
|
|
pub code_model: Option<CodeModel>,
|
2017-10-31 17:45:19 +00:00
|
|
|
/// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec"
|
|
|
|
/// and "local-exec". This is similar to the -ftls-model option in GCC/Clang.
|
2020-04-25 21:45:21 +03:00
|
|
|
pub tls_model: TlsModel,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Do not emit code that uses the "red zone", if the ABI has one. Defaults to false.
|
|
|
|
pub disable_redzone: bool,
|
2021-06-26 23:53:35 +03:00
|
|
|
/// Frame pointer mode for this target. Defaults to `MayOmit`.
|
|
|
|
pub frame_pointer: FramePointer,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Emit each function in its own section. Defaults to true.
|
|
|
|
pub function_sections: bool,
|
|
|
|
/// String to prepend to the name of every dynamic library. Defaults to "lib".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub dll_prefix: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// String to append to the name of every dynamic library. Defaults to ".so".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub dll_suffix: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// String to append to the name of every executable.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub exe_suffix: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// String to prepend to the name of every static library. Defaults to "lib".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub staticlib_prefix: StaticCow<str>,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// String to append to the name of every static library. Defaults to ".a".
|
2022-04-03 18:42:39 +02:00
|
|
|
pub staticlib_suffix: StaticCow<str>,
|
2021-04-10 23:22:58 +03:00
|
|
|
/// Values of the `target_family` cfg set for this target.
|
|
|
|
///
|
|
|
|
/// Common options are: "unix", "windows". Defaults to no families.
|
|
|
|
///
|
2021-04-10 23:28:58 +03:00
|
|
|
/// See <https://doc.rust-lang.org/reference/conditional-compilation.html#target_family>.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub families: StaticCow<[StaticCow<str>]>,
|
2018-02-26 10:20:14 -08:00
|
|
|
/// Whether the target toolchain's ABI supports returning small structs as an integer.
|
|
|
|
pub abi_return_struct_as_int: bool,
|
2017-03-12 14:13:35 -04:00
|
|
|
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
|
|
|
|
/// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
|
2014-07-23 11:56:36 -07:00
|
|
|
pub is_like_osx: bool,
|
2016-01-21 19:30:22 +03:00
|
|
|
/// Whether the target toolchain is like Solaris's.
|
|
|
|
/// Only useful for compiling against Illumos/Solaris,
|
|
|
|
/// as they have a different set of linker flags. Defaults to false.
|
2016-01-28 14:02:31 +03:00
|
|
|
pub is_like_solaris: bool,
|
2020-11-12 00:54:23 +03:00
|
|
|
/// Whether the target is like Windows.
|
|
|
|
/// This is a combination of several more specific properties represented as a single flag:
|
|
|
|
/// - The target uses a Windows ABI,
|
|
|
|
/// - uses PE/COFF as a format for object code,
|
|
|
|
/// - uses Windows-style dllexport/dllimport for shared libraries,
|
|
|
|
/// - uses import libraries and .def files for symbol exports,
|
|
|
|
/// - executables support setting a subsystem.
|
2014-07-23 11:56:36 -07:00
|
|
|
pub is_like_windows: bool,
|
2020-11-12 00:54:23 +03:00
|
|
|
/// Whether the target is like MSVC.
|
|
|
|
/// This is a combination of several more specific properties represented as a single flag:
|
|
|
|
/// - The target has all the properties from `is_like_windows`
|
|
|
|
/// (for in-tree targets "is_like_msvc ⇒ is_like_windows" is ensured by a unit test),
|
|
|
|
/// - has some MSVC-specific Windows ABI properties,
|
|
|
|
/// - uses a link.exe-like linker,
|
|
|
|
/// - uses CodeView/PDB for debuginfo and natvis for its visualization,
|
|
|
|
/// - uses SEH-based unwinding,
|
|
|
|
/// - supports control flow guard mechanism.
|
2015-03-04 22:58:59 +00:00
|
|
|
pub is_like_msvc: bool,
|
2020-12-30 12:52:21 -06:00
|
|
|
/// Whether a target toolchain is like WASM.
|
|
|
|
pub is_like_wasm: bool,
|
2020-10-09 15:08:18 -04:00
|
|
|
/// Version of DWARF to use if not using the default.
|
|
|
|
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
|
|
|
|
pub dwarf_version: Option<u32>,
|
2021-05-20 16:38:40 -07:00
|
|
|
/// Whether the linker support GNU-like arguments such as -O. Defaults to true.
|
2014-07-23 11:56:36 -07:00
|
|
|
pub linker_is_gnu: bool,
|
2016-07-13 17:03:02 -04:00
|
|
|
/// The MinGW toolchain has a known issue that prevents it from correctly
|
2017-12-31 17:17:01 +01:00
|
|
|
/// handling COFF object files with more than 2<sup>15</sup> sections. Since each weak
|
2016-07-13 17:03:02 -04:00
|
|
|
/// symbol needs its own COMDAT section, weak linkage implies a large
|
|
|
|
/// number sections that easily exceeds the given limit for larger
|
2022-03-30 17:28:19 -04:00
|
|
|
/// codebases. Consequently we want a way to disallow weak linkage on some
|
2016-07-13 17:03:02 -04:00
|
|
|
/// platforms.
|
|
|
|
pub allows_weak_linkage: bool,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Whether the linker support rpaths or not. Defaults to false.
|
|
|
|
pub has_rpath: bool,
|
2015-09-21 19:02:46 +02:00
|
|
|
/// Whether to disable linking to the default libraries, typically corresponds
|
|
|
|
/// to `-nodefaultlibs`. Defaults to true.
|
|
|
|
pub no_default_libraries: bool,
|
2015-05-11 14:41:27 -07:00
|
|
|
/// 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
|
|
|
|
/// the functions in the executable are not randomized and can be used
|
|
|
|
/// during an exploit of a vulnerability in any code.
|
2014-11-06 00:17:56 -05:00
|
|
|
pub position_independent_executables: bool,
|
2020-05-02 01:59:35 +03:00
|
|
|
/// Executables that are both statically linked and position-independent are supported.
|
|
|
|
pub static_position_independent_executables: bool,
|
2018-09-26 19:19:55 +03:00
|
|
|
/// Determines if the target always requires using the PLT for indirect
|
|
|
|
/// library calls or not. This controls the default value of the `-Z plt` flag.
|
|
|
|
pub needs_plt: bool,
|
2017-07-14 22:01:37 +02:00
|
|
|
/// Either partial, full, or off. Full RELRO makes the dynamic linker
|
|
|
|
/// resolve all symbols at startup and marks the GOT read-only before
|
|
|
|
/// starting the program, preventing overwriting the GOT.
|
|
|
|
pub relro_level: RelroLevel,
|
trans: Use LLVM's writeArchive to modify archives
We have previously always relied upon an external tool, `ar`, to modify archives
that the compiler produces (staticlibs, rlibs, etc). This approach, however, has
a number of downsides:
* Spawning a process is relatively expensive for small compilations
* Encoding arguments across process boundaries often incurs unnecessary overhead
or lossiness. For example `ar` has a tough time dealing with files that have
the same name in archives, and the compiler copies many files around to ensure
they can be passed to `ar` in a reasonable fashion.
* Most `ar` programs found do **not** have the ability to target arbitrary
platforms, so this is an extra tool which needs to be found/specified when
cross compiling.
The LLVM project has had a tool called `llvm-ar` for quite some time now, but it
wasn't available in the standard LLVM libraries (it was just a standalone
program). Recently, however, in LLVM 3.7, this functionality has been moved to a
library and is now accessible by consumers of LLVM via the `writeArchive`
function.
This commit migrates our archive bindings to no longer invoke `ar` by default
but instead make a library call to LLVM to do various operations. This solves
all of the downsides listed above:
* Archive management is now much faster, for example creating a "hello world"
staticlib is now 6x faster (50ms => 8ms). Linking dynamic libraries also
recently started requiring modification of rlibs, and linking a hello world
dynamic library is now 2x faster.
* The compiler is now one step closer to "hassle free" cross compilation because
no external tool is needed for managing archives, LLVM does the right thing!
This commit does not remove support for calling a system `ar` utility currently.
We will continue to maintain compatibility with LLVM 3.5 and 3.6 looking forward
(so the system LLVM can be used wherever possible), and in these cases we must
shell out to a system utility. All nightly builds of Rust, however, will stop
needing a system `ar`.
2015-07-09 00:14:20 -07:00
|
|
|
/// Format that archives should be emitted in. This affects whether we use
|
|
|
|
/// LLVM to assemble an archive or fall back to the system linker, and
|
|
|
|
/// currently only "gnu" is used to fall into LLVM. Unknown strings cause
|
|
|
|
/// the system linker to be used.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub archive_format: StaticCow<str>,
|
2015-08-20 17:47:21 -05:00
|
|
|
/// Is asm!() allowed? Defaults to true.
|
|
|
|
pub allow_asm: bool,
|
2019-10-17 16:09:32 -07:00
|
|
|
/// Whether the runtime startup code requires the `main` function be passed
|
|
|
|
/// `argc` and `argv` values.
|
|
|
|
pub main_needs_argc_argv: bool,
|
2015-06-25 10:07:01 -07:00
|
|
|
|
2021-12-17 20:56:38 +00:00
|
|
|
/// Flag indicating whether #[thread_local] is available for this target.
|
|
|
|
pub has_thread_local: bool,
|
2015-11-27 19:44:33 +00:00
|
|
|
// This is mainly for easy compatibility with emscripten.
|
|
|
|
// If we give emcc .o files that are actually .bc files it
|
|
|
|
// will 'just work'.
|
|
|
|
pub obj_is_bitcode: bool,
|
2020-05-07 12:26:18 +10:00
|
|
|
/// Whether the target requires that emitted object code includes bitcode.
|
|
|
|
pub forces_embed_bitcode: bool,
|
2020-05-07 15:34:31 +10:00
|
|
|
/// Content of the LLVM cmdline section associated with embedded bitcode.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub bitcode_llvm_cmdline: StaticCow<str>,
|
2016-04-15 20:16:19 +01:00
|
|
|
|
2016-08-15 09:46:44 +00:00
|
|
|
/// Don't use this field; instead use the `.min_atomic_width()` method.
|
|
|
|
pub min_atomic_width: Option<u64>,
|
|
|
|
|
2016-10-03 23:45:40 -05:00
|
|
|
/// Don't use this field; instead use the `.max_atomic_width()` method.
|
|
|
|
pub max_atomic_width: Option<u64>,
|
2016-09-27 21:26:08 -05:00
|
|
|
|
2018-06-30 14:56:08 -05:00
|
|
|
/// Whether the target supports atomic CAS operations natively
|
|
|
|
pub atomic_cas: bool,
|
|
|
|
|
2016-09-27 21:26:08 -05:00
|
|
|
/// Panic strategy: "unwind" or "abort"
|
|
|
|
pub panic_strategy: PanicStrategy,
|
2016-10-24 11:04:04 +02:00
|
|
|
|
2017-08-22 16:24:29 -05:00
|
|
|
/// Whether or not linking dylibs to a static CRT is allowed.
|
|
|
|
pub crt_static_allows_dylibs: bool,
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 16:40:13 -07:00
|
|
|
/// Whether or not the CRT is statically linked by default.
|
|
|
|
pub crt_static_default: bool,
|
2017-08-22 16:24:29 -05:00
|
|
|
/// Whether or not crt-static is respected by the compiler (or is a no-op).
|
|
|
|
pub crt_static_respected: bool,
|
2017-06-21 12:08:18 -07:00
|
|
|
|
2021-01-09 16:54:20 +02:00
|
|
|
/// The implementation of stack probes to use.
|
|
|
|
pub stack_probes: StackProbeType,
|
2017-09-08 14:49:51 -07:00
|
|
|
|
|
|
|
/// The minimum alignment for global symbols.
|
|
|
|
pub min_global_align: Option<u64>,
|
2017-10-04 14:38:52 -07:00
|
|
|
|
|
|
|
/// Default number of codegen units to use in debug mode
|
|
|
|
pub default_codegen_units: Option<u64>,
|
2017-11-11 07:08:00 -08:00
|
|
|
|
|
|
|
/// Whether to generate trap instructions in places where optimization would
|
|
|
|
/// otherwise produce control flow that falls through into unrelated memory.
|
|
|
|
pub trap_unreachable: bool,
|
2017-10-22 20:01:00 -07:00
|
|
|
|
|
|
|
/// This target requires everything to be compiled with LTO to emit a final
|
|
|
|
/// executable, aka there is no native linker for this target.
|
|
|
|
pub requires_lto: bool,
|
|
|
|
|
|
|
|
/// This target has no support for threads.
|
|
|
|
pub singlethread: bool,
|
|
|
|
|
|
|
|
/// Whether library functions call lowering/optimization is disabled in LLVM
|
|
|
|
/// for this target unconditionally.
|
|
|
|
pub no_builtins: bool,
|
2017-12-03 21:53:48 -08:00
|
|
|
|
2018-01-30 11:54:07 -08:00
|
|
|
/// The default visibility for symbols in this target should be "hidden"
|
|
|
|
/// rather than "default"
|
|
|
|
pub default_hidden_visibility: bool,
|
2018-03-09 07:25:54 -08:00
|
|
|
|
2018-04-06 15:40:43 +02:00
|
|
|
/// Whether a .debug_gdb_scripts section will be added to the output object file
|
|
|
|
pub emit_debug_gdb_scripts: bool,
|
2018-04-19 15:17:34 -07:00
|
|
|
|
|
|
|
/// Whether or not to unconditionally `uwtable` attributes on functions,
|
|
|
|
/// typically because the platform needs to unwind for things like stack
|
|
|
|
/// unwinders.
|
|
|
|
pub requires_uwtable: bool,
|
2018-10-12 17:04:31 -07:00
|
|
|
|
2021-03-23 02:38:30 +08:00
|
|
|
/// Whether or not to emit `uwtable` attributes on functions if `-C force-unwind-tables`
|
|
|
|
/// is not specified and `uwtable` is not required on this target.
|
|
|
|
pub default_uwtable: bool,
|
|
|
|
|
2018-10-12 17:04:31 -07:00
|
|
|
/// Whether or not SIMD types are passed by reference in the Rust ABI,
|
|
|
|
/// typically required if a target can be compiled with a mixed set of
|
|
|
|
/// target features. This is `true` by default, and `false` for targets like
|
|
|
|
/// wasm32 where the whole program either has simd or not.
|
|
|
|
pub simd_types_indirect: bool,
|
2018-11-19 15:04:28 +05:30
|
|
|
|
2019-04-14 19:05:21 +02:00
|
|
|
/// Pass a list of symbol which should be exported in the dylib to the linker.
|
|
|
|
pub limit_rdylib_exports: bool,
|
|
|
|
|
2018-11-19 15:04:28 +05:30
|
|
|
/// If set, have the linker export exactly these symbols, instead of using
|
|
|
|
/// the usual logic to figure this out from the crate itself.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub override_export_symbols: Option<StaticCow<[StaticCow<str>]>>,
|
2018-12-31 10:58:13 -08:00
|
|
|
|
|
|
|
/// Determines how or whether the MergeFunctions LLVM pass should run for
|
|
|
|
/// this target. Either "disabled", "trampolines", or "aliases".
|
|
|
|
/// The MergeFunctions pass is generally useful, but some targets may need
|
|
|
|
/// to opt out. The default is "aliases".
|
|
|
|
///
|
2020-10-14 17:35:43 +02:00
|
|
|
/// Workaround for: <https://github.com/rust-lang/rust/issues/57356>
|
2019-03-30 18:50:19 +09:00
|
|
|
pub merge_functions: MergeFunctions,
|
|
|
|
|
|
|
|
/// Use platform dependent mcount function
|
2022-04-03 18:42:39 +02:00
|
|
|
pub mcount: StaticCow<str>,
|
2019-10-29 21:12:05 -07:00
|
|
|
|
|
|
|
/// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
|
2022-04-03 18:42:39 +02:00
|
|
|
pub llvm_abiname: StaticCow<str>,
|
2019-12-02 17:52:45 +05:30
|
|
|
|
|
|
|
/// Whether or not RelaxElfRelocation flag will be passed to the linker
|
|
|
|
pub relax_elf_relocations: bool,
|
2020-01-09 16:40:40 +01:00
|
|
|
|
|
|
|
/// Additional arguments to pass to LLVM, similar to the `-C llvm-args` codegen option.
|
2022-04-03 18:42:39 +02:00
|
|
|
pub llvm_args: StaticCow<[StaticCow<str>]>,
|
2020-04-16 19:40:11 -07:00
|
|
|
|
|
|
|
/// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults
|
|
|
|
/// to false (uses .init_array).
|
|
|
|
pub use_ctors_section: bool,
|
2020-07-22 15:49:04 +03:00
|
|
|
|
|
|
|
/// Whether the linker is instructed to add a `GNU_EH_FRAME` ELF header
|
|
|
|
/// used to locate unwinding information is passed
|
|
|
|
/// (only has effect if the linker is `ld`-like).
|
|
|
|
pub eh_frame_header: bool,
|
2020-10-08 23:23:27 +01:00
|
|
|
|
|
|
|
/// Is true if the target is an ARM architecture using thumb v1 which allows for
|
|
|
|
/// thumb and arm interworking.
|
|
|
|
pub has_thumb_interworking: bool,
|
2020-11-30 08:39:08 -08:00
|
|
|
|
|
|
|
/// How to handle split debug information, if at all. Specifying `None` has
|
|
|
|
/// target-specific meaning.
|
|
|
|
pub split_debuginfo: SplitDebuginfo,
|
2021-02-08 00:49:00 +02:00
|
|
|
|
|
|
|
/// The sanitizers supported by this target
|
|
|
|
///
|
|
|
|
/// Note that the support here is at a codegen level. If the machine code with sanitizer
|
|
|
|
/// enabled can generated on this target, but the necessary supporting libraries are not
|
|
|
|
/// distributed with the target, the sanitizer should still appear in this list for the target.
|
|
|
|
pub supported_sanitizers: SanitizerSet,
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
|
|
|
|
/// If present it's a default value to use for adjusting the C ABI.
|
|
|
|
pub default_adjusted_cabi: Option<Abi>,
|
2021-08-10 18:34:13 +00:00
|
|
|
|
|
|
|
/// Minimum number of bits in #[repr(C)] enum. Defaults to 32.
|
|
|
|
pub c_enum_min_bits: u64,
|
2021-11-10 10:47:00 -08:00
|
|
|
|
|
|
|
/// Whether or not the DWARF `.debug_aranges` section should be generated.
|
|
|
|
pub generate_arange_section: bool,
|
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
|
|
|
|
|
|
|
/// Whether the target supports stack canary checks. `true` by default,
|
|
|
|
/// since this is most common among tier 1 and tier 2 targets.
|
|
|
|
pub supports_stack_protector: bool,
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
|
2022-06-17 17:38:42 +03:00
|
|
|
/// Add arguments for the given flavor and also for its "twin" flavors
|
|
|
|
/// that have a compatible command line interface.
|
|
|
|
fn add_link_args(link_args: &mut LinkArgs, flavor: LinkerFlavor, args: &[&'static str]) {
|
|
|
|
let mut insert = |flavor| {
|
|
|
|
link_args.entry(flavor).or_default().extend(args.iter().copied().map(Cow::Borrowed))
|
|
|
|
};
|
|
|
|
insert(flavor);
|
|
|
|
match flavor {
|
|
|
|
LinkerFlavor::Ld => insert(LinkerFlavor::Lld(LldFlavor::Ld)),
|
|
|
|
LinkerFlavor::Msvc => insert(LinkerFlavor::Lld(LldFlavor::Link)),
|
|
|
|
LinkerFlavor::Lld(LldFlavor::Wasm) => {}
|
|
|
|
LinkerFlavor::Lld(lld_flavor) => {
|
|
|
|
panic!("add_link_args: use non-LLD flavor for {:?}", lld_flavor)
|
|
|
|
}
|
|
|
|
LinkerFlavor::Gcc
|
|
|
|
| LinkerFlavor::Em
|
|
|
|
| LinkerFlavor::L4Bender
|
|
|
|
| LinkerFlavor::BpfLinker
|
|
|
|
| LinkerFlavor::PtxLinker => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetOptions {
|
|
|
|
fn link_args(flavor: LinkerFlavor, args: &[&'static str]) -> LinkArgs {
|
|
|
|
let mut link_args = LinkArgs::new();
|
|
|
|
add_link_args(&mut link_args, flavor, args);
|
|
|
|
link_args
|
|
|
|
}
|
|
|
|
|
|
|
|
fn add_pre_link_args(&mut self, flavor: LinkerFlavor, args: &[&'static str]) {
|
|
|
|
add_link_args(&mut self.pre_link_args, flavor, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn add_post_link_args(&mut self, flavor: LinkerFlavor, args: &[&'static str]) {
|
|
|
|
add_link_args(&mut self.post_link_args, flavor, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
impl Default for TargetOptions {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates a set of "sane defaults" for any target. This is still
|
2015-05-11 14:41:27 -07:00
|
|
|
/// incomplete, and if used for compilation, will certainly not work.
|
2014-07-23 11:56:36 -07:00
|
|
|
fn default() -> TargetOptions {
|
|
|
|
TargetOptions {
|
2016-04-18 15:38:45 +03:00
|
|
|
is_builtin: false,
|
2021-01-05 01:01:29 +00:00
|
|
|
endian: Endian::Little,
|
2022-03-22 11:43:05 +01:00
|
|
|
c_int_width: "32".into(),
|
|
|
|
os: "none".into(),
|
2022-04-03 18:42:39 +02:00
|
|
|
env: "".into(),
|
|
|
|
abi: "".into(),
|
2022-03-22 11:43:05 +01:00
|
|
|
vendor: "unknown".into(),
|
2020-10-08 22:22:28 +03:00
|
|
|
linker_flavor: LinkerFlavor::Gcc,
|
2022-03-22 11:43:05 +01:00
|
|
|
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.into()),
|
2018-08-18 16:31:36 +02:00
|
|
|
lld_flavor: LldFlavor::Ld,
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
pre_link_args: LinkArgs::new(),
|
|
|
|
post_link_args: LinkArgs::new(),
|
2020-05-10 17:39:57 -04:00
|
|
|
link_script: None,
|
2022-04-03 18:42:39 +02:00
|
|
|
asm_args: cvs![],
|
2022-03-22 11:43:05 +01:00
|
|
|
cpu: "generic".into(),
|
2022-04-03 18:42:39 +02:00
|
|
|
features: "".into(),
|
2014-07-23 11:56:36 -07:00
|
|
|
dynamic_linking: false,
|
2017-10-22 20:01:00 -07:00
|
|
|
only_cdylib: false,
|
2014-07-23 11:56:36 -07:00
|
|
|
executables: false,
|
2020-04-23 00:46:45 +03:00
|
|
|
relocation_model: RelocModel::Pic,
|
2018-01-22 17:01:36 -08:00
|
|
|
code_model: None,
|
2020-04-25 21:45:21 +03:00
|
|
|
tls_model: TlsModel::GeneralDynamic,
|
2014-07-23 11:56:36 -07:00
|
|
|
disable_redzone: false,
|
2021-06-26 23:53:35 +03:00
|
|
|
frame_pointer: FramePointer::MayOmit,
|
2014-07-23 11:56:36 -07:00
|
|
|
function_sections: true,
|
2022-03-22 11:43:05 +01:00
|
|
|
dll_prefix: "lib".into(),
|
|
|
|
dll_suffix: ".so".into(),
|
2022-04-03 18:42:39 +02:00
|
|
|
exe_suffix: "".into(),
|
2022-03-22 11:43:05 +01:00
|
|
|
staticlib_prefix: "lib".into(),
|
|
|
|
staticlib_suffix: ".a".into(),
|
2022-03-28 01:08:17 +02:00
|
|
|
families: cvs![],
|
2018-02-26 10:20:14 -08:00
|
|
|
abi_return_struct_as_int: false,
|
2014-07-23 11:56:36 -07:00
|
|
|
is_like_osx: false,
|
2016-01-28 14:02:31 +03:00
|
|
|
is_like_solaris: false,
|
2014-07-23 11:56:36 -07:00
|
|
|
is_like_windows: false,
|
2015-03-04 22:58:59 +00:00
|
|
|
is_like_msvc: false,
|
2020-12-30 12:52:21 -06:00
|
|
|
is_like_wasm: false,
|
2020-10-09 15:08:18 -04:00
|
|
|
dwarf_version: None,
|
2021-05-20 16:38:40 -07:00
|
|
|
linker_is_gnu: true,
|
2016-07-13 17:03:02 -04:00
|
|
|
allows_weak_linkage: true,
|
2014-07-23 11:56:36 -07:00
|
|
|
has_rpath: false,
|
2015-09-21 19:02:46 +02:00
|
|
|
no_default_libraries: true,
|
2014-11-06 00:17:56 -05:00
|
|
|
position_independent_executables: false,
|
2020-05-02 01:59:35 +03:00
|
|
|
static_position_independent_executables: false,
|
2018-09-26 19:19:55 +03:00
|
|
|
needs_plt: false,
|
2018-03-09 14:53:15 +01:00
|
|
|
relro_level: RelroLevel::None,
|
2020-04-29 20:47:07 +03:00
|
|
|
pre_link_objects: Default::default(),
|
|
|
|
post_link_objects: Default::default(),
|
|
|
|
pre_link_objects_fallback: Default::default(),
|
|
|
|
post_link_objects_fallback: Default::default(),
|
|
|
|
crt_objects_fallback: None,
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
late_link_args: LinkArgs::new(),
|
2020-03-03 20:41:37 +00:00
|
|
|
late_link_args_dynamic: LinkArgs::new(),
|
|
|
|
late_link_args_static: LinkArgs::new(),
|
2022-04-03 18:42:39 +02:00
|
|
|
link_env: cvs![],
|
|
|
|
link_env_remove: cvs![],
|
2022-03-22 11:43:05 +01:00
|
|
|
archive_format: "gnu".into(),
|
2019-10-17 16:09:32 -07:00
|
|
|
main_needs_argc_argv: true,
|
2015-08-20 17:47:21 -05:00
|
|
|
allow_asm: true,
|
2021-12-17 20:56:38 +00:00
|
|
|
has_thread_local: false,
|
2015-11-27 19:44:33 +00:00
|
|
|
obj_is_bitcode: false,
|
2020-05-07 12:26:18 +10:00
|
|
|
forces_embed_bitcode: false,
|
2022-04-03 18:42:39 +02:00
|
|
|
bitcode_llvm_cmdline: "".into(),
|
2016-08-15 09:46:44 +00:00
|
|
|
min_atomic_width: None,
|
2016-10-03 23:45:40 -05:00
|
|
|
max_atomic_width: None,
|
2018-06-30 14:56:08 -05:00
|
|
|
atomic_cas: true,
|
2016-09-27 21:26:08 -05:00
|
|
|
panic_strategy: PanicStrategy::Unwind,
|
2017-08-22 16:24:29 -05:00
|
|
|
crt_static_allows_dylibs: false,
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 16:40:13 -07:00
|
|
|
crt_static_default: false,
|
2017-08-22 16:24:29 -05:00
|
|
|
crt_static_respected: false,
|
2021-01-09 16:54:20 +02:00
|
|
|
stack_probes: StackProbeType::None,
|
2017-09-08 14:49:51 -07:00
|
|
|
min_global_align: None,
|
2017-10-04 14:38:52 -07:00
|
|
|
default_codegen_units: None,
|
2017-11-11 07:08:00 -08:00
|
|
|
trap_unreachable: true,
|
2017-10-22 20:01:00 -07:00
|
|
|
requires_lto: false,
|
|
|
|
singlethread: false,
|
|
|
|
no_builtins: false,
|
2018-01-30 11:54:07 -08:00
|
|
|
default_hidden_visibility: false,
|
2018-04-06 15:40:43 +02:00
|
|
|
emit_debug_gdb_scripts: true,
|
2018-04-19 15:17:34 -07:00
|
|
|
requires_uwtable: false,
|
2021-03-23 02:38:30 +08:00
|
|
|
default_uwtable: false,
|
2018-10-12 17:04:31 -07:00
|
|
|
simd_types_indirect: true,
|
2019-04-14 19:05:21 +02:00
|
|
|
limit_rdylib_exports: true,
|
2018-11-19 15:04:28 +05:30
|
|
|
override_export_symbols: None,
|
2018-12-31 10:58:13 -08:00
|
|
|
merge_functions: MergeFunctions::Aliases,
|
2022-03-22 11:43:05 +01:00
|
|
|
mcount: "mcount".into(),
|
|
|
|
llvm_abiname: "".into(),
|
2019-12-02 17:52:45 +05:30
|
|
|
relax_elf_relocations: false,
|
2022-03-28 01:08:17 +02:00
|
|
|
llvm_args: cvs![],
|
2020-04-16 19:40:11 -07:00
|
|
|
use_ctors_section: false,
|
2020-07-22 15:49:04 +03:00
|
|
|
eh_frame_header: true,
|
2020-10-08 23:23:27 +01:00
|
|
|
has_thumb_interworking: false,
|
2020-11-30 08:39:08 -08:00
|
|
|
split_debuginfo: SplitDebuginfo::Off,
|
2021-02-08 00:49:00 +02:00
|
|
|
supported_sanitizers: SanitizerSet::empty(),
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
default_adjusted_cabi: None,
|
2021-08-10 18:34:13 +00:00
|
|
|
c_enum_min_bits: 32,
|
2021-11-10 10:47:00 -08:00
|
|
|
generate_arange_section: true,
|
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
|
|
|
supports_stack_protector: true,
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 19:36:11 +03:00
|
|
|
/// `TargetOptions` being a separate type is basically an implementation detail of `Target` that is
|
|
|
|
/// used for providing defaults. Perhaps there's a way to merge `TargetOptions` into `Target` so
|
|
|
|
/// this `Deref` implementation is no longer necessary.
|
|
|
|
impl Deref for Target {
|
|
|
|
type Target = TargetOptions;
|
|
|
|
|
2022-02-12 00:00:00 +00:00
|
|
|
#[inline]
|
2020-10-08 19:36:11 +03:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.options
|
|
|
|
}
|
|
|
|
}
|
2020-11-08 14:27:51 +03:00
|
|
|
impl DerefMut for Target {
|
2022-02-12 00:00:00 +00:00
|
|
|
#[inline]
|
2020-11-08 14:27:51 +03:00
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.options
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 19:36:11 +03:00
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
impl Target {
|
2018-09-25 16:37:31 -04:00
|
|
|
/// Given a function ABI, turn it into the correct ABI for this target.
|
2016-02-05 13:13:36 +01:00
|
|
|
pub fn adjust_abi(&self, abi: Abi) -> Abi {
|
2014-07-23 11:56:36 -07:00
|
|
|
match abi {
|
2021-06-11 14:22:13 +03:00
|
|
|
Abi::C { .. } => self.default_adjusted_cabi.unwrap_or(abi),
|
|
|
|
Abi::System { unwind } if self.is_like_windows && self.arch == "x86" => {
|
|
|
|
Abi::Stdcall { unwind }
|
2019-10-24 15:29:29 +00:00
|
|
|
}
|
2021-06-11 14:22:13 +03:00
|
|
|
Abi::System { unwind } => Abi::C { unwind },
|
2022-02-01 18:53:45 +01:00
|
|
|
Abi::EfiApi if self.arch == "x86_64" => Abi::Win64 { unwind: false },
|
2021-06-11 14:22:13 +03:00
|
|
|
Abi::EfiApi => Abi::C { unwind: false },
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
|
2021-06-11 14:22:13 +03:00
|
|
|
// See commentary in `is_abi_supported`.
|
|
|
|
Abi::Stdcall { .. } | Abi::Thiscall { .. } if self.arch == "x86" => abi,
|
|
|
|
Abi::Stdcall { unwind } | Abi::Thiscall { unwind } => Abi::C { unwind },
|
2022-02-01 18:53:45 +01:00
|
|
|
Abi::Fastcall { .. } if self.arch == "x86" => abi,
|
|
|
|
Abi::Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => abi,
|
|
|
|
Abi::Fastcall { unwind } | Abi::Vectorcall { unwind } => Abi::C { unwind },
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
abi => abi,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 14:22:13 +03:00
|
|
|
/// Returns a None if the UNSUPPORTED_CALLING_CONVENTIONS lint should be emitted
|
|
|
|
pub fn is_abi_supported(&self, abi: Abi) -> Option<bool> {
|
|
|
|
use Abi::*;
|
|
|
|
Some(match abi {
|
|
|
|
Rust
|
|
|
|
| C { .. }
|
|
|
|
| System { .. }
|
|
|
|
| RustIntrinsic
|
|
|
|
| RustCall
|
|
|
|
| PlatformIntrinsic
|
|
|
|
| Unadjusted
|
2022-02-01 18:53:45 +01:00
|
|
|
| Cdecl { .. }
|
2022-05-29 00:25:14 -07:00
|
|
|
| EfiApi
|
|
|
|
| RustCold => true,
|
2021-06-11 14:22:13 +03:00
|
|
|
X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]),
|
2022-02-01 18:53:45 +01:00
|
|
|
Aapcs { .. } => "arm" == self.arch,
|
2021-08-27 19:36:18 +03:00
|
|
|
CCmseNonSecureCall => ["arm", "aarch64"].contains(&&self.arch[..]),
|
2022-02-01 18:53:45 +01:00
|
|
|
Win64 { .. } | SysV64 { .. } => self.arch == "x86_64",
|
2021-06-11 14:22:13 +03:00
|
|
|
PtxKernel => self.arch == "nvptx64",
|
|
|
|
Msp430Interrupt => self.arch == "msp430",
|
|
|
|
AmdGpuKernel => self.arch == "amdgcn",
|
|
|
|
AvrInterrupt | AvrNonBlockingInterrupt => self.arch == "avr",
|
|
|
|
Wasm => ["wasm32", "wasm64"].contains(&&self.arch[..]),
|
2021-10-24 11:57:45 -07:00
|
|
|
Thiscall { .. } => self.arch == "x86",
|
2021-06-11 14:22:13 +03:00
|
|
|
// On windows these fall-back to platform native calling convention (C) when the
|
|
|
|
// architecture is not supported.
|
|
|
|
//
|
|
|
|
// This is I believe a historical accident that has occurred as part of Microsoft
|
|
|
|
// striving to allow most of the code to "just" compile when support for 64-bit x86
|
|
|
|
// was added and then later again, when support for ARM architectures was added.
|
|
|
|
//
|
|
|
|
// This is well documented across MSDN. Support for this in Rust has been added in
|
|
|
|
// #54576. This makes much more sense in context of Microsoft's C++ than it does in
|
|
|
|
// Rust, but there isn't much leeway remaining here to change it back at the time this
|
|
|
|
// comment has been written.
|
|
|
|
//
|
|
|
|
// Following are the relevant excerpts from the MSDN documentation.
|
|
|
|
//
|
|
|
|
// > The __vectorcall calling convention is only supported in native code on x86 and
|
|
|
|
// x64 processors that include Streaming SIMD Extensions 2 (SSE2) and above.
|
|
|
|
// > ...
|
|
|
|
// > On ARM machines, __vectorcall is accepted and ignored by the compiler.
|
|
|
|
//
|
|
|
|
// -- https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-160
|
|
|
|
//
|
|
|
|
// > On ARM and x64 processors, __stdcall is accepted and ignored by the compiler;
|
|
|
|
//
|
|
|
|
// -- https://docs.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-160
|
|
|
|
//
|
|
|
|
// > In most cases, keywords or compiler switches that specify an unsupported
|
|
|
|
// > convention on a particular platform are ignored, and the platform default
|
|
|
|
// > convention is used.
|
|
|
|
//
|
|
|
|
// -- https://docs.microsoft.com/en-us/cpp/cpp/argument-passing-and-naming-conventions
|
2022-02-01 18:53:45 +01:00
|
|
|
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } if self.is_like_windows => true,
|
2021-06-11 14:22:13 +03:00
|
|
|
// Outside of Windows we want to only support these calling conventions for the
|
|
|
|
// architectures for which these calling conventions are actually well defined.
|
2022-02-01 18:53:45 +01:00
|
|
|
Stdcall { .. } | Fastcall { .. } if self.arch == "x86" => true,
|
|
|
|
Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => true,
|
2021-06-11 14:22:13 +03:00
|
|
|
// Return a `None` for other cases so that we know to emit a future compat lint.
|
2022-02-01 18:53:45 +01:00
|
|
|
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => return None,
|
2021-06-11 14:22:13 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-15 09:46:44 +00:00
|
|
|
/// Minimum integer size in bits that this target can perform atomic
|
|
|
|
/// operations on.
|
|
|
|
pub fn min_atomic_width(&self) -> u64 {
|
2020-11-08 14:27:51 +03:00
|
|
|
self.min_atomic_width.unwrap_or(8)
|
2016-08-15 09:46:44 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 23:45:40 -05:00
|
|
|
/// Maximum integer size in bits that this target can perform atomic
|
|
|
|
/// operations on.
|
|
|
|
pub fn max_atomic_width(&self) -> u64 {
|
2020-11-08 14:27:51 +03:00
|
|
|
self.max_atomic_width.unwrap_or_else(|| self.pointer_width.into())
|
2016-10-03 23:45:40 -05:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Loads a target descriptor from a JSON object.
|
2021-06-03 17:45:09 +02:00
|
|
|
pub fn from_json(obj: Json) -> Result<(Target, TargetWarnings), String> {
|
2016-04-07 22:29:01 -05:00
|
|
|
// While ugly, this code must remain this way to retain
|
|
|
|
// compatibility with existing JSON fields and the internal
|
|
|
|
// expected naming of the Target and TargetOptions structs.
|
|
|
|
// To ensure compatibility is retained, the built-in targets
|
|
|
|
// are round-tripped through this code to catch cases where
|
|
|
|
// the JSON parser is not updated to match the structs.
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2021-06-03 17:45:09 +02:00
|
|
|
let mut obj = match obj {
|
|
|
|
Value::Object(obj) => obj,
|
|
|
|
_ => return Err("Expected JSON object for target")?,
|
|
|
|
};
|
|
|
|
|
2021-05-27 10:21:53 +02:00
|
|
|
let mut get_req_field = |name: &str| {
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(name)
|
|
|
|
.and_then(|j| j.as_str().map(str::to_string))
|
2018-08-10 13:13:50 +02:00
|
|
|
.ok_or_else(|| format!("Field {} in target specification is required", name))
|
2014-07-23 11:56:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut base = Target {
|
2022-03-22 11:43:05 +01:00
|
|
|
llvm_target: get_req_field("llvm-target")?.into(),
|
2020-10-14 18:22:10 +02:00
|
|
|
pointer_width: get_req_field("target-pointer-width")?
|
|
|
|
.parse::<u32>()
|
|
|
|
.map_err(|_| "target-pointer-width must be an integer".to_string())?,
|
2022-03-22 11:43:05 +01:00
|
|
|
data_layout: get_req_field("data-layout")?.into(),
|
|
|
|
arch: get_req_field("arch")?.into(),
|
2014-07-23 11:56:36 -07:00
|
|
|
options: Default::default(),
|
|
|
|
};
|
|
|
|
|
2021-05-27 10:21:53 +02:00
|
|
|
let mut incorrect_type = vec![];
|
|
|
|
|
2015-01-02 14:44:21 -08:00
|
|
|
macro_rules! key {
|
2014-07-23 11:56:36 -07:00
|
|
|
($key_name:ident) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(&name).and_then(|s| s.as_str().map(str::to_string).map(Cow::from)) {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.$key_name = s;
|
2020-04-24 13:58:41 -07:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
} );
|
2020-10-08 20:54:45 +03:00
|
|
|
($key_name:ident = $json_name:expr) => ( {
|
|
|
|
let name = $json_name;
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(name).and_then(|s| s.as_str().map(str::to_string).map(Cow::from)) {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.$key_name = s;
|
2020-10-08 20:54:45 +03:00
|
|
|
}
|
|
|
|
} );
|
2014-07-23 11:56:36 -07:00
|
|
|
($key_name:ident, bool) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) {
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = s;
|
2020-04-24 13:58:41 -07:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
} );
|
2021-08-10 18:34:13 +00:00
|
|
|
($key_name:ident, u64) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(&name).and_then(|j| Json::as_u64(&j)) {
|
2021-08-10 18:34:13 +00:00
|
|
|
base.$key_name = s;
|
|
|
|
}
|
|
|
|
} );
|
2020-10-09 15:08:18 -04:00
|
|
|
($key_name:ident, Option<u32>) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) {
|
2020-10-09 15:08:18 -04:00
|
|
|
if s < 1 || s > 5 {
|
2022-03-22 11:43:05 +01:00
|
|
|
return Err("Not a valid DWARF version number".into());
|
2020-10-09 15:08:18 -04:00
|
|
|
}
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = Some(s as u32);
|
2020-10-09 15:08:18 -04:00
|
|
|
}
|
|
|
|
} );
|
2016-10-03 23:45:40 -05:00
|
|
|
($key_name:ident, Option<u64>) => ( {
|
2016-04-15 20:16:19 +01:00
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) {
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = Some(s);
|
2020-04-24 13:58:41 -07:00
|
|
|
}
|
2016-04-15 20:16:19 +01:00
|
|
|
} );
|
2018-12-31 10:58:13 -08:00
|
|
|
($key_name:ident, MergeFunctions) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2018-12-31 10:58:13 -08:00
|
|
|
match s.parse::<MergeFunctions>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(mergefunc) => base.$key_name = mergefunc,
|
2018-12-31 10:58:13 -08:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for \
|
|
|
|
merge-functions. Use 'disabled', \
|
|
|
|
'trampolines', or 'aliases'.",
|
|
|
|
s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2020-04-23 00:46:45 +03:00
|
|
|
($key_name:ident, RelocModel) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-04-23 00:46:45 +03:00
|
|
|
match s.parse::<RelocModel>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(relocation_model) => base.$key_name = relocation_model,
|
2020-04-23 00:46:45 +03:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid relocation model. \
|
|
|
|
Run `rustc --print relocation-models` to \
|
|
|
|
see the list of supported values.", s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2020-05-07 03:34:27 +03:00
|
|
|
($key_name:ident, CodeModel) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-05-07 03:34:27 +03:00
|
|
|
match s.parse::<CodeModel>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(code_model) => base.$key_name = Some(code_model),
|
2020-05-07 03:34:27 +03:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid code model. \
|
|
|
|
Run `rustc --print code-models` to \
|
|
|
|
see the list of supported values.", s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2020-04-25 21:45:21 +03:00
|
|
|
($key_name:ident, TlsModel) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-04-25 21:45:21 +03:00
|
|
|
match s.parse::<TlsModel>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(tls_model) => base.$key_name = tls_model,
|
2020-04-25 21:45:21 +03:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid TLS model. \
|
|
|
|
Run `rustc --print tls-models` to \
|
|
|
|
see the list of supported values.", s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2016-09-27 21:26:08 -05:00
|
|
|
($key_name:ident, PanicStrategy) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2016-09-27 21:26:08 -05:00
|
|
|
match s {
|
2020-11-08 14:27:51 +03:00
|
|
|
"unwind" => base.$key_name = PanicStrategy::Unwind,
|
|
|
|
"abort" => base.$key_name = PanicStrategy::Abort,
|
2016-09-27 21:26:08 -05:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for \
|
|
|
|
panic-strategy. Use 'unwind' or 'abort'.",
|
|
|
|
s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2017-07-14 22:01:37 +02:00
|
|
|
($key_name:ident, RelroLevel) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2017-07-18 01:27:55 +02:00
|
|
|
match s.parse::<RelroLevel>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(level) => base.$key_name = level,
|
2017-07-14 22:01:37 +02:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for \
|
|
|
|
relro-level. Use 'full', 'partial, or 'off'.",
|
|
|
|
s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2020-11-30 08:39:08 -08:00
|
|
|
($key_name:ident, SplitDebuginfo) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-11-30 08:39:08 -08:00
|
|
|
match s.parse::<SplitDebuginfo>() {
|
|
|
|
Ok(level) => base.$key_name = level,
|
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for \
|
|
|
|
split-debuginfo. Use 'off' or 'dsymutil'.",
|
|
|
|
s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2014-07-23 11:56:36 -07:00
|
|
|
($key_name:ident, list) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(j) = obj.remove(&name) {
|
|
|
|
if let Some(v) = j.as_array() {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.$key_name = v.iter()
|
2021-06-03 17:45:09 +02:00
|
|
|
.map(|a| a.as_str().unwrap().to_string().into())
|
2021-05-27 10:21:53 +02:00
|
|
|
.collect();
|
|
|
|
} else {
|
|
|
|
incorrect_type.push(name)
|
|
|
|
}
|
2020-04-24 13:58:41 -07:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
} );
|
2018-11-19 15:04:28 +05:30
|
|
|
($key_name:ident, opt_list) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(j) = obj.remove(&name) {
|
|
|
|
if let Some(v) = j.as_array() {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.$key_name = Some(v.iter()
|
2021-06-03 17:45:09 +02:00
|
|
|
.map(|a| a.as_str().unwrap().to_string().into())
|
2021-05-27 10:21:53 +02:00
|
|
|
.collect());
|
|
|
|
} else {
|
|
|
|
incorrect_type.push(name)
|
|
|
|
}
|
2020-04-24 13:58:41 -07:00
|
|
|
}
|
2018-11-19 15:04:28 +05:30
|
|
|
} );
|
2015-09-07 00:35:57 -05:00
|
|
|
($key_name:ident, optional) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(o) = obj.remove(&name) {
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = o
|
2021-06-03 17:45:09 +02:00
|
|
|
.as_str()
|
2022-03-22 11:43:05 +01:00
|
|
|
.map(|s| s.to_string().into());
|
2015-09-07 00:35:57 -05:00
|
|
|
}
|
|
|
|
} );
|
2018-08-18 20:16:04 +02:00
|
|
|
($key_name:ident, LldFlavor) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2018-08-18 20:16:04 +02:00
|
|
|
if let Some(flavor) = LldFlavor::from_str(&s) {
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = flavor;
|
2018-08-18 20:16:04 +02:00
|
|
|
} else {
|
|
|
|
return Some(Err(format!(
|
|
|
|
"'{}' is not a valid value for lld-flavor. \
|
|
|
|
Use 'darwin', 'gnu', 'link' or 'wasm.",
|
|
|
|
s)))
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
($key_name:ident, LinkerFlavor) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-10-08 22:22:28 +03:00
|
|
|
match LinkerFlavor::from_str(s) {
|
2020-11-08 14:27:51 +03:00
|
|
|
Some(linker_flavor) => base.$key_name = linker_flavor,
|
2020-10-08 22:22:28 +03:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for linker-flavor. \
|
|
|
|
Use {}", s, LinkerFlavor::one_of()))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2021-01-09 16:54:20 +02:00
|
|
|
($key_name:ident, StackProbeType) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| match StackProbeType::from_json(&o) {
|
2021-01-09 16:54:20 +02:00
|
|
|
Ok(v) => {
|
|
|
|
base.$key_name = v;
|
|
|
|
Some(Ok(()))
|
|
|
|
},
|
|
|
|
Err(s) => Some(Err(
|
|
|
|
format!("`{:?}` is not a valid value for `{}`: {}", o, name, s)
|
|
|
|
)),
|
|
|
|
}).unwrap_or(Ok(()))
|
|
|
|
} );
|
2021-02-13 22:00:07 +02:00
|
|
|
($key_name:ident, SanitizerSet) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(o) = obj.remove(&name) {
|
2021-05-27 10:21:53 +02:00
|
|
|
if let Some(a) = o.as_array() {
|
|
|
|
for s in a {
|
2021-06-03 17:45:09 +02:00
|
|
|
base.$key_name |= match s.as_str() {
|
2021-05-27 10:21:53 +02:00
|
|
|
Some("address") => SanitizerSet::ADDRESS,
|
2021-10-07 15:33:13 -07:00
|
|
|
Some("cfi") => SanitizerSet::CFI,
|
2021-05-27 10:21:53 +02:00
|
|
|
Some("leak") => SanitizerSet::LEAK,
|
|
|
|
Some("memory") => SanitizerSet::MEMORY,
|
2021-12-03 16:11:13 -05:00
|
|
|
Some("memtag") => SanitizerSet::MEMTAG,
|
2021-05-27 10:21:53 +02:00
|
|
|
Some("thread") => SanitizerSet::THREAD,
|
|
|
|
Some("hwaddress") => SanitizerSet::HWADDRESS,
|
|
|
|
Some(s) => return Err(format!("unknown sanitizer {}", s)),
|
|
|
|
_ => return Err(format!("not a string: {:?}", s)),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
incorrect_type.push(name)
|
2021-02-13 22:00:07 +02:00
|
|
|
}
|
2021-05-27 10:21:53 +02:00
|
|
|
}
|
|
|
|
Ok::<(), String>(())
|
2021-02-13 22:00:07 +02:00
|
|
|
} );
|
|
|
|
|
2020-04-29 20:47:07 +03:00
|
|
|
($key_name:ident, crt_objects_fallback) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
2020-04-29 20:47:07 +03:00
|
|
|
match s.parse::<CrtObjectsFallback>() {
|
2020-11-08 14:27:51 +03:00
|
|
|
Ok(fallback) => base.$key_name = Some(fallback),
|
2020-04-29 20:47:07 +03:00
|
|
|
_ => return Some(Err(format!("'{}' is not a valid CRT objects fallback. \
|
|
|
|
Use 'musl', 'mingw' or 'wasm'", s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
|
|
|
($key_name:ident, link_objects) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(val) = obj.remove(&name) {
|
2020-04-29 20:47:07 +03:00
|
|
|
let obj = val.as_object().ok_or_else(|| format!("{}: expected a \
|
|
|
|
JSON object with fields per CRT object kind.", name))?;
|
|
|
|
let mut args = CrtObjects::new();
|
|
|
|
for (k, v) in obj {
|
|
|
|
let kind = LinkOutputKind::from_str(&k).ok_or_else(|| {
|
|
|
|
format!("{}: '{}' is not a valid value for CRT object kind. \
|
|
|
|
Use '(dynamic,static)-(nopic,pic)-exe' or \
|
2020-12-12 21:38:23 -06:00
|
|
|
'(dynamic,static)-dylib' or 'wasi-reactor-exe'", name, k)
|
2020-04-29 20:47:07 +03:00
|
|
|
})?;
|
|
|
|
|
|
|
|
let v = v.as_array().ok_or_else(||
|
|
|
|
format!("{}.{}: expected a JSON array", name, k)
|
|
|
|
)?.iter().enumerate()
|
|
|
|
.map(|(i,s)| {
|
2021-06-03 17:45:09 +02:00
|
|
|
let s = s.as_str().ok_or_else(||
|
2020-04-29 20:47:07 +03:00
|
|
|
format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
|
2022-03-22 11:43:05 +01:00
|
|
|
Ok(s.to_string().into())
|
2020-04-29 20:47:07 +03:00
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>, String>>()?;
|
|
|
|
|
|
|
|
args.insert(kind, v);
|
|
|
|
}
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = args;
|
2020-04-29 20:47:07 +03:00
|
|
|
}
|
|
|
|
} );
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
($key_name:ident, link_args) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(val) = obj.remove(&name) {
|
2018-07-13 10:14:16 -07:00
|
|
|
let obj = val.as_object().ok_or_else(|| format!("{}: expected a \
|
|
|
|
JSON object with fields per linker-flavor.", name))?;
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
let mut args = LinkArgs::new();
|
|
|
|
for (k, v) in obj {
|
2018-07-13 10:14:16 -07:00
|
|
|
let flavor = LinkerFlavor::from_str(&k).ok_or_else(|| {
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
format!("{}: '{}' is not a valid value for linker-flavor. \
|
|
|
|
Use 'em', 'gcc', 'ld' or 'msvc'", name, k)
|
|
|
|
})?;
|
|
|
|
|
2018-07-13 10:14:16 -07:00
|
|
|
let v = v.as_array().ok_or_else(||
|
|
|
|
format!("{}.{}: expected a JSON array", name, k)
|
|
|
|
)?.iter().enumerate()
|
|
|
|
.map(|(i,s)| {
|
2021-06-03 17:45:09 +02:00
|
|
|
let s = s.as_str().ok_or_else(||
|
2018-07-13 10:14:16 -07:00
|
|
|
format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
|
2022-03-28 15:06:46 +02:00
|
|
|
Ok(s.to_string().into())
|
2018-07-13 10:14:16 -07:00
|
|
|
})
|
|
|
|
.collect::<Result<Vec<_>, String>>()?;
|
|
|
|
|
|
|
|
args.insert(flavor, v);
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
}
|
2020-11-08 14:27:51 +03:00
|
|
|
base.$key_name = args;
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
}
|
|
|
|
} );
|
2017-06-23 17:26:39 -07:00
|
|
|
($key_name:ident, env) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(o) = obj.remove(&name) {
|
2021-05-27 10:21:53 +02:00
|
|
|
if let Some(a) = o.as_array() {
|
|
|
|
for o in a {
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(s) = o.as_str() {
|
2021-05-27 10:21:53 +02:00
|
|
|
let p = s.split('=').collect::<Vec<_>>();
|
|
|
|
if p.len() == 2 {
|
|
|
|
let k = p[0].to_string();
|
|
|
|
let v = p[1].to_string();
|
2022-03-28 01:08:17 +02:00
|
|
|
base.$key_name.to_mut().push((k.into(), v.into()));
|
2021-05-27 10:21:53 +02:00
|
|
|
}
|
2017-06-23 17:26:39 -07:00
|
|
|
}
|
|
|
|
}
|
2021-05-27 10:21:53 +02:00
|
|
|
} else {
|
|
|
|
incorrect_type.push(name)
|
2017-06-23 17:26:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
($key_name:ident, Option<Abi>) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2021-06-03 17:45:09 +02:00
|
|
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
match lookup_abi(s) {
|
|
|
|
Some(abi) => base.$key_name = Some(abi),
|
|
|
|
_ => return Some(Err(format!("'{}' is not a valid value for abi", s))),
|
|
|
|
}
|
|
|
|
Some(Ok(()))
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
2021-04-10 23:22:58 +03:00
|
|
|
($key_name:ident, TargetFamilies) => ( {
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(value) = obj.remove("target-family") {
|
|
|
|
if let Some(v) = value.as_array() {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.$key_name = v.iter()
|
2021-06-03 17:45:09 +02:00
|
|
|
.map(|a| a.as_str().unwrap().to_string().into())
|
2021-05-27 10:21:53 +02:00
|
|
|
.collect();
|
2021-06-03 17:45:09 +02:00
|
|
|
} else if let Some(v) = value.as_str() {
|
2022-03-28 01:08:17 +02:00
|
|
|
base.$key_name = vec![v.to_string().into()].into();
|
2021-05-27 10:21:53 +02:00
|
|
|
}
|
2021-04-10 23:22:58 +03:00
|
|
|
}
|
|
|
|
} );
|
2015-01-02 14:44:21 -08:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(j) = obj.remove("target-endian") {
|
|
|
|
if let Some(s) = j.as_str() {
|
2021-05-27 10:21:53 +02:00
|
|
|
base.endian = s.parse()?;
|
|
|
|
} else {
|
2022-03-22 11:43:05 +01:00
|
|
|
incorrect_type.push("target-endian".into())
|
2021-05-27 10:21:53 +02:00
|
|
|
}
|
2021-01-05 01:01:29 +00:00
|
|
|
}
|
2021-05-27 10:21:53 +02:00
|
|
|
|
2021-06-03 17:45:09 +02:00
|
|
|
if let Some(fp) = obj.remove("frame-pointer") {
|
|
|
|
if let Some(s) = fp.as_str() {
|
2021-06-26 23:53:35 +03:00
|
|
|
base.frame_pointer = s
|
|
|
|
.parse()
|
|
|
|
.map_err(|()| format!("'{}' is not a valid value for frame-pointer", s))?;
|
|
|
|
} else {
|
2022-03-22 11:43:05 +01:00
|
|
|
incorrect_type.push("frame-pointer".into())
|
2021-06-26 23:53:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(is_builtin, bool);
|
2020-11-12 19:16:59 +03:00
|
|
|
key!(c_int_width = "target-c-int-width");
|
2020-11-08 14:57:55 +03:00
|
|
|
key!(os);
|
|
|
|
key!(env);
|
2021-07-06 20:54:54 -07:00
|
|
|
key!(abi);
|
2020-11-08 14:57:55 +03:00
|
|
|
key!(vendor);
|
2020-10-08 22:22:28 +03:00
|
|
|
key!(linker_flavor, LinkerFlavor)?;
|
2018-02-10 12:09:25 -08:00
|
|
|
key!(linker, optional);
|
2018-12-01 15:48:55 -06:00
|
|
|
key!(lld_flavor, LldFlavor)?;
|
2020-04-29 20:47:07 +03:00
|
|
|
key!(pre_link_objects, link_objects);
|
|
|
|
key!(post_link_objects, link_objects);
|
|
|
|
key!(pre_link_objects_fallback, link_objects);
|
|
|
|
key!(post_link_objects_fallback, link_objects);
|
|
|
|
key!(crt_objects_fallback, crt_objects_fallback)?;
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
key!(pre_link_args, link_args);
|
|
|
|
key!(late_link_args, link_args);
|
2020-03-03 20:41:37 +00:00
|
|
|
key!(late_link_args_dynamic, link_args);
|
|
|
|
key!(late_link_args_static, link_args);
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
key!(post_link_args, link_args);
|
2020-05-10 17:39:57 -04:00
|
|
|
key!(link_script, optional);
|
2017-06-23 17:26:39 -07:00
|
|
|
key!(link_env, env);
|
2019-09-12 13:47:17 +03:00
|
|
|
key!(link_env_remove, list);
|
2016-12-18 22:25:46 -05:00
|
|
|
key!(asm_args, list);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(cpu);
|
|
|
|
key!(features);
|
|
|
|
key!(dynamic_linking, bool);
|
2017-10-22 20:01:00 -07:00
|
|
|
key!(only_cdylib, bool);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(executables, bool);
|
2020-04-23 00:46:45 +03:00
|
|
|
key!(relocation_model, RelocModel)?;
|
2020-05-07 03:34:27 +03:00
|
|
|
key!(code_model, CodeModel)?;
|
2020-04-25 21:45:21 +03:00
|
|
|
key!(tls_model, TlsModel)?;
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(disable_redzone, bool);
|
|
|
|
key!(function_sections, bool);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(dll_prefix);
|
|
|
|
key!(dll_suffix);
|
|
|
|
key!(exe_suffix);
|
|
|
|
key!(staticlib_prefix);
|
|
|
|
key!(staticlib_suffix);
|
2021-04-10 23:22:58 +03:00
|
|
|
key!(families, TargetFamilies);
|
2018-02-26 10:20:14 -08:00
|
|
|
key!(abi_return_struct_as_int, bool);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(is_like_osx, bool);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(is_like_solaris, bool);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(is_like_windows, bool);
|
2016-04-08 11:24:19 +03:00
|
|
|
key!(is_like_msvc, bool);
|
2020-12-30 12:52:21 -06:00
|
|
|
key!(is_like_wasm, bool);
|
2020-10-09 15:08:18 -04:00
|
|
|
key!(dwarf_version, Option<u32>);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(linker_is_gnu, bool);
|
2016-07-13 17:03:02 -04:00
|
|
|
key!(allows_weak_linkage, bool);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(has_rpath, bool);
|
2015-09-21 19:02:46 +02:00
|
|
|
key!(no_default_libraries, bool);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(position_independent_executables, bool);
|
2020-05-02 01:59:35 +03:00
|
|
|
key!(static_position_independent_executables, bool);
|
2018-09-26 19:19:55 +03:00
|
|
|
key!(needs_plt, bool);
|
2018-12-01 15:48:55 -06:00
|
|
|
key!(relro_level, RelroLevel)?;
|
2015-11-18 01:14:15 +01:00
|
|
|
key!(archive_format);
|
2015-08-20 17:47:21 -05:00
|
|
|
key!(allow_asm, bool);
|
2019-10-17 16:09:32 -07:00
|
|
|
key!(main_needs_argc_argv, bool);
|
2021-12-17 20:56:38 +00:00
|
|
|
key!(has_thread_local, bool);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(obj_is_bitcode, bool);
|
2020-05-07 12:26:18 +10:00
|
|
|
key!(forces_embed_bitcode, bool);
|
2020-05-07 15:34:31 +10:00
|
|
|
key!(bitcode_llvm_cmdline);
|
2016-10-03 23:45:40 -05:00
|
|
|
key!(max_atomic_width, Option<u64>);
|
2016-08-15 09:46:44 +00:00
|
|
|
key!(min_atomic_width, Option<u64>);
|
2018-06-30 14:56:08 -05:00
|
|
|
key!(atomic_cas, bool);
|
2018-12-01 15:48:55 -06:00
|
|
|
key!(panic_strategy, PanicStrategy)?;
|
2017-08-22 16:24:29 -05:00
|
|
|
key!(crt_static_allows_dylibs, bool);
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 16:40:13 -07:00
|
|
|
key!(crt_static_default, bool);
|
2017-08-22 16:24:29 -05:00
|
|
|
key!(crt_static_respected, bool);
|
2021-01-09 16:54:20 +02:00
|
|
|
key!(stack_probes, StackProbeType)?;
|
2017-09-08 14:49:51 -07:00
|
|
|
key!(min_global_align, Option<u64>);
|
2017-10-04 14:38:52 -07:00
|
|
|
key!(default_codegen_units, Option<u64>);
|
2017-11-11 07:08:00 -08:00
|
|
|
key!(trap_unreachable, bool);
|
2017-10-22 20:01:00 -07:00
|
|
|
key!(requires_lto, bool);
|
|
|
|
key!(singlethread, bool);
|
|
|
|
key!(no_builtins, bool);
|
2018-01-30 11:54:07 -08:00
|
|
|
key!(default_hidden_visibility, bool);
|
2018-04-06 15:40:43 +02:00
|
|
|
key!(emit_debug_gdb_scripts, bool);
|
2018-04-19 15:17:34 -07:00
|
|
|
key!(requires_uwtable, bool);
|
2021-03-23 02:38:30 +08:00
|
|
|
key!(default_uwtable, bool);
|
2018-10-12 17:04:31 -07:00
|
|
|
key!(simd_types_indirect, bool);
|
2019-04-14 19:05:21 +02:00
|
|
|
key!(limit_rdylib_exports, bool);
|
2018-11-19 15:04:28 +05:30
|
|
|
key!(override_export_symbols, opt_list);
|
2018-12-31 10:58:13 -08:00
|
|
|
key!(merge_functions, MergeFunctions)?;
|
2020-11-12 19:16:59 +03:00
|
|
|
key!(mcount = "target-mcount");
|
2019-10-29 21:12:05 -07:00
|
|
|
key!(llvm_abiname);
|
2019-12-02 17:52:45 +05:30
|
|
|
key!(relax_elf_relocations, bool);
|
2020-01-09 16:40:40 +01:00
|
|
|
key!(llvm_args, list);
|
2020-04-16 19:40:11 -07:00
|
|
|
key!(use_ctors_section, bool);
|
2020-07-22 15:49:04 +03:00
|
|
|
key!(eh_frame_header, bool);
|
2020-10-08 23:23:27 +01:00
|
|
|
key!(has_thumb_interworking, bool);
|
2020-11-30 08:39:08 -08:00
|
|
|
key!(split_debuginfo, SplitDebuginfo)?;
|
2021-02-13 22:00:07 +02:00
|
|
|
key!(supported_sanitizers, SanitizerSet)?;
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
key!(default_adjusted_cabi, Option<Abi>)?;
|
2021-08-10 18:34:13 +00:00
|
|
|
key!(c_enum_min_bits, u64);
|
2021-11-10 10:47:00 -08:00
|
|
|
key!(generate_arange_section, bool);
|
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
|
|
|
key!(supports_stack_protector, bool);
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2021-06-06 18:13:27 +03:00
|
|
|
if base.is_builtin {
|
|
|
|
// This can cause unfortunate ICEs later down the line.
|
2022-03-22 11:43:05 +01:00
|
|
|
return Err("may not set is_builtin for targets not built-in".into());
|
2021-06-06 18:13:27 +03:00
|
|
|
}
|
2021-06-03 17:45:09 +02:00
|
|
|
// Each field should have been read using `Json::remove` so any keys remaining are unused.
|
|
|
|
let remaining_keys = obj.keys();
|
2021-05-27 10:21:53 +02:00
|
|
|
Ok((
|
|
|
|
base,
|
|
|
|
TargetWarnings { unused_fields: remaining_keys.cloned().collect(), incorrect_type },
|
|
|
|
))
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
|
2022-02-25 16:10:26 +01:00
|
|
|
/// Load a built-in target
|
|
|
|
pub fn expect_builtin(target_triple: &TargetTriple) -> Target {
|
|
|
|
match *target_triple {
|
|
|
|
TargetTriple::TargetTriple(ref target_triple) => {
|
|
|
|
load_builtin(target_triple).expect("built-in target")
|
|
|
|
}
|
2022-06-18 10:19:24 +00:00
|
|
|
TargetTriple::TargetJson { .. } => {
|
2022-02-25 16:10:26 +01:00
|
|
|
panic!("built-in targets doens't support target-paths")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 19:15:19 +03:00
|
|
|
/// Search for a JSON file specifying the given target triple.
|
2014-07-23 11:56:36 -07:00
|
|
|
///
|
2021-05-10 19:15:19 +03:00
|
|
|
/// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the
|
|
|
|
/// sysroot under the target-triple's `rustlib` directory. Note that it could also just be a
|
|
|
|
/// bare filename already, so also check for that. If one of the hardcoded targets we know
|
|
|
|
/// about, just return it directly.
|
|
|
|
///
|
|
|
|
/// The error string could come from any of the APIs called, including filesystem access and
|
|
|
|
/// JSON decoding.
|
2021-05-27 10:21:53 +02:00
|
|
|
pub fn search(
|
|
|
|
target_triple: &TargetTriple,
|
2021-11-07 10:33:27 +01:00
|
|
|
sysroot: &Path,
|
2021-05-27 10:21:53 +02:00
|
|
|
) -> Result<(Target, TargetWarnings), String> {
|
2015-01-27 12:20:58 -08:00
|
|
|
use std::env;
|
2018-01-10 08:58:39 -08:00
|
|
|
use std::fs;
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2021-05-27 10:21:53 +02:00
|
|
|
fn load_file(path: &Path) -> Result<(Target, TargetWarnings), String> {
|
2022-02-05 14:50:46 -05:00
|
|
|
let contents = fs::read_to_string(path).map_err(|e| e.to_string())?;
|
2021-06-03 17:45:09 +02:00
|
|
|
let obj = serde_json::from_str(&contents).map_err(|e| e.to_string())?;
|
2016-07-24 11:47:39 -05:00
|
|
|
Target::from_json(obj)
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
|
2018-08-09 15:42:43 +02:00
|
|
|
match *target_triple {
|
|
|
|
TargetTriple::TargetTriple(ref target_triple) => {
|
2020-10-05 16:24:04 +03:00
|
|
|
// check if triple is in list of built-in targets
|
|
|
|
if let Some(t) = load_builtin(target_triple) {
|
2021-05-27 10:21:53 +02:00
|
|
|
return Ok((t, TargetWarnings::empty()));
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
// search for a file named `target_triple`.json in RUST_TARGET_PATH
|
|
|
|
let path = {
|
|
|
|
let mut target = target_triple.to_string();
|
|
|
|
target.push_str(".json");
|
|
|
|
PathBuf::from(target)
|
|
|
|
};
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2018-08-09 15:42:43 +02:00
|
|
|
let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
for dir in env::split_paths(&target_path) {
|
|
|
|
let p = dir.join(&path);
|
|
|
|
if p.is_file() {
|
|
|
|
return load_file(&p);
|
|
|
|
}
|
|
|
|
}
|
2021-04-03 13:45:02 +08:00
|
|
|
|
|
|
|
// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
|
|
|
|
// as a fallback.
|
2021-05-10 19:15:19 +03:00
|
|
|
let rustlib_path = crate::target_rustlib_path(&sysroot, &target_triple);
|
2021-09-03 12:36:33 +02:00
|
|
|
let p = PathBuf::from_iter([
|
2021-05-10 19:15:19 +03:00
|
|
|
Path::new(sysroot),
|
|
|
|
Path::new(&rustlib_path),
|
|
|
|
Path::new("target.json"),
|
2021-09-03 12:36:33 +02:00
|
|
|
]);
|
2021-04-03 13:45:02 +08:00
|
|
|
if p.is_file() {
|
|
|
|
return load_file(&p);
|
|
|
|
}
|
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
Err(format!("Could not find specification for target {:?}", target_triple))
|
|
|
|
}
|
2022-06-18 10:48:46 +00:00
|
|
|
TargetTriple::TargetJson { ref contents, .. } => {
|
2022-06-18 10:19:24 +00:00
|
|
|
let obj = serde_json::from_str(contents).map_err(|e| e.to_string())?;
|
|
|
|
Target::from_json(obj)
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-25 10:07:01 -07:00
|
|
|
|
2016-04-07 22:29:01 -05:00
|
|
|
impl ToJson for Target {
|
|
|
|
fn to_json(&self) -> Json {
|
2021-06-03 17:45:09 +02:00
|
|
|
let mut d = serde_json::Map::new();
|
2016-04-07 22:29:01 -05:00
|
|
|
let default: TargetOptions = Default::default();
|
|
|
|
|
|
|
|
macro_rules! target_val {
|
|
|
|
($attr:ident) => {{
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
2018-10-26 03:11:11 +09:00
|
|
|
d.insert(name, self.$attr.to_json());
|
2016-04-07 22:29:01 -05:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! target_option_val {
|
|
|
|
($attr:ident) => {{
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
2020-11-08 14:27:51 +03:00
|
|
|
if default.$attr != self.$attr {
|
|
|
|
d.insert(name, self.$attr.to_json());
|
2016-04-07 22:29:01 -05:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
($attr:ident, $key_name:expr) => {{
|
|
|
|
let name = $key_name;
|
2020-11-08 14:27:51 +03:00
|
|
|
if default.$attr != self.$attr {
|
2022-03-22 11:43:05 +01:00
|
|
|
d.insert(name.into(), self.$attr.to_json());
|
2016-04-07 22:29:01 -05:00
|
|
|
}
|
|
|
|
}};
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
(link_args - $attr:ident) => {{
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
2020-11-08 14:27:51 +03:00
|
|
|
if default.$attr != self.$attr {
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
let obj = self
|
|
|
|
.$attr
|
|
|
|
.iter()
|
2022-03-22 11:43:05 +01:00
|
|
|
.map(|(k, v)| (k.desc().to_string(), v.clone()))
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
.collect::<BTreeMap<_, _>>();
|
2018-10-26 03:11:11 +09:00
|
|
|
d.insert(name, obj.to_json());
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
}
|
|
|
|
}};
|
2017-06-23 17:26:39 -07:00
|
|
|
(env - $attr:ident) => {{
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
2020-11-08 14:27:51 +03:00
|
|
|
if default.$attr != self.$attr {
|
2017-06-23 17:26:39 -07:00
|
|
|
let obj = self
|
|
|
|
.$attr
|
|
|
|
.iter()
|
2022-03-22 11:43:05 +01:00
|
|
|
.map(|&(ref k, ref v)| format!("{k}={v}"))
|
2017-06-23 17:26:39 -07:00
|
|
|
.collect::<Vec<_>>();
|
2018-10-26 03:11:11 +09:00
|
|
|
d.insert(name, obj.to_json());
|
2017-06-23 17:26:39 -07:00
|
|
|
}
|
|
|
|
}};
|
2016-04-07 22:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
target_val!(llvm_target);
|
2020-10-15 11:44:00 +02:00
|
|
|
d.insert("target-pointer-width".to_string(), self.pointer_width.to_string().to_json());
|
2016-04-07 22:29:01 -05:00
|
|
|
target_val!(arch);
|
|
|
|
target_val!(data_layout);
|
|
|
|
|
2020-10-08 21:47:22 +03:00
|
|
|
target_option_val!(is_builtin);
|
2020-11-12 19:16:59 +03:00
|
|
|
target_option_val!(endian, "target-endian");
|
|
|
|
target_option_val!(c_int_width, "target-c-int-width");
|
2020-11-08 14:57:55 +03:00
|
|
|
target_option_val!(os);
|
|
|
|
target_option_val!(env);
|
2021-07-06 20:54:54 -07:00
|
|
|
target_option_val!(abi);
|
2020-11-08 14:57:55 +03:00
|
|
|
target_option_val!(vendor);
|
2020-10-08 22:22:28 +03:00
|
|
|
target_option_val!(linker_flavor);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(linker);
|
2018-08-18 20:16:04 +02:00
|
|
|
target_option_val!(lld_flavor);
|
2020-04-29 20:47:07 +03:00
|
|
|
target_option_val!(pre_link_objects);
|
|
|
|
target_option_val!(post_link_objects);
|
|
|
|
target_option_val!(pre_link_objects_fallback);
|
|
|
|
target_option_val!(post_link_objects_fallback);
|
|
|
|
target_option_val!(crt_objects_fallback);
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
target_option_val!(link_args - pre_link_args);
|
|
|
|
target_option_val!(link_args - late_link_args);
|
2020-03-03 20:41:37 +00:00
|
|
|
target_option_val!(link_args - late_link_args_dynamic);
|
|
|
|
target_option_val!(link_args - late_link_args_static);
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
target_option_val!(link_args - post_link_args);
|
2020-05-10 17:39:57 -04:00
|
|
|
target_option_val!(link_script);
|
2017-06-23 17:26:39 -07:00
|
|
|
target_option_val!(env - link_env);
|
2019-09-12 13:47:17 +03:00
|
|
|
target_option_val!(link_env_remove);
|
2016-12-18 22:25:46 -05:00
|
|
|
target_option_val!(asm_args);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(cpu);
|
|
|
|
target_option_val!(features);
|
|
|
|
target_option_val!(dynamic_linking);
|
2017-10-22 20:01:00 -07:00
|
|
|
target_option_val!(only_cdylib);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(executables);
|
|
|
|
target_option_val!(relocation_model);
|
|
|
|
target_option_val!(code_model);
|
2017-10-31 17:45:19 +00:00
|
|
|
target_option_val!(tls_model);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(disable_redzone);
|
2021-06-26 23:53:35 +03:00
|
|
|
target_option_val!(frame_pointer);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(function_sections);
|
|
|
|
target_option_val!(dll_prefix);
|
|
|
|
target_option_val!(dll_suffix);
|
|
|
|
target_option_val!(exe_suffix);
|
|
|
|
target_option_val!(staticlib_prefix);
|
|
|
|
target_option_val!(staticlib_suffix);
|
2021-04-10 23:22:58 +03:00
|
|
|
target_option_val!(families, "target-family");
|
2018-02-26 10:20:14 -08:00
|
|
|
target_option_val!(abi_return_struct_as_int);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(is_like_osx);
|
|
|
|
target_option_val!(is_like_solaris);
|
|
|
|
target_option_val!(is_like_windows);
|
|
|
|
target_option_val!(is_like_msvc);
|
2020-12-30 12:52:21 -06:00
|
|
|
target_option_val!(is_like_wasm);
|
2020-10-09 15:08:18 -04:00
|
|
|
target_option_val!(dwarf_version);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(linker_is_gnu);
|
2016-07-13 17:03:02 -04:00
|
|
|
target_option_val!(allows_weak_linkage);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(has_rpath);
|
|
|
|
target_option_val!(no_default_libraries);
|
|
|
|
target_option_val!(position_independent_executables);
|
2020-05-02 01:59:35 +03:00
|
|
|
target_option_val!(static_position_independent_executables);
|
2018-09-26 19:19:55 +03:00
|
|
|
target_option_val!(needs_plt);
|
2017-07-14 22:01:37 +02:00
|
|
|
target_option_val!(relro_level);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(archive_format);
|
|
|
|
target_option_val!(allow_asm);
|
2019-10-17 16:09:32 -07:00
|
|
|
target_option_val!(main_needs_argc_argv);
|
2021-12-17 20:56:38 +00:00
|
|
|
target_option_val!(has_thread_local);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(obj_is_bitcode);
|
2020-05-07 12:26:18 +10:00
|
|
|
target_option_val!(forces_embed_bitcode);
|
2020-05-07 15:34:31 +10:00
|
|
|
target_option_val!(bitcode_llvm_cmdline);
|
2016-08-15 09:46:44 +00:00
|
|
|
target_option_val!(min_atomic_width);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(max_atomic_width);
|
2018-06-30 14:56:08 -05:00
|
|
|
target_option_val!(atomic_cas);
|
2016-09-27 21:26:08 -05:00
|
|
|
target_option_val!(panic_strategy);
|
2017-08-22 16:24:29 -05:00
|
|
|
target_option_val!(crt_static_allows_dylibs);
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-10-31 16:40:13 -07:00
|
|
|
target_option_val!(crt_static_default);
|
2017-08-22 16:24:29 -05:00
|
|
|
target_option_val!(crt_static_respected);
|
2017-06-21 12:08:18 -07:00
|
|
|
target_option_val!(stack_probes);
|
2017-09-08 14:49:51 -07:00
|
|
|
target_option_val!(min_global_align);
|
2017-10-04 14:38:52 -07:00
|
|
|
target_option_val!(default_codegen_units);
|
2017-11-11 07:08:00 -08:00
|
|
|
target_option_val!(trap_unreachable);
|
2017-10-22 20:01:00 -07:00
|
|
|
target_option_val!(requires_lto);
|
|
|
|
target_option_val!(singlethread);
|
|
|
|
target_option_val!(no_builtins);
|
2018-01-30 11:54:07 -08:00
|
|
|
target_option_val!(default_hidden_visibility);
|
2018-04-06 15:40:43 +02:00
|
|
|
target_option_val!(emit_debug_gdb_scripts);
|
2018-04-19 15:17:34 -07:00
|
|
|
target_option_val!(requires_uwtable);
|
2021-03-23 02:38:30 +08:00
|
|
|
target_option_val!(default_uwtable);
|
2018-10-12 17:04:31 -07:00
|
|
|
target_option_val!(simd_types_indirect);
|
2019-04-14 19:05:21 +02:00
|
|
|
target_option_val!(limit_rdylib_exports);
|
2018-11-19 15:04:28 +05:30
|
|
|
target_option_val!(override_export_symbols);
|
2018-12-31 10:58:13 -08:00
|
|
|
target_option_val!(merge_functions);
|
2020-11-12 19:16:59 +03:00
|
|
|
target_option_val!(mcount, "target-mcount");
|
2019-10-29 21:12:05 -07:00
|
|
|
target_option_val!(llvm_abiname);
|
2019-12-02 17:52:45 +05:30
|
|
|
target_option_val!(relax_elf_relocations);
|
2020-01-09 16:40:40 +01:00
|
|
|
target_option_val!(llvm_args);
|
2020-04-16 19:40:11 -07:00
|
|
|
target_option_val!(use_ctors_section);
|
2020-07-22 15:49:04 +03:00
|
|
|
target_option_val!(eh_frame_header);
|
2020-10-08 23:23:27 +01:00
|
|
|
target_option_val!(has_thumb_interworking);
|
2020-11-30 08:39:08 -08:00
|
|
|
target_option_val!(split_debuginfo);
|
2021-02-13 22:00:07 +02:00
|
|
|
target_option_val!(supported_sanitizers);
|
2021-08-10 18:34:13 +00:00
|
|
|
target_option_val!(c_enum_min_bits);
|
2021-11-10 10:47:00 -08:00
|
|
|
target_option_val!(generate_arange_section);
|
add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.
Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.
Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.
Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.
LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.
The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.
Reviewed-by: Nikita Popov <nikic@php.net>
Extra commits during review:
- [address-review] make the stack-protector option unstable
- [address-review] reduce detail level of stack-protector option help text
- [address-review] correct grammar in comment
- [address-review] use compiler flag to avoid merging functions in test
- [address-review] specify min LLVM version in fortanix stack-protector test
Only for Fortanix test, since this target specifically requests the
`--x86-experimental-lvi-inline-asm-hardening` flag.
- [address-review] specify required LLVM components in stack-protector tests
- move stack protector option enum closer to other similar option enums
- rustc_interface/tests: sort debug option list in tracking hash test
- add an explicit `none` stack-protector option
Revert "set LLVM requirements for all stack protector support test revisions"
This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-04-06 21:37:49 +02:00
|
|
|
target_option_val!(supports_stack_protector);
|
2016-04-07 22:29:01 -05:00
|
|
|
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
if let Some(abi) = self.default_adjusted_cabi {
|
2022-03-22 11:43:05 +01:00
|
|
|
d.insert("default-adjusted-cabi".into(), Abi::name(abi).to_json());
|
rustc: Add a new `wasm` ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.
When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.
Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.
To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.
With the addition of a new ABI, this enables rustc to:
* Eventually remove the "wasm-bindgen compat hack". Once this
ABI is stable wasm-bindgen can switch to using it everywhere.
Afterwards the wasm32-unknown-unknown target can have its default ABI
updated to match C.
* Expose the ability to precisely match an ABI signature for a
WebAssembly function, regardless of what the C ABI that clang chooses
turns out to be.
* Continue to evolve the definition of the default C ABI to match what
clang does on all targets, since the purpose of that ABI will be
explicitly matching C rather than generating particular function
imports/exports.
Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-01 16:08:29 -07:00
|
|
|
}
|
|
|
|
|
2016-04-07 22:29:01 -05:00
|
|
|
Json::Object(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
/// Either a target triple string or a path to a JSON file.
|
2022-06-18 10:48:46 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2018-03-14 15:27:06 +01:00
|
|
|
pub enum TargetTriple {
|
|
|
|
TargetTriple(String),
|
2022-06-18 10:48:46 +00:00
|
|
|
TargetJson {
|
|
|
|
/// Warning: This field may only be used by rustdoc. Using it anywhere else will lead to
|
|
|
|
/// inconsistencies as it is discarded during serialization.
|
|
|
|
path_for_rustdoc: PathBuf,
|
|
|
|
triple: String,
|
|
|
|
contents: String,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a manual implementation to ignore the path field
|
|
|
|
impl PartialEq for TargetTriple {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
match (self, other) {
|
|
|
|
(Self::TargetTriple(l0), Self::TargetTriple(r0)) => l0 == r0,
|
|
|
|
(
|
|
|
|
Self::TargetJson { path_for_rustdoc: _, triple: l_triple, contents: l_contents },
|
|
|
|
Self::TargetJson { path_for_rustdoc: _, triple: r_triple, contents: r_contents },
|
|
|
|
) => l_triple == r_triple && l_contents == r_contents,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a manual implementation to ignore the path field
|
|
|
|
impl Hash for TargetTriple {
|
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) -> () {
|
|
|
|
match self {
|
|
|
|
TargetTriple::TargetTriple(triple) => {
|
|
|
|
0u8.hash(state);
|
|
|
|
triple.hash(state)
|
|
|
|
}
|
|
|
|
TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents } => {
|
|
|
|
1u8.hash(state);
|
|
|
|
triple.hash(state);
|
|
|
|
contents.hash(state)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use a manual implementation to prevent encoding the target json file path in the crate metadata
|
|
|
|
impl<S: Encoder> Encodable<S> for TargetTriple {
|
|
|
|
fn encode(&self, s: &mut S) {
|
|
|
|
match self {
|
|
|
|
TargetTriple::TargetTriple(triple) => s.emit_enum_variant(0, |s| s.emit_str(triple)),
|
|
|
|
TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents } => s
|
|
|
|
.emit_enum_variant(1, |s| {
|
|
|
|
s.emit_str(triple);
|
|
|
|
s.emit_str(contents)
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<D: Decoder> Decodable<D> for TargetTriple {
|
|
|
|
fn decode(d: &mut D) -> Self {
|
|
|
|
match d.read_usize() {
|
|
|
|
0 => TargetTriple::TargetTriple(d.read_str().to_owned()),
|
|
|
|
1 => TargetTriple::TargetJson {
|
|
|
|
path_for_rustdoc: PathBuf::new(),
|
|
|
|
triple: d.read_str().to_owned(),
|
|
|
|
contents: d.read_str().to_owned(),
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
panic!("invalid enum variant tag while decoding `TargetTriple`, expected 0..2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TargetTriple {
|
2018-03-24 20:14:59 +01:00
|
|
|
/// Creates a target triple from the passed target triple string.
|
2018-03-14 15:27:06 +01:00
|
|
|
pub fn from_triple(triple: &str) -> Self {
|
2022-03-22 11:43:05 +01:00
|
|
|
TargetTriple::TargetTriple(triple.into())
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-24 20:14:59 +01:00
|
|
|
/// Creates a target triple from the passed target path.
|
|
|
|
pub fn from_path(path: &Path) -> Result<Self, io::Error> {
|
|
|
|
let canonicalized_path = path.canonicalize()?;
|
2022-06-18 10:19:24 +00:00
|
|
|
let contents = std::fs::read_to_string(&canonicalized_path).map_err(|err| {
|
|
|
|
io::Error::new(
|
|
|
|
io::ErrorKind::InvalidInput,
|
2022-06-18 10:48:46 +00:00
|
|
|
format!("target path {:?} is not a valid file: {}", canonicalized_path, err),
|
2022-06-18 10:19:24 +00:00
|
|
|
)
|
|
|
|
})?;
|
|
|
|
let triple = canonicalized_path
|
|
|
|
.file_stem()
|
|
|
|
.expect("target path must not be empty")
|
|
|
|
.to_str()
|
|
|
|
.expect("target path must be valid unicode")
|
|
|
|
.to_owned();
|
2022-06-18 10:48:46 +00:00
|
|
|
Ok(TargetTriple::TargetJson { path_for_rustdoc: canonicalized_path, triple, contents })
|
2018-03-24 20:14:59 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
/// Returns a string triple for this target.
|
|
|
|
///
|
|
|
|
/// If this target is a path, the file name (without extension) is returned.
|
|
|
|
pub fn triple(&self) -> &str {
|
2018-08-09 15:42:43 +02:00
|
|
|
match *self {
|
2022-06-18 10:19:24 +00:00
|
|
|
TargetTriple::TargetTriple(ref triple)
|
2022-06-18 10:48:46 +00:00
|
|
|
| TargetTriple::TargetJson { ref triple, .. } => triple,
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-26 19:01:26 +02:00
|
|
|
|
|
|
|
/// Returns an extended string triple for this target.
|
|
|
|
///
|
|
|
|
/// If this target is a path, a hash of the path is appended to the triple returned
|
|
|
|
/// by `triple()`.
|
|
|
|
pub fn debug_triple(&self) -> String {
|
|
|
|
use std::collections::hash_map::DefaultHasher;
|
|
|
|
|
2022-06-18 10:19:24 +00:00
|
|
|
match self {
|
|
|
|
TargetTriple::TargetTriple(triple) => triple.to_owned(),
|
2022-06-18 10:48:46 +00:00
|
|
|
TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents: content } => {
|
2022-06-18 10:19:24 +00:00
|
|
|
let mut hasher = DefaultHasher::new();
|
|
|
|
content.hash(&mut hasher);
|
|
|
|
let hash = hasher.finish();
|
|
|
|
format!("{}-{}", triple, hash)
|
|
|
|
}
|
2018-03-26 19:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TargetTriple {
|
2019-02-08 21:00:07 +09:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-03-26 19:01:26 +02:00
|
|
|
write!(f, "{}", self.debug_triple())
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
}
|