Skip to content

Commit 502d6aa

Browse files
committed
Auto merge of rust-lang#93854 - matthiaskrgr:rollup-bh2a85j, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#92670 (add kernel target for RustyHermit) - rust-lang#93756 (Support custom options for LLVM build) - rust-lang#93802 (fix oversight in the `min_const_generics` checks) - rust-lang#93808 (Remove first headings indent) - rust-lang#93824 (Stabilize cfg_target_has_atomic) - rust-lang#93830 (Refactor sidebar printing code) - rust-lang#93843 (kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 56cd04a + 8c60f44 commit 502d6aa

34 files changed

+445
-599
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ declare_features! (
7272
(accepted, cfg_doctest, "1.40.0", Some(62210), None),
7373
/// Allows `cfg(target_feature = "...")`.
7474
(accepted, cfg_target_feature, "1.27.0", Some(29717), None),
75+
/// Allows `cfg(target_has_atomic = "...")`.
76+
(accepted, cfg_target_has_atomic, "1.60.0", Some(32976), None),
7577
/// Allows `cfg(target_vendor = "...")`.
7678
(accepted, cfg_target_vendor, "1.33.0", Some(29718), None),
7779
/// Allows implementing `Clone` for closures where possible (RFC 2132).

compiler/rustc_feature/src/active.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ declare_features! (
309309
(active, cfg_sanitize, "1.41.0", Some(39699), None),
310310
/// Allows `cfg(target_abi = "...")`.
311311
(active, cfg_target_abi, "1.55.0", Some(80970), None),
312-
/// Allows `cfg(target_has_atomic = "...")`.
313-
(active, cfg_target_has_atomic, "1.9.0", Some(32976), None),
312+
/// Allows `cfg(target_has_atomic_equal_alignment = "...")`.
313+
(active, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822), None),
314314
/// Allows `cfg(target_thread_local)`.
315315
(active, cfg_target_thread_local, "1.7.0", Some(29594), None),
316316
/// Allow conditional compilation depending on rust version

compiler/rustc_feature/src/builtin_attrs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ const GATED_CFGS: &[GatedCfg] = &[
2626
// (name in cfg, feature, function to check if the feature is enabled)
2727
(sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
2828
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
29-
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
30-
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
3129
(
3230
sym::target_has_atomic_equal_alignment,
33-
sym::cfg_target_has_atomic,
34-
cfg_fn!(cfg_target_has_atomic),
31+
sym::cfg_target_has_atomic_equal_alignment,
32+
cfg_fn!(cfg_target_has_atomic_equal_alignment),
3533
),
3634
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
3735
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ symbols! {
421421
cfg_target_abi,
422422
cfg_target_feature,
423423
cfg_target_has_atomic,
424+
cfg_target_has_atomic_equal_alignment,
424425
cfg_target_thread_local,
425426
cfg_target_vendor,
426427
cfg_version,

compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::spec::Target;
33
pub fn target() -> Target {
44
let mut base = super::hermit_base::opts();
55
base.max_atomic_width = Some(128);
6+
base.features = "+strict-align,+neon,+fp-armv8".to_string();
67

78
Target {
89
llvm_target: "aarch64-unknown-hermit".to_string(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::Target;
2+
3+
pub fn target() -> Target {
4+
let mut base = super::hermit_kernel_base::opts();
5+
base.max_atomic_width = Some(128);
6+
base.abi = "softfloat".to_string();
7+
base.features = "+strict-align,-neon,-fp-armv8".to_string();
8+
9+
Target {
10+
llvm_target: "aarch64-unknown-hermit".to_string(),
11+
pointer_width: 64,
12+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
13+
arch: "aarch64".to_string(),
14+
options: base,
15+
}
16+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ supported_targets! {
964964
("aarch64-unknown-hermit", aarch64_unknown_hermit),
965965
("x86_64-unknown-hermit", x86_64_unknown_hermit),
966966

967+
("aarch64-unknown-none-hermitkernel", aarch64_unknown_none_hermitkernel),
967968
("x86_64-unknown-none-hermitkernel", x86_64_unknown_none_hermitkernel),
968969

969970
("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),

compiler/rustc_typeck/src/astconv/mod.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -2281,8 +2281,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22812281
assert_eq!(opt_self_ty, None);
22822282
self.prohibit_generics(path.segments);
22832283
// Try to evaluate any array length constants.
2284-
let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id));
2285-
if forbid_generic && normalized_ty.needs_subst() {
2284+
let ty = tcx.at(span).type_of(def_id);
2285+
// HACK(min_const_generics): Forbid generic `Self` types
2286+
// here as we can't easily do that during nameres.
2287+
//
2288+
// We do this before normalization as we otherwise allow
2289+
// ```rust
2290+
// trait AlwaysApplicable { type Assoc; }
2291+
// impl<T: ?Sized> AlwaysApplicable for T { type Assoc = usize; }
2292+
//
2293+
// trait BindsParam<T> {
2294+
// type ArrayTy;
2295+
// }
2296+
// impl<T> BindsParam<T> for <T as AlwaysApplicable>::Assoc {
2297+
// type ArrayTy = [u8; Self::MAX];
2298+
// }
2299+
// ```
2300+
// Note that the normalization happens in the param env of
2301+
// the anon const, which is empty. This is why the
2302+
// `AlwaysApplicable` impl needs a `T: ?Sized` bound for
2303+
// this to compile if we were to normalize here.
2304+
if forbid_generic && ty.needs_subst() {
22862305
let mut err = tcx.sess.struct_span_err(
22872306
path.span,
22882307
"generic `Self` types are currently not permitted in anonymous constants",
@@ -2297,7 +2316,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22972316
err.emit();
22982317
tcx.ty_error()
22992318
} else {
2300-
normalized_ty
2319+
self.normalize_ty(span, ty)
23012320
}
23022321
}
23032322
Res::Def(DefKind::AssocTy, def_id) => {

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ changelog-seen = 2
157157
# Whether to build the clang compiler.
158158
#clang = false
159159

160+
# Custom CMake defines to set when building LLVM.
161+
#build-config = {}
162+
160163
# =============================================================================
161164
# General build configuration options
162165
# =============================================================================

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
#![feature(associated_type_bounds)]
141141
#![feature(box_syntax)]
142142
#![feature(cfg_sanitize)]
143-
#![feature(cfg_target_has_atomic)]
143+
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
144144
#![feature(const_deref)]
145145
#![feature(const_fn_trait_bound)]
146146
#![feature(const_mut_refs)]

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
#![feature(allow_internal_unstable)]
156156
#![feature(associated_type_bounds)]
157157
#![feature(auto_traits)]
158-
#![feature(cfg_target_has_atomic)]
158+
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
159+
#![cfg_attr(not(bootstrap), feature(cfg_target_has_atomic_equal_alignment))]
159160
#![feature(const_fn_floating_point_arithmetic)]
160161
#![feature(const_fn_fn_ptr_basics)]
161162
#![feature(const_fn_trait_bound)]

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![feature(box_syntax)]
88
#![feature(cell_update)]
99
#![feature(cfg_panic)]
10-
#![feature(cfg_target_has_atomic)]
10+
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
1111
#![feature(const_assume)]
1212
#![feature(const_black_box)]
1313
#![feature(const_bool_to_option)]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
#![feature(c_variadic)]
243243
#![feature(cfg_accessible)]
244244
#![feature(cfg_eval)]
245-
#![feature(cfg_target_has_atomic)]
245+
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
246246
#![feature(cfg_target_thread_local)]
247247
#![feature(char_error_internals)]
248248
#![feature(char_internals)]

library/std/src/sys/itron/condvar.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ unsafe impl Sync for Condvar {}
1515
pub type MovableCondvar = Condvar;
1616

1717
impl Condvar {
18+
#[inline]
1819
pub const fn new() -> Condvar {
1920
Condvar { waiters: SpinMutex::new(waiter_queue::WaiterQueue::new()) }
2021
}
2122

23+
#[inline]
2224
pub unsafe fn init(&mut self) {}
2325

2426
pub unsafe fn notify_one(&self) {
@@ -190,7 +192,7 @@ mod waiter_queue {
190192
let insert_after = {
191193
let mut cursor = head.last;
192194
loop {
193-
if waiter.priority <= cursor.as_ref().priority {
195+
if waiter.priority >= cursor.as_ref().priority {
194196
// `cursor` and all previous waiters have the same or higher
195197
// priority than `current_task_priority`. Insert the new
196198
// waiter right after `cursor`.
@@ -206,14 +208,16 @@ mod waiter_queue {
206208

207209
if let Some(mut insert_after) = insert_after {
208210
// Insert `waiter` after `insert_after`
209-
let insert_before = insert_after.as_ref().prev;
211+
let insert_before = insert_after.as_ref().next;
210212

211213
waiter.prev = Some(insert_after);
212214
insert_after.as_mut().next = Some(waiter_ptr);
213215

214216
waiter.next = insert_before;
215217
if let Some(mut insert_before) = insert_before {
216218
insert_before.as_mut().prev = Some(waiter_ptr);
219+
} else {
220+
head.last = waiter_ptr;
217221
}
218222
} else {
219223
// Insert `waiter` to the front
@@ -240,11 +244,11 @@ mod waiter_queue {
240244
match (waiter.prev, waiter.next) {
241245
(Some(mut prev), Some(mut next)) => {
242246
prev.as_mut().next = Some(next);
243-
next.as_mut().next = Some(prev);
247+
next.as_mut().prev = Some(prev);
244248
}
245249
(None, Some(mut next)) => {
246250
head.first = next;
247-
next.as_mut().next = None;
251+
next.as_mut().prev = None;
248252
}
249253
(Some(mut prev), None) => {
250254
prev.as_mut().next = None;
@@ -271,6 +275,7 @@ mod waiter_queue {
271275
unsafe { waiter.as_ref().task != 0 }
272276
}
273277

278+
#[inline]
274279
pub fn pop_front(&mut self) -> Option<abi::ID> {
275280
unsafe {
276281
let head = self.head.as_mut()?;

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub struct Config {
108108
pub llvm_polly: bool,
109109
pub llvm_clang: bool,
110110
pub llvm_from_ci: bool,
111+
pub llvm_build_config: HashMap<String, String>,
111112

112113
pub use_lld: bool,
113114
pub lld_enabled: bool,
@@ -477,6 +478,7 @@ derive_merge! {
477478
polly: Option<bool>,
478479
clang: Option<bool>,
479480
download_ci_llvm: Option<StringOrBool>,
481+
build_config: Option<HashMap<String, String>>,
480482
}
481483
}
482484

@@ -807,6 +809,7 @@ impl Config {
807809
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.unwrap_or(false);
808810
config.llvm_polly = llvm.polly.unwrap_or(false);
809811
config.llvm_clang = llvm.clang.unwrap_or(false);
812+
config.llvm_build_config = llvm.build_config.clone().unwrap_or(Default::default());
810813
config.llvm_from_ci = match llvm.download_ci_llvm {
811814
Some(StringOrBool::String(s)) => {
812815
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
@@ -876,6 +879,7 @@ impl Config {
876879
check_ci_llvm!(llvm.allow_old_toolchain);
877880
check_ci_llvm!(llvm.polly);
878881
check_ci_llvm!(llvm.clang);
882+
check_ci_llvm!(llvm.build_config);
879883
check_ci_llvm!(llvm.plugins);
880884

881885
// CI-built LLVM can be either dynamic or static.

src/bootstrap/native.rs

+4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ impl Step for Llvm {
353353

354354
configure_cmake(builder, target, &mut cfg, true);
355355

356+
for (key, val) in &builder.config.llvm_build_config {
357+
cfg.define(key, val);
358+
}
359+
356360
// FIXME: we don't actually need to build all LLVM tools and all LLVM
357361
// libraries here, e.g., we just want a few components and a few
358362
// tools. Figure out how to filter them down and only build the right

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1818
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
1919
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
20+
- [aarch64-unknown-none-hermitkernel](platform-support/aarch64-unknown-none-hermitkernel.md)
2021
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
2122
- [*-unknown-openbsd](platform-support/openbsd.md)
2223
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)

src/doc/rustc/src/platform-support.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ target | std | host | notes
204204
`aarch64-apple-tvos` | * | | ARM64 tvOS
205205
[`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3
206206
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
207-
`aarch64-unknown-hermit` | ? | |
207+
`aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore
208+
[`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel
208209
`aarch64-unknown-uefi` | * | | ARM64 UEFI
209210
`aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)
210211
`aarch64-unknown-netbsd` | ✓ | ✓ |
@@ -286,10 +287,10 @@ target | std | host | notes
286287
`x86_64-sun-solaris` | ? | | Deprecated target for 64-bit Solaris 10/11, illumos
287288
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
288289
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
289-
`x86_64-unknown-hermit` | ? | |
290+
`x86_64-unknown-hermit` | | | HermitCore
290291
`x86_64-unknown-l4re-uclibc` | ? | |
291292
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat
292-
`x86_64-unknown-none-hermitkernel` | ? | | HermitCore kernel
293+
`x86_64-unknown-none-hermitkernel` | * | | HermitCore kernel
293294
`x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules
294295
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
295296
`x86_64-unknown-uefi` | * | | 64-bit UEFI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# `aarch64-unknown-none-hermitkernel`
2+
3+
**Tier: 3**
4+
5+
Required to build the kernel for [HermitCore](https://github.com/hermitcore/hermit-playground)
6+
or [RustyHermit](https://github.com/hermitcore/rusty-hermit).
7+
The result is a bare-metal aarch64 binary in ELF format.
8+
9+
## Target maintainers
10+
11+
- Stefan Lankes, https://github.com/stlankes
12+
13+
## Requirements
14+
15+
This target is cross-compiled. There is no support for `std`, but the
16+
library operating system provides a simple allocator to use `alloc`.
17+
18+
By default, Rust code generated for this target does not use any vector or
19+
floating-point registers. This allows the generated code to build the library
20+
operaring system, which may need to avoid the use of such
21+
registers or which may have special considerations about the use of such
22+
registers (e.g. saving and restoring them to avoid breaking userspace code
23+
using the same registers). In contrast to `aarch64-unknown-none-softfloat`,
24+
the target is completly relocatable, which is a required feature of RustyHermit.
25+
26+
By default, code generated with this target should run on any `aarch64`
27+
hardware; enabling additional target features may raise this baseline.
28+
On `aarch64-unknown-none-hermitkernel`, `extern "C"` uses the [standard System V calling
29+
convention](https://github.com/ARM-software/abi-aa/releases/download/2021Q3/sysvabi64.pdf),
30+
without red zones.
31+
32+
This target generated binaries in the ELF format.
33+
34+
## Building the target
35+
36+
Typical you should not use the target directly. The target `aarch64-unknown-hermit`
37+
builds the _user space_ of RustyHermit and supports red zones and floating-point
38+
operations.
39+
To build and link the kernel to the application, the crate
40+
[hermit-sys](https://github.com/hermitcore/rusty-hermit/tree/master/hermit-sys)
41+
should be used by adding the following lines to the `Cargo.toml` file of
42+
your application.
43+
44+
```toml
45+
[target.'cfg(target_os = "hermit")'.dependencies]
46+
hermit-sys = "0.1.*"
47+
```
48+
49+
The crate `hermit-sys` uses the target `aarch64-unknown-none-hermitkernel`
50+
to build the kernel.
51+
52+
## Building Rust programs
53+
54+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
55+
this target, you need to build the crate `hermit-sys` (see
56+
"Building the target" above).
57+
58+
## Testing
59+
60+
As `aarch64-unknown-none-hermitkernel` does not support `std`
61+
and does not support running any Rust testsuite.
62+
63+
## Cross-compilation toolchains and C code
64+
65+
If you want to compile C code along with Rust you will need an
66+
appropriate `aarch64` toolchain.
67+
68+
Rust *may* be able to use an `aarch64-linux-gnu-` toolchain with appropriate
69+
standalone flags to build for this toolchain (depending on the assumptions of
70+
that toolchain, see below), or you may wish to use a separate
71+
`aarch64-unknown-none` (or `aarch64-elf-`) toolchain.
72+
73+
On some `aarch64` hosts that use ELF binaries, you *may* be able to use the host
74+
C toolchain, if it does not introduce assumptions about the host environment
75+
that don't match the expectations of a standalone environment. Otherwise, you
76+
may need a separate toolchain for standalone/freestanding development, just as
77+
when cross-compiling from a non-`aarch64` platform.

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = SpannedEvent<'a>>> Iterator
565565
self.buf.push_back((Event::Html(format!("</a></h{}>", level).into()), 0..0));
566566

567567
let start_tags = format!(
568-
"<h{level} id=\"{id}\" class=\"section-header\">\
568+
"<h{level} id=\"{id}\">\
569569
<a href=\"#{id}\">",
570570
id = id,
571571
level = level

0 commit comments

Comments
 (0)