2014-12-12 23:39:27 +00:00
|
|
|
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-07-23 11:56:36 -07:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! [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
|
|
|
|
//!
|
|
|
|
//! Targets are defined using [JSON](http://json.org/). The `Target` struct in
|
|
|
|
//! 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
|
|
|
|
2016-04-07 22:29:01 -05:00
|
|
|
use serialize::json::{Json, ToJson};
|
|
|
|
use std::collections::BTreeMap;
|
2014-07-23 11:56:36 -07:00
|
|
|
use std::default::Default;
|
2018-03-24 20:14:59 +01:00
|
|
|
use std::{fmt, io};
|
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;
|
2018-04-25 19:30:39 +03:00
|
|
|
use spec::abi::{Abi, lookup as lookup_abi};
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2018-04-25 19:30:39 +03:00
|
|
|
pub mod abi;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod android_base;
|
2014-07-23 11:56:36 -07:00
|
|
|
mod apple_base;
|
2015-01-08 10:19:52 +02:00
|
|
|
mod apple_ios_base;
|
2016-10-24 11:04:04 +02:00
|
|
|
mod arm_base;
|
2015-01-16 23:51:04 -08:00
|
|
|
mod bitrig_base;
|
2017-12-22 09:37:02 +01:00
|
|
|
mod cloudabi_base;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod dragonfly_base;
|
|
|
|
mod freebsd_base;
|
2016-09-25 16:55:40 -05:00
|
|
|
mod haiku_base;
|
2018-07-30 15:50:51 +02:00
|
|
|
mod hermit_base;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod linux_base;
|
2016-05-01 17:41:28 -04:00
|
|
|
mod linux_musl_base;
|
2015-01-29 08:19:28 +01:00
|
|
|
mod openbsd_base;
|
2015-06-30 20:37:11 -07:00
|
|
|
mod netbsd_base;
|
2016-01-28 14:02:31 +03:00
|
|
|
mod solaris_base;
|
2015-04-29 10:53:01 -07:00
|
|
|
mod windows_base;
|
2015-05-08 14:44:17 -07:00
|
|
|
mod windows_msvc_base;
|
2016-09-15 20:46:04 -05:00
|
|
|
mod thumb_base;
|
2017-08-03 10:37:11 +02:00
|
|
|
mod l4re_base;
|
2016-10-18 13:43:18 -07:00
|
|
|
mod fuchsia_base;
|
2016-12-12 19:53:51 -07:00
|
|
|
mod redox_base;
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2017-12-08 17:07:47 +02:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
|
|
|
|
RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum LinkerFlavor {
|
|
|
|
Em,
|
|
|
|
Gcc,
|
|
|
|
Ld,
|
|
|
|
Msvc,
|
|
|
|
Lld(LldFlavor),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
|
|
|
|
RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum LldFlavor {
|
|
|
|
Wasm,
|
|
|
|
Ld64,
|
|
|
|
Ld,
|
|
|
|
Link,
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
concat!("one of: ", $($string, " ",)+)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(s: &str) -> Option<Self> {
|
|
|
|
Some(match s {
|
|
|
|
$($string => $($flavor)*,)+
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
$($($flavor)* => $string,)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
flavor_mappings! {
|
|
|
|
((LinkerFlavor::Em), "em"),
|
|
|
|
((LinkerFlavor::Gcc), "gcc"),
|
|
|
|
((LinkerFlavor::Ld), "ld"),
|
|
|
|
((LinkerFlavor::Msvc), "msvc"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Wasm)), "wasm-ld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Ld64)), "ld64.lld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Ld)), "ld.lld"),
|
|
|
|
((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum PanicStrategy {
|
|
|
|
Unwind,
|
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PanicStrategy {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
PanicStrategy::Unwind => "unwind",
|
|
|
|
PanicStrategy::Abort => "abort",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for PanicStrategy {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
match *self {
|
|
|
|
PanicStrategy::Abort => "abort".to_json(),
|
|
|
|
PanicStrategy::Unwind => "unwind".to_json(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
-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 type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>;
|
2016-07-24 11:47:39 -05:00
|
|
|
pub type TargetResult = Result<Target, String>;
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
macro_rules! supported_targets {
|
2016-09-15 20:46:04 -05:00
|
|
|
( $(($triple:expr, $module:ident),)+ ) => (
|
2016-02-11 00:52:44 +00:00
|
|
|
$(mod $module;)*
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
/// List of supported targets
|
2016-07-26 17:44:27 -07:00
|
|
|
const TARGETS: &'static [&'static str] = &[$($triple),*];
|
2016-02-12 10:11:58 -05:00
|
|
|
|
2016-07-24 11:47:39 -05:00
|
|
|
fn load_specific(target: &str) -> TargetResult {
|
2016-05-04 22:15:47 -05:00
|
|
|
match target {
|
|
|
|
$(
|
|
|
|
$triple => {
|
2016-08-27 07:48:39 -07:00
|
|
|
let mut t = $module::target()?;
|
2016-05-04 22:15:47 -05:00
|
|
|
t.options.is_builtin = true;
|
2016-07-23 07:22:58 -05:00
|
|
|
|
|
|
|
// round-trip through the JSON parser to ensure at
|
|
|
|
// run-time that the parser works correctly
|
2016-08-27 07:48:39 -07:00
|
|
|
t = Target::from_json(t.to_json())?;
|
2016-05-04 22:15:47 -05:00
|
|
|
debug!("Got builtin target: {:?}", t);
|
2016-07-24 11:47:39 -05:00
|
|
|
Ok(t)
|
2016-05-04 22:15:47 -05:00
|
|
|
},
|
|
|
|
)+
|
2016-07-24 11:47:39 -05:00
|
|
|
_ => Err(format!("Unable to find target: {}", target))
|
2016-05-04 22:15:47 -05:00
|
|
|
}
|
2016-02-12 10:11:58 -05:00
|
|
|
}
|
2016-07-23 07:22:58 -05:00
|
|
|
|
2018-07-12 13:26:29 +02:00
|
|
|
pub fn get_targets() -> Box<dyn Iterator<Item=String>> {
|
2016-07-26 17:44:27 -07:00
|
|
|
Box::new(TARGETS.iter().filter_map(|t| -> Option<String> {
|
|
|
|
load_specific(t)
|
2016-08-08 19:22:57 +09:00
|
|
|
.and(Ok(t.to_string()))
|
2016-07-26 17:44:27 -07:00
|
|
|
.ok()
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2016-07-23 07:22:58 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_json_encode_decode {
|
|
|
|
use serialize::json::ToJson;
|
|
|
|
use super::Target;
|
|
|
|
$(use super::$module;)*
|
|
|
|
|
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $module() {
|
|
|
|
// Grab the TargetResult struct. If we successfully retrieved
|
|
|
|
// a Target, then the test JSON encoding/decoding can run for this
|
|
|
|
// Target on this testing platform (i.e., checking the iOS targets
|
|
|
|
// only on a Mac test platform).
|
|
|
|
let _ = $module::target().map(|original| {
|
|
|
|
let as_json = original.to_json();
|
|
|
|
let parsed = Target::from_json(as_json).unwrap();
|
|
|
|
assert_eq!(original, parsed);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
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),
|
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),
|
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),
|
2016-02-12 10:11:58 -05:00
|
|
|
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
|
|
|
|
("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),
|
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),
|
2016-02-12 10:11:58 -05:00
|
|
|
("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf),
|
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),
|
2018-01-04 14:55:04 -02:00
|
|
|
|
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),
|
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),
|
2016-02-12 10:11:58 -05:00
|
|
|
("aarch64-linux-android", aarch64_linux_android),
|
|
|
|
|
2017-01-25 21:09:18 +01:00
|
|
|
("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
|
2016-02-12 10:11:58 -05:00
|
|
|
("i686-unknown-freebsd", i686_unknown_freebsd),
|
|
|
|
("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
|
|
|
|
|
|
|
|
("i686-unknown-dragonfly", i686_unknown_dragonfly),
|
|
|
|
("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly),
|
|
|
|
|
|
|
|
("x86_64-unknown-bitrig", x86_64_unknown_bitrig),
|
2016-11-29 18:49:09 +01:00
|
|
|
|
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),
|
2016-02-12 10:11:58 -05:00
|
|
|
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
|
2016-11-29 18:49:09 +01:00
|
|
|
|
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),
|
|
|
|
("x86_64-rumprun-netbsd", x86_64_rumprun_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
|
|
|
|
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
|
|
|
|
2017-08-03 10:37:11 +02:00
|
|
|
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
|
|
|
|
|
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),
|
|
|
|
|
2018-05-16 21:58:26 +02:00
|
|
|
("armebv7r-none-eabihf", armebv7r_none_eabihf),
|
|
|
|
|
2016-02-12 10:11:58 -05:00
|
|
|
("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
|
|
|
|
|
|
|
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
|
|
|
|
("i686-pc-windows-gnu", i686_pc_windows_gnu),
|
|
|
|
|
|
|
|
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
|
|
|
|
("i686-pc-windows-msvc", i686_pc_windows_msvc),
|
2016-03-03 17:23:00 -08:00
|
|
|
("i586-pc-windows-msvc", i586_pc_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),
|
2017-06-16 15:43:43 -07:00
|
|
|
("wasm32-experimental-emscripten", wasm32_experimental_emscripten),
|
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),
|
2017-07-06 15:15:44 -05:00
|
|
|
|
|
|
|
("msp430-none-elf", msp430_none_elf),
|
2017-12-22 09:37:02 +01:00
|
|
|
|
|
|
|
("aarch64-unknown-cloudabi", aarch64_unknown_cloudabi),
|
|
|
|
("armv7-unknown-cloudabi-eabihf", armv7_unknown_cloudabi_eabihf),
|
|
|
|
("i686-unknown-cloudabi", i686_unknown_cloudabi),
|
|
|
|
("x86_64-unknown-cloudabi", x86_64_unknown_cloudabi),
|
2018-07-30 15:50:51 +02:00
|
|
|
|
|
|
|
("aarch64-unknown-hermit", aarch64_unknown_hermit),
|
|
|
|
("x86_64-unknown-hermit", x86_64_unknown_hermit),
|
2018-07-26 14:01:24 +02:00
|
|
|
|
|
|
|
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
|
2016-02-12 10:11:58 -05:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
pub llvm_target: String,
|
|
|
|
/// String to use as the `target_endian` `cfg` variable.
|
|
|
|
pub target_endian: String,
|
2015-01-07 17:26:55 +13:00
|
|
|
/// String to use as the `target_pointer_width` `cfg` variable.
|
|
|
|
pub target_pointer_width: String,
|
2017-09-30 13:47:49 +02:00
|
|
|
/// Width of c_int type
|
|
|
|
pub target_c_int_width: String,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// OS name to use for conditional compilation.
|
|
|
|
pub target_os: String,
|
2015-04-21 15:53:32 -07:00
|
|
|
/// Environment name to use for conditional compilation.
|
|
|
|
pub target_env: String,
|
2015-09-24 01:20:43 +02:00
|
|
|
/// Vendor name to use for conditional compilation.
|
|
|
|
pub target_vendor: String,
|
2016-01-30 13:27:00 -08:00
|
|
|
/// Architecture to use for ABI considerations. Valid options: "x86",
|
|
|
|
/// "x86_64", "arm", "aarch64", "mips", "powerpc", and "powerpc64".
|
2014-07-23 11:56:36 -07:00
|
|
|
pub arch: String,
|
2016-04-18 15:38:45 +03:00
|
|
|
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
|
|
|
pub data_layout: String,
|
-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
|
|
|
/// Linker flavor
|
|
|
|
pub linker_flavor: LinkerFlavor,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Optional settings with defaults.
|
|
|
|
pub options: TargetOptions,
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:01:26 +03:00
|
|
|
pub trait HasTargetSpec: Copy {
|
|
|
|
fn target_spec(&self) -> &Target;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> HasTargetSpec for &'a Target {
|
|
|
|
fn target_spec(&self) -> &Target {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
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,
|
|
|
|
|
2018-02-10 12:09:25 -08:00
|
|
|
/// Linker to invoke
|
|
|
|
pub linker: Option<String>,
|
2015-10-18 14:32:50 -07:00
|
|
|
|
2018-04-29 11:17:54 +02:00
|
|
|
/// Linker arguments that are passed *before* any user-defined libraries.
|
|
|
|
pub pre_link_args: LinkArgs, // ... unconditionally
|
|
|
|
pub pre_link_args_crt: LinkArgs, // ... when linking with a bundled crt
|
2018-05-13 07:44:46 -07:00
|
|
|
/// Objects to link before all others, always found within the
|
2015-10-18 14:32:50 -07:00
|
|
|
/// sysroot folder.
|
2018-04-29 11:17:54 +02:00
|
|
|
pub pre_link_objects_exe: Vec<String>, // ... when linking an executable, unconditionally
|
|
|
|
pub pre_link_objects_exe_crt: Vec<String>, // ... when linking an executable with a bundled crt
|
2015-10-18 14:32:50 -07:00
|
|
|
pub pre_link_objects_dll: Vec<String>, // ... when linking a dylib
|
|
|
|
/// Linker arguments that are unconditionally passed after any
|
|
|
|
/// user-defined but before post_link_objects. Standard platform
|
|
|
|
/// 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,
|
2018-05-13 07:44:46 -07:00
|
|
|
/// Objects to link after all others, always found within the
|
2015-10-18 14:32:50 -07:00
|
|
|
/// sysroot folder.
|
2018-04-29 11:17:54 +02:00
|
|
|
pub post_link_objects: Vec<String>, // ... unconditionally
|
|
|
|
pub post_link_objects_crt: Vec<String>, // ... when linking with a bundled crt
|
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,
|
2015-10-18 14:32:50 -07:00
|
|
|
|
2017-06-22 15:16:54 -07:00
|
|
|
/// Environment variables to be set before invoking the linker.
|
|
|
|
pub link_env: Vec<(String, String)>,
|
|
|
|
|
2016-12-18 22:25:46 -05:00
|
|
|
/// Extra arguments to pass to the external assembler (when used)
|
|
|
|
pub asm_args: Vec<String>,
|
|
|
|
|
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".
|
2014-07-23 11:56:36 -07:00
|
|
|
pub cpu: String,
|
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`.
|
2014-07-23 11:56:36 -07:00
|
|
|
pub features: String,
|
|
|
|
/// 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
|
|
|
|
/// -relocation-model=$relocation_model`. Defaults to "pic".
|
|
|
|
pub relocation_model: String,
|
2018-01-22 17:01:36 -08:00
|
|
|
/// Code model to use. Corresponds to `llc -code-model=$code_model`.
|
|
|
|
pub code_model: Option<String>,
|
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.
|
|
|
|
pub tls_model: String,
|
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,
|
|
|
|
/// Eliminate frame pointers from stack frames if possible. Defaults to true.
|
|
|
|
pub eliminate_frame_pointer: bool,
|
|
|
|
/// 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".
|
|
|
|
pub dll_prefix: String,
|
|
|
|
/// String to append to the name of every dynamic library. Defaults to ".so".
|
|
|
|
pub dll_suffix: String,
|
|
|
|
/// String to append to the name of every executable.
|
|
|
|
pub exe_suffix: String,
|
|
|
|
/// String to prepend to the name of every static library. Defaults to "lib".
|
|
|
|
pub staticlib_prefix: String,
|
|
|
|
/// String to append to the name of every static library. Defaults to ".a".
|
|
|
|
pub staticlib_suffix: String,
|
2015-10-08 22:08:07 -04:00
|
|
|
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
|
|
|
|
pub target_family: Option<String>,
|
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,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
|
2015-03-28 18:09:51 +03:00
|
|
|
/// only really used for figuring out how to find libraries, since Windows uses its own
|
2014-07-23 11:56:36 -07:00
|
|
|
/// library naming convention. Defaults to false.
|
|
|
|
pub is_like_windows: bool,
|
2015-03-04 22:58:59 +00:00
|
|
|
pub is_like_msvc: bool,
|
2015-02-16 17:48:50 +09:00
|
|
|
/// Whether the target toolchain is like Android's. Only useful for compiling against Android.
|
|
|
|
/// Defaults to false.
|
|
|
|
pub is_like_android: bool,
|
2017-01-19 22:31:57 +03:00
|
|
|
/// Whether the target toolchain is like Emscripten's. Only useful for compiling with
|
|
|
|
/// Emscripten toolchain.
|
|
|
|
/// Defaults to false.
|
|
|
|
pub is_like_emscripten: bool,
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
|
|
|
|
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
|
|
|
|
/// codebases. Consequently we want a way to disallow weak linkage on some
|
|
|
|
/// 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,
|
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.
|
|
|
|
pub archive_format: String,
|
2015-08-20 17:47:21 -05:00
|
|
|
/// Is asm!() allowed? Defaults to true.
|
|
|
|
pub allow_asm: bool,
|
2015-07-13 18:11:44 -07:00
|
|
|
/// Whether the target uses a custom unwind resumption routine.
|
|
|
|
/// By default LLVM lowers `resume` instructions into calls to `_Unwind_Resume`
|
|
|
|
/// defined in libgcc. If this option is enabled, the target must provide
|
|
|
|
/// `eh_unwind_resume` lang item.
|
|
|
|
pub custom_unwind_resume: bool,
|
2015-06-25 10:07:01 -07:00
|
|
|
|
2017-06-03 14:54:08 -07:00
|
|
|
/// If necessary, a different crate to link exe allocators by default
|
|
|
|
pub exe_allocation_crate: Option<String>,
|
2015-12-10 12:21:55 -08:00
|
|
|
|
|
|
|
/// Flag indicating whether ELF TLS (e.g. #[thread_local]) is available for
|
|
|
|
/// this target.
|
|
|
|
pub has_elf_tls: 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,
|
2016-04-15 20:16:19 +01:00
|
|
|
|
2016-11-12 17:30:06 -05:00
|
|
|
// LLVM can't produce object files for this target. Instead, we'll make LLVM
|
|
|
|
// emit assembly and then use `gcc` to turn that assembly into an object
|
|
|
|
// file
|
|
|
|
pub no_integrated_as: bool,
|
2016-11-09 19:05:32 -05: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
|
|
|
|
|
|
|
/// A blacklist of ABIs unsupported by the current target. Note that generic
|
|
|
|
/// ABIs are considered to be supported on all platforms and cannot be blacklisted.
|
|
|
|
pub abi_blacklist: Vec<Abi>,
|
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
|
|
|
|
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
|
|
|
|
|
|
|
/// Whether or not stack probes (__rust_probestack) are enabled
|
|
|
|
pub stack_probes: bool,
|
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
|
|
|
|
|
|
|
/// Whether to lower 128-bit operations to compiler_builtins calls. Use if
|
|
|
|
/// your backend only supports 64-bit and smaller math.
|
|
|
|
pub i128_lowering: bool,
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
|
|
|
|
/// The codegen backend to use for this target, typically "llvm"
|
|
|
|
pub codegen_backend: String,
|
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
|
|
|
|
|
|
|
/// Whether or not bitcode is embedded in object files
|
|
|
|
pub embed_bitcode: bool,
|
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,
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TargetOptions {
|
2015-05-11 14:41:27 -07:00
|
|
|
/// Create a set of "sane defaults" for any target. This is still
|
|
|
|
/// 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,
|
2018-02-10 12:09:25 -08:00
|
|
|
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()),
|
-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(),
|
2018-04-29 11:17:54 +02:00
|
|
|
pre_link_args_crt: LinkArgs::new(),
|
-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
|
|
|
post_link_args: LinkArgs::new(),
|
2016-12-18 22:25:46 -05:00
|
|
|
asm_args: Vec::new(),
|
2014-07-23 11:56:36 -07:00
|
|
|
cpu: "generic".to_string(),
|
|
|
|
features: "".to_string(),
|
|
|
|
dynamic_linking: false,
|
2017-10-22 20:01:00 -07:00
|
|
|
only_cdylib: false,
|
2014-07-23 11:56:36 -07:00
|
|
|
executables: false,
|
|
|
|
relocation_model: "pic".to_string(),
|
2018-01-22 17:01:36 -08:00
|
|
|
code_model: None,
|
2017-10-31 17:45:19 +00:00
|
|
|
tls_model: "global-dynamic".to_string(),
|
2014-07-23 11:56:36 -07:00
|
|
|
disable_redzone: false,
|
|
|
|
eliminate_frame_pointer: true,
|
|
|
|
function_sections: true,
|
|
|
|
dll_prefix: "lib".to_string(),
|
|
|
|
dll_suffix: ".so".to_string(),
|
|
|
|
exe_suffix: "".to_string(),
|
|
|
|
staticlib_prefix: "lib".to_string(),
|
|
|
|
staticlib_suffix: ".a".to_string(),
|
2015-10-08 22:08:07 -04:00
|
|
|
target_family: None,
|
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-02-16 17:48:50 +09:00
|
|
|
is_like_android: false,
|
2017-01-19 22:31:57 +03:00
|
|
|
is_like_emscripten: false,
|
2015-03-04 22:58:59 +00:00
|
|
|
is_like_msvc: false,
|
2014-07-23 11:56:36 -07:00
|
|
|
linker_is_gnu: false,
|
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,
|
2018-03-09 14:53:15 +01:00
|
|
|
relro_level: RelroLevel::None,
|
2015-10-18 14:32:50 -07:00
|
|
|
pre_link_objects_exe: Vec::new(),
|
2018-04-29 11:17:54 +02:00
|
|
|
pre_link_objects_exe_crt: Vec::new(),
|
2015-10-18 14:32:50 -07:00
|
|
|
pre_link_objects_dll: Vec::new(),
|
2015-04-21 18:00:16 -07:00
|
|
|
post_link_objects: Vec::new(),
|
2018-04-29 11:17:54 +02:00
|
|
|
post_link_objects_crt: Vec::new(),
|
-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(),
|
2017-06-22 15:16:54 -07:00
|
|
|
link_env: Vec::new(),
|
2016-02-08 10:27:03 -08:00
|
|
|
archive_format: "gnu".to_string(),
|
2015-07-13 18:11:44 -07:00
|
|
|
custom_unwind_resume: false,
|
2017-06-03 14:54:08 -07:00
|
|
|
exe_allocation_crate: None,
|
2015-08-20 17:47:21 -05:00
|
|
|
allow_asm: true,
|
2015-12-10 12:21:55 -08:00
|
|
|
has_elf_tls: false,
|
2015-11-27 19:44:33 +00:00
|
|
|
obj_is_bitcode: false,
|
2016-11-12 17:30:06 -05:00
|
|
|
no_integrated_as: false,
|
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,
|
2016-10-24 11:04:04 +02:00
|
|
|
abi_blacklist: vec![],
|
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,
|
2017-06-21 12:08:18 -07:00
|
|
|
stack_probes: false,
|
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,
|
2017-12-03 21:53:48 -08:00
|
|
|
i128_lowering: false,
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
codegen_backend: "llvm".to_string(),
|
2018-01-30 11:54:07 -08:00
|
|
|
default_hidden_visibility: false,
|
2018-03-09 07:25:54 -08:00
|
|
|
embed_bitcode: 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,
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Target {
|
|
|
|
/// Given a function ABI, turn "System" 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 {
|
2016-02-05 13:13:36 +01:00
|
|
|
Abi::System => {
|
2014-11-27 13:57:31 -05:00
|
|
|
if self.options.is_like_windows && self.arch == "x86" {
|
2016-02-05 13:13:36 +01:00
|
|
|
Abi::Stdcall
|
2014-07-23 11:56:36 -07:00
|
|
|
} else {
|
2016-02-05 13:13:36 +01:00
|
|
|
Abi::C
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
abi => abi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
self.options.min_atomic_width.unwrap_or(8)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
self.options.max_atomic_width.unwrap_or(self.target_pointer_width.parse().unwrap())
|
|
|
|
}
|
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
pub fn is_abi_supported(&self, abi: Abi) -> bool {
|
|
|
|
abi.generic() || !self.options.abi_blacklist.contains(&abi)
|
|
|
|
}
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
/// Load a target descriptor from a JSON object.
|
2016-07-24 11:47:39 -05:00
|
|
|
pub fn from_json(obj: Json) -> TargetResult {
|
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
|
|
|
|
2015-02-01 12:44:15 -05:00
|
|
|
let get_req_field = |name: &str| {
|
2014-11-04 05:35:53 -05:00
|
|
|
match obj.find(name)
|
2014-07-23 11:56:36 -07:00
|
|
|
.map(|s| s.as_string())
|
|
|
|
.and_then(|os| os.map(|s| s.to_string())) {
|
2016-07-24 11:47:39 -05:00
|
|
|
Some(val) => Ok(val),
|
2015-10-23 19:42:42 -07:00
|
|
|
None => {
|
2016-07-24 11:47:39 -05:00
|
|
|
return Err(format!("Field {} in target specification is required", name))
|
2015-10-23 19:42:42 -07:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-24 01:20:43 +02:00
|
|
|
let get_opt_field = |name: &str, default: &str| {
|
|
|
|
obj.find(name).and_then(|s| s.as_string())
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
.unwrap_or(default.to_string())
|
|
|
|
};
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
let mut base = Target {
|
2016-08-27 07:48:39 -07:00
|
|
|
llvm_target: get_req_field("llvm-target")?,
|
|
|
|
target_endian: get_req_field("target-endian")?,
|
|
|
|
target_pointer_width: get_req_field("target-pointer-width")?,
|
2017-09-30 13:47:49 +02:00
|
|
|
target_c_int_width: get_req_field("target-c-int-width")?,
|
2016-08-27 07:48:39 -07:00
|
|
|
data_layout: get_req_field("data-layout")?,
|
|
|
|
arch: get_req_field("arch")?,
|
|
|
|
target_os: get_req_field("os")?,
|
2015-09-24 01:20:43 +02:00
|
|
|
target_env: get_opt_field("env", ""),
|
|
|
|
target_vendor: get_opt_field("vendor", "unknown"),
|
-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
|
|
|
linker_flavor: LinkerFlavor::from_str(&*get_req_field("linker-flavor")?)
|
|
|
|
.ok_or_else(|| {
|
|
|
|
format!("linker flavor must be {}", LinkerFlavor::one_of())
|
|
|
|
})?,
|
2014-07-23 11:56:36 -07:00
|
|
|
options: Default::default(),
|
|
|
|
};
|
|
|
|
|
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("_", "-");
|
2015-02-18 14:48:57 -05:00
|
|
|
obj.find(&name[..]).map(|o| o.as_string()
|
2014-07-23 11:56:36 -07:00
|
|
|
.map(|s| base.options.$key_name = s.to_string()));
|
|
|
|
} );
|
|
|
|
($key_name:ident, bool) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2015-02-18 14:48:57 -05:00
|
|
|
obj.find(&name[..])
|
2015-01-04 17:43:24 +13:00
|
|
|
.map(|o| o.as_boolean()
|
|
|
|
.map(|s| base.options.$key_name = s));
|
2014-07-23 11:56:36 -07: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("_", "-");
|
|
|
|
obj.find(&name[..])
|
|
|
|
.map(|o| o.as_u64()
|
2016-10-03 23:45:40 -05:00
|
|
|
.map(|s| base.options.$key_name = Some(s)));
|
2016-04-15 20:16:19 +01:00
|
|
|
} );
|
2016-09-27 21:26:08 -05:00
|
|
|
($key_name:ident, PanicStrategy) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
|
|
|
obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
|
|
|
|
match s {
|
|
|
|
"unwind" => base.options.$key_name = PanicStrategy::Unwind,
|
|
|
|
"abort" => base.options.$key_name = PanicStrategy::Abort,
|
|
|
|
_ => 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("_", "-");
|
|
|
|
obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
|
2017-07-18 01:27:55 +02:00
|
|
|
match s.parse::<RelroLevel>() {
|
|
|
|
Ok(level) => base.options.$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(()))
|
|
|
|
} );
|
2014-07-23 11:56:36 -07:00
|
|
|
($key_name:ident, list) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2015-02-18 14:48:57 -05:00
|
|
|
obj.find(&name[..]).map(|o| o.as_array()
|
2014-07-23 11:56:36 -07:00
|
|
|
.map(|v| base.options.$key_name = v.iter()
|
|
|
|
.map(|a| a.as_string().unwrap().to_string()).collect()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
2015-09-07 00:35:57 -05:00
|
|
|
($key_name:ident, optional) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
|
|
|
if let Some(o) = obj.find(&name[..]) {
|
|
|
|
base.options.$key_name = o
|
|
|
|
.as_string()
|
|
|
|
.map(|s| s.to_string() );
|
|
|
|
}
|
|
|
|
} );
|
-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("_", "-");
|
|
|
|
obj.find(&name[..]).and_then(|o| o.as_string().map(|s| {
|
|
|
|
LinkerFlavor::from_str(&s).ok_or_else(|| {
|
|
|
|
Err(format!("'{}' is not a valid value for linker-flavor. \
|
|
|
|
Use 'em', 'gcc', 'ld' or 'msvc.", s))
|
|
|
|
})
|
|
|
|
})).unwrap_or(Ok(()))
|
|
|
|
} );
|
|
|
|
($key_name:ident, link_args) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2018-07-13 10:14:16 -07:00
|
|
|
if let Some(val) = obj.find(&name[..]) {
|
|
|
|
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)| {
|
|
|
|
let s = s.as_string().ok_or_else(||
|
|
|
|
format!("{}.{}[{}]: expected a JSON string", name, k, i))?;
|
|
|
|
Ok(s.to_owned())
|
|
|
|
})
|
|
|
|
.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
|
|
|
}
|
|
|
|
base.options.$key_name = args;
|
|
|
|
}
|
|
|
|
} );
|
2017-06-23 17:26:39 -07:00
|
|
|
($key_name:ident, env) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
|
|
|
if let Some(a) = obj.find(&name[..]).and_then(|o| o.as_array()) {
|
|
|
|
for o in a {
|
|
|
|
if let Some(s) = o.as_string() {
|
|
|
|
let p = s.split('=').collect::<Vec<_>>();
|
|
|
|
if p.len() == 2 {
|
|
|
|
let k = p[0].to_string();
|
|
|
|
let v = p[1].to_string();
|
|
|
|
base.options.$key_name.push((k, v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2015-01-02 14:44:21 -08:00
|
|
|
}
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(is_builtin, bool);
|
2018-02-10 12:09:25 -08:00
|
|
|
key!(linker, optional);
|
-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);
|
2018-04-29 11:17:54 +02:00
|
|
|
key!(pre_link_args_crt, link_args);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(pre_link_objects_exe, list);
|
2018-04-29 11:17:54 +02:00
|
|
|
key!(pre_link_objects_exe_crt, list);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(pre_link_objects_dll, list);
|
-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!(late_link_args, link_args);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(post_link_objects, list);
|
2018-04-29 11:17:54 +02:00
|
|
|
key!(post_link_objects_crt, list);
|
-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);
|
2017-06-23 17:26:39 -07:00
|
|
|
key!(link_env, env);
|
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);
|
2014-07-23 11:56:36 -07:00
|
|
|
key!(relocation_model);
|
2018-01-22 17:01:36 -08:00
|
|
|
key!(code_model, optional);
|
2017-10-31 17:45:19 +00:00
|
|
|
key!(tls_model);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(disable_redzone, bool);
|
|
|
|
key!(eliminate_frame_pointer, 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);
|
2015-10-08 22:08:07 -04:00
|
|
|
key!(target_family, optional);
|
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);
|
2017-01-20 21:18:51 +03:00
|
|
|
key!(is_like_emscripten, bool);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(is_like_android, bool);
|
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);
|
2017-07-14 22:01:37 +02:00
|
|
|
try!(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);
|
2015-10-30 03:20:51 +11:00
|
|
|
key!(custom_unwind_resume, bool);
|
2017-06-03 14:54:08 -07:00
|
|
|
key!(exe_allocation_crate, optional);
|
2016-04-15 09:13:28 -05:00
|
|
|
key!(has_elf_tls, bool);
|
|
|
|
key!(obj_is_bitcode, bool);
|
2016-11-12 17:30:06 -05:00
|
|
|
key!(no_integrated_as, bool);
|
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);
|
2016-09-27 21:26:08 -05:00
|
|
|
try!(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);
|
2017-06-21 12:08:18 -07:00
|
|
|
key!(stack_probes, bool);
|
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);
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
key!(codegen_backend);
|
2018-01-30 11:54:07 -08:00
|
|
|
key!(default_hidden_visibility, bool);
|
2018-03-09 07:25:54 -08:00
|
|
|
key!(embed_bitcode, 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);
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
|
|
|
|
for name in array.iter().filter_map(|abi| abi.as_string()) {
|
|
|
|
match lookup_abi(name) {
|
|
|
|
Some(abi) => {
|
|
|
|
if abi.generic() {
|
|
|
|
return Err(format!("The ABI \"{}\" is considered to be supported on \
|
|
|
|
all targets and cannot be blacklisted", abi))
|
|
|
|
}
|
|
|
|
|
|
|
|
base.options.abi_blacklist.push(abi)
|
|
|
|
}
|
|
|
|
None => return Err(format!("Unknown ABI \"{}\" in target specification", name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 11:47:39 -05:00
|
|
|
Ok(base)
|
2014-07-23 11:56:36 -07:00
|
|
|
}
|
|
|
|
|
2015-02-26 21:00:43 -08:00
|
|
|
/// Search RUST_TARGET_PATH for a JSON file specifying the given target
|
|
|
|
/// triple. 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.
|
2014-07-23 11:56:36 -07:00
|
|
|
///
|
2015-02-26 21:00:43 -08:00
|
|
|
/// The error string could come from any of the APIs called, including
|
|
|
|
/// filesystem access and JSON decoding.
|
2018-03-14 15:27:06 +01:00
|
|
|
pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
|
2015-01-27 12:20:58 -08:00
|
|
|
use std::env;
|
|
|
|
use std::ffi::OsString;
|
2018-01-10 08:58:39 -08:00
|
|
|
use std::fs;
|
2014-07-23 11:56:36 -07:00
|
|
|
use serialize::json;
|
|
|
|
|
|
|
|
fn load_file(path: &Path) -> Result<Target, String> {
|
2018-01-10 08:58:39 -08:00
|
|
|
let contents = fs::read(path).map_err(|e| e.to_string())?;
|
2016-03-22 22:01:37 -05:00
|
|
|
let obj = json::from_reader(&mut &contents[..])
|
2016-03-22 17:58:45 -05:00
|
|
|
.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-03-14 15:27:06 +01:00
|
|
|
match target_triple {
|
|
|
|
&TargetTriple::TargetTriple(ref target_triple) => {
|
|
|
|
// check if triple is in list of supported targets
|
|
|
|
if let Ok(t) = load_specific(target_triple) {
|
|
|
|
return Ok(t)
|
|
|
|
}
|
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-03-14 15:27:06 +01:00
|
|
|
let target_path = env::var_os("RUST_TARGET_PATH")
|
|
|
|
.unwrap_or(OsString::new());
|
2014-07-23 11:56:36 -07:00
|
|
|
|
2018-03-14 15:27:06 +01:00
|
|
|
// FIXME 16351: add a sane default search path?
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(format!("Could not find specification for target {:?}", target_triple))
|
|
|
|
}
|
|
|
|
&TargetTriple::TargetPath(ref target_path) => {
|
|
|
|
if target_path.is_file() {
|
|
|
|
return load_file(&target_path);
|
|
|
|
}
|
|
|
|
Err(format!("Target path {:?} is not a valid file", target_path))
|
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 {
|
|
|
|
let mut d = BTreeMap::new();
|
|
|
|
let default: TargetOptions = Default::default();
|
|
|
|
|
|
|
|
macro_rules! target_val {
|
|
|
|
($attr:ident) => ( {
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
|
|
|
d.insert(name.to_string(), self.$attr.to_json());
|
|
|
|
} );
|
|
|
|
($attr:ident, $key_name:expr) => ( {
|
|
|
|
let name = $key_name;
|
|
|
|
d.insert(name.to_string(), self.$attr.to_json());
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! target_option_val {
|
|
|
|
($attr:ident) => ( {
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
|
|
|
if default.$attr != self.options.$attr {
|
|
|
|
d.insert(name.to_string(), self.options.$attr.to_json());
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
($attr:ident, $key_name:expr) => ( {
|
|
|
|
let name = $key_name;
|
|
|
|
if default.$attr != self.options.$attr {
|
|
|
|
d.insert(name.to_string(), self.options.$attr.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
|
|
|
(link_args - $attr:ident) => ( {
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
|
|
|
if default.$attr != self.options.$attr {
|
|
|
|
let obj = self.options.$attr
|
|
|
|
.iter()
|
|
|
|
.map(|(k, v)| (k.desc().to_owned(), v.clone()))
|
|
|
|
.collect::<BTreeMap<_, _>>();
|
|
|
|
d.insert(name.to_string(), obj.to_json());
|
|
|
|
}
|
|
|
|
} );
|
2017-06-23 17:26:39 -07:00
|
|
|
(env - $attr:ident) => ( {
|
|
|
|
let name = (stringify!($attr)).replace("_", "-");
|
|
|
|
if default.$attr != self.options.$attr {
|
|
|
|
let obj = self.options.$attr
|
|
|
|
.iter()
|
|
|
|
.map(|&(ref k, ref v)| k.clone() + "=" + &v)
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
d.insert(name.to_string(), obj.to_json());
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-04-07 22:29:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
target_val!(llvm_target);
|
|
|
|
target_val!(target_endian);
|
|
|
|
target_val!(target_pointer_width);
|
2017-09-30 13:47:49 +02:00
|
|
|
target_val!(target_c_int_width);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_val!(arch);
|
|
|
|
target_val!(target_os, "os");
|
|
|
|
target_val!(target_env, "env");
|
|
|
|
target_val!(target_vendor, "vendor");
|
|
|
|
target_val!(data_layout);
|
-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_val!(linker_flavor);
|
2016-04-07 22:29:01 -05:00
|
|
|
|
|
|
|
target_option_val!(is_builtin);
|
|
|
|
target_option_val!(linker);
|
-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);
|
2018-04-29 11:17:54 +02:00
|
|
|
target_option_val!(link_args - pre_link_args_crt);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(pre_link_objects_exe);
|
2018-04-29 11:17:54 +02:00
|
|
|
target_option_val!(pre_link_objects_exe_crt);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(pre_link_objects_dll);
|
-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 - late_link_args);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(post_link_objects);
|
2018-04-29 11:17:54 +02:00
|
|
|
target_option_val!(post_link_objects_crt);
|
-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);
|
2017-06-23 17:26:39 -07:00
|
|
|
target_option_val!(env - link_env);
|
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);
|
|
|
|
target_option_val!(eliminate_frame_pointer);
|
|
|
|
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);
|
|
|
|
target_option_val!(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);
|
2017-01-20 21:18:51 +03:00
|
|
|
target_option_val!(is_like_emscripten);
|
2016-04-07 22:29:01 -05:00
|
|
|
target_option_val!(is_like_android);
|
|
|
|
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);
|
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);
|
|
|
|
target_option_val!(custom_unwind_resume);
|
|
|
|
target_option_val!(exe_allocation_crate);
|
|
|
|
target_option_val!(has_elf_tls);
|
|
|
|
target_option_val!(obj_is_bitcode);
|
2016-11-12 17:30:06 -05:00
|
|
|
target_option_val!(no_integrated_as);
|
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);
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
target_option_val!(codegen_backend);
|
2018-01-30 11:54:07 -08:00
|
|
|
target_option_val!(default_hidden_visibility);
|
2018-03-09 07:25:54 -08:00
|
|
|
target_option_val!(embed_bitcode);
|
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);
|
2016-04-07 22:29:01 -05:00
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
if default.abi_blacklist != self.options.abi_blacklist {
|
|
|
|
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
|
|
|
|
.map(Abi::name).map(|name| name.to_json())
|
|
|
|
.collect::<Vec<_>>().to_json());
|
|
|
|
}
|
|
|
|
|
2016-04-07 22:29:01 -05:00
|
|
|
Json::Object(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-03 14:54:08 -07:00
|
|
|
fn maybe_jemalloc() -> Option<String> {
|
2016-01-21 18:37:46 -08:00
|
|
|
if cfg!(feature = "jemalloc") {
|
2017-06-03 14:54:08 -07:00
|
|
|
Some("alloc_jemalloc".to_string())
|
2016-01-21 18:37:46 -08:00
|
|
|
} else {
|
2017-06-03 14:54:08 -07:00
|
|
|
None
|
2015-06-25 10:07:01 -07:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:27:06 +01:00
|
|
|
|
|
|
|
/// Either a target triple string or a path to a JSON file.
|
|
|
|
#[derive(PartialEq, Clone, Debug, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum TargetTriple {
|
|
|
|
TargetTriple(String),
|
|
|
|
TargetPath(PathBuf),
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
TargetTriple::TargetTriple(triple.to_string())
|
|
|
|
}
|
|
|
|
|
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()?;
|
|
|
|
Ok(TargetTriple::TargetPath(canonicalized_path))
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
match self {
|
|
|
|
&TargetTriple::TargetTriple(ref triple) => triple,
|
|
|
|
&TargetTriple::TargetPath(ref path) => {
|
|
|
|
path.file_stem().expect("target path must not be empty").to_str()
|
|
|
|
.expect("target path must be valid unicode")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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::hash::{Hash, Hasher};
|
|
|
|
use std::collections::hash_map::DefaultHasher;
|
|
|
|
|
|
|
|
let triple = self.triple();
|
|
|
|
if let &TargetTriple::TargetPath(ref path) = self {
|
|
|
|
let mut hasher = DefaultHasher::new();
|
|
|
|
path.hash(&mut hasher);
|
|
|
|
let hash = hasher.finish();
|
|
|
|
format!("{}-{}", triple, hash)
|
|
|
|
} else {
|
|
|
|
triple.to_owned()
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for TargetTriple {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|