Skip to content

Commit 14ee63a

Browse files
committed
Auto merge of #134765 - Noratrieb:linux-none-cant-unwind-silly, r=jieyouxu
Improve default target options for x86_64-unknown-linux-none Without a standard library, we cannot unwind, so it should be panic=abort by default. Additionally, it does not have std because while it is Linux, it cannot use libc, which std uses today for Linux. Using PIE by default may be surprising to users, as shown in #134763, so I've documented it explicitly. I'm not sure if we want to count that as fixing the issue or not. cc `@morr0ne,` as you added the target (and are the maintainer), and `@Noratrieb,` who reviewed that PR (:D).
2 parents 5c0a6e6 + b235cc9 commit 14ee63a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_none.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, StackProbeType, Target, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::linux::opts();
@@ -7,14 +7,15 @@ pub(crate) fn target() -> Target {
77
base.stack_probes = StackProbeType::Inline;
88
base.linker_flavor = LinkerFlavor::Gnu(Cc::No, Lld::Yes);
99
base.linker = Some("rust-lld".into());
10+
base.panic_strategy = PanicStrategy::Abort;
1011

1112
Target {
1213
llvm_target: "x86_64-unknown-linux-none".into(),
1314
metadata: crate::spec::TargetMetadata {
1415
description: None,
1516
tier: None,
1617
host_tools: None,
17-
std: Some(true),
18+
std: Some(false),
1819
},
1920
pointer_width: 64,
2021
data_layout:

src/doc/rustc/src/platform-support/x86_64-unknown-linux-none.md

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ This target is cross compiled and can be built from any host.
1414

1515
This target has no support for host tools, std, or alloc.
1616

17+
One of the primary motivations of the target is to write a dynamic linker and libc in Rust.
18+
For that, the target defaults to position-independent code and position-independent executables (PIE) by default.
19+
PIE binaries need relocation at runtime. This is usually done by the dynamic linker or libc.
20+
You can use `-Crelocation-model=static` to create a position-dependent binary that does not need relocation at runtime.
21+
1722
## Building the target
1823

1924
The target can be built by enabling it for a `rustc` build:

0 commit comments

Comments
 (0)