2014-07-04 19:41:54 -07:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// 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.
|
|
|
|
|
2014-07-06 21:58:30 -07:00
|
|
|
//! Some stuff used by rustc that doesn't have many dependencies
|
|
|
|
//!
|
|
|
|
//! Originally extracted from rustc::back, which was nominally the
|
|
|
|
//! compiler 'backend', though LLVM is rustc's backend, so rustc_back
|
|
|
|
//! is really just odds-and-ends relating to code gen and linking.
|
|
|
|
//! This crate mostly exists to make rustc smaller, so we might put
|
|
|
|
//! more 'stuff' here in the future. It does not have a dependency on
|
|
|
|
//! rustc_llvm.
|
|
|
|
//!
|
|
|
|
//! FIXME: Split this into two crates: one that has deps on syntax, and
|
|
|
|
//! one that doesn't; the one that doesn't might get decent parallel
|
|
|
|
//! build speedups.
|
|
|
|
|
2015-08-09 14:15:05 -07:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-05-15 16:04:01 -07:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
2015-08-09 14:15:05 -07:00
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
2016-12-29 09:47:34 -08:00
|
|
|
#![deny(warnings)]
|
2015-01-30 12:26:44 -08:00
|
|
|
|
|
|
|
#![feature(box_syntax)]
|
2016-03-07 15:42:29 -08:00
|
|
|
#![feature(const_fn)]
|
2018-01-10 08:58:39 -08:00
|
|
|
#![feature(fs_read_write)]
|
2014-12-31 20:43:46 -08:00
|
|
|
|
2014-07-04 19:41:54 -07:00
|
|
|
extern crate syntax;
|
2017-11-01 12:32:13 -07:00
|
|
|
extern crate rand;
|
2014-07-06 22:21:04 -07:00
|
|
|
extern crate serialize;
|
2015-01-06 09:24:46 -08:00
|
|
|
#[macro_use] extern crate log;
|
2014-07-04 19:41:54 -07:00
|
|
|
|
2016-09-27 21:26:08 -05:00
|
|
|
extern crate serialize as rustc_serialize; // used by deriving
|
|
|
|
|
2014-07-23 11:56:36 -07:00
|
|
|
pub mod target;
|
2016-09-27 21:26:08 -05:00
|
|
|
|
2017-07-18 01:27:55 +02:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2016-09-27 21:26:08 -05:00
|
|
|
use serialize::json::{Json, ToJson};
|
|
|
|
|
-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
|
|
|
macro_rules! linker_flavor {
|
|
|
|
($(($variant:ident, $string:expr),)+) => {
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash,
|
|
|
|
RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum LinkerFlavor {
|
|
|
|
$($variant,)+
|
|
|
|
}
|
|
|
|
|
|
|
|
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 => LinkerFlavor::$variant,)+
|
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
$(LinkerFlavor::$variant => $string,)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToJson for LinkerFlavor {
|
|
|
|
fn to_json(&self) -> Json {
|
|
|
|
self.desc().to_json()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
linker_flavor! {
|
|
|
|
(Em, "em"),
|
2017-10-22 20:01:00 -07:00
|
|
|
(Binaryen, "binaryen"),
|
-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
|
|
|
(Gcc, "gcc"),
|
|
|
|
(Ld, "ld"),
|
|
|
|
(Msvc, "msvc"),
|
|
|
|
}
|
|
|
|
|
2016-09-27 21:26:08 -05:00
|
|
|
#[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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-14 22:01:37 +02:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum RelroLevel {
|
|
|
|
Full,
|
|
|
|
Partial,
|
|
|
|
Off,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RelroLevel {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
RelroLevel::Full => "full",
|
|
|
|
RelroLevel::Partial => "partial",
|
|
|
|
RelroLevel::Off => "off",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 01:27:55 +02:00
|
|
|
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),
|
|
|
|
_ => Err(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:01:37 +02:00
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|