2020-04-29 20:47:07 +03:00
|
|
|
use crate::spec::{crt_objects, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions};
|
2016-10-18 13:43:18 -07:00
|
|
|
|
|
|
|
|
pub fn opts() -> TargetOptions {
|
2018-11-22 00:59:37 -08:00
|
|
|
let mut pre_link_args = LinkArgs::new();
|
2019-12-22 17:42:04 -05:00
|
|
|
pre_link_args.insert(
|
|
|
|
|
LinkerFlavor::Lld(LldFlavor::Ld),
|
|
|
|
|
vec![
|
|
|
|
|
"--build-id".to_string(),
|
|
|
|
|
"--hash-style=gnu".to_string(),
|
|
|
|
|
"-z".to_string(),
|
2020-05-11 10:37:35 -07:00
|
|
|
"max-page-size=4096".to_string(),
|
|
|
|
|
"-z".to_string(),
|
|
|
|
|
"now".to_string(),
|
|
|
|
|
"-z".to_string(),
|
2019-12-22 17:42:04 -05:00
|
|
|
"rodynamic".to_string(),
|
2020-05-11 10:37:35 -07:00
|
|
|
"-z".to_string(),
|
|
|
|
|
"separate-loadable-segments".to_string(),
|
|
|
|
|
"--pack-dyn-relocs=relr".to_string(),
|
2019-12-22 17:42:04 -05:00
|
|
|
],
|
|
|
|
|
);
|
-Z linker-flavor
This patch adds a `-Z linker-flavor` flag to rustc which can be used to invoke
the linker using a different interface.
For example, by default rustc assumes that all the Linux targets will be linked
using GCC. This makes it impossible to use LLD as a linker using just `-C
linker=ld.lld` because that will invoke LLD with invalid command line
arguments. (e.g. rustc will pass -Wl,--gc-sections to LLD but LLD doesn't
understand that; --gc-sections would be the right argument)
With this patch one can pass `-Z linker-flavor=ld` to rustc to invoke the linker
using a LD-like interface. This way, `rustc -C linker=ld.lld -Z
linker-flavor=ld` will invoke LLD with the right arguments.
`-Z linker-flavor` accepts 4 different arguments: `em` (emcc), `ld`,
`gcc`, `msvc` (link.exe). `em`, `gnu` and `msvc` cover all the existing linker
interfaces. `ld` is a new flavor for interfacing GNU's ld and LLD.
This patch also changes target specifications. `linker-flavor` is now a
mandatory field that specifies the *default* linker flavor that the target will
use. This change also makes the linker interface *explicit*; before, it used to
be derived from other fields like linker-is-gnu, is-like-msvc,
is-like-emscripten, etc.
Another change to target specifications is that the fields `pre-link-args`,
`post-link-args` and `late-link-args` now expect a map from flavor to linker
arguments.
``` diff
- "pre-link-args": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "pre-link-args": {
+ "gcc": ["-Wl,--as-needed", "-Wl,-z,-noexecstack"],
+ "ld": ["--as-needed", "-z,-noexecstack"],
+ },
```
[breaking-change] for users of custom targets specifications
2017-02-21 14:47:15 -05:00
|
|
|
|
2016-10-18 13:43:18 -07:00
|
|
|
TargetOptions {
|
2020-10-08 20:54:45 +03:00
|
|
|
target_os: "fuchsia".to_string(),
|
2020-10-08 22:10:13 +03:00
|
|
|
target_vendor: String::new(),
|
2018-10-15 17:27:07 -07:00
|
|
|
linker: Some("rust-lld".to_owned()),
|
|
|
|
|
lld_flavor: LldFlavor::Ld,
|
2016-10-18 13:43:18 -07:00
|
|
|
dynamic_linking: true,
|
|
|
|
|
executables: true,
|
2016-12-22 22:20:47 -07:00
|
|
|
target_family: Some("unix".to_string()),
|
2018-11-22 00:59:37 -08:00
|
|
|
is_like_fuchsia: true,
|
2016-10-18 13:43:18 -07:00
|
|
|
linker_is_gnu: true,
|
2018-07-26 17:57:20 -07:00
|
|
|
has_rpath: false,
|
2019-06-25 23:22:45 +02:00
|
|
|
pre_link_args,
|
2020-04-29 20:47:07 +03:00
|
|
|
pre_link_objects: crt_objects::new(&[
|
|
|
|
|
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
|
|
|
|
|
(LinkOutputKind::DynamicPicExe, &["Scrt1.o"]),
|
|
|
|
|
(LinkOutputKind::StaticNoPicExe, &["Scrt1.o"]),
|
|
|
|
|
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
|
|
|
|
|
]),
|
2016-10-18 13:43:18 -07:00
|
|
|
position_independent_executables: true,
|
|
|
|
|
has_elf_tls: true,
|
2019-12-22 17:42:04 -05:00
|
|
|
..Default::default()
|
2016-10-18 13:43:18 -07:00
|
|
|
}
|
|
|
|
|
}
|