Skip to content

Commit

Permalink
Auto merge of rust-lang#93854 - matthiaskrgr:rollup-bh2a85j, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

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
  • Loading branch information
bors committed Feb 10, 2022
2 parents 56cd04a + 8c60f44 commit 502d6aa
Show file tree
Hide file tree
Showing 34 changed files with 445 additions and 599 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ declare_features! (
(accepted, cfg_doctest, "1.40.0", Some(62210), None),
/// Allows `cfg(target_feature = "...")`.
(accepted, cfg_target_feature, "1.27.0", Some(29717), None),
/// Allows `cfg(target_has_atomic = "...")`.
(accepted, cfg_target_has_atomic, "1.60.0", Some(32976), None),
/// Allows `cfg(target_vendor = "...")`.
(accepted, cfg_target_vendor, "1.33.0", Some(29718), None),
/// Allows implementing `Clone` for closures where possible (RFC 2132).
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ declare_features! (
(active, cfg_sanitize, "1.41.0", Some(39699), None),
/// Allows `cfg(target_abi = "...")`.
(active, cfg_target_abi, "1.55.0", Some(80970), None),
/// Allows `cfg(target_has_atomic = "...")`.
(active, cfg_target_has_atomic, "1.9.0", Some(32976), None),
/// Allows `cfg(target_has_atomic_equal_alignment = "...")`.
(active, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822), None),
/// Allows `cfg(target_thread_local)`.
(active, cfg_target_thread_local, "1.7.0", Some(29594), None),
/// Allow conditional compilation depending on rust version
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ const GATED_CFGS: &[GatedCfg] = &[
// (name in cfg, feature, function to check if the feature is enabled)
(sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
(
sym::target_has_atomic_equal_alignment,
sym::cfg_target_has_atomic,
cfg_fn!(cfg_target_has_atomic),
sym::cfg_target_has_atomic_equal_alignment,
cfg_fn!(cfg_target_has_atomic_equal_alignment),
),
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ symbols! {
cfg_target_abi,
cfg_target_feature,
cfg_target_has_atomic,
cfg_target_has_atomic_equal_alignment,
cfg_target_thread_local,
cfg_target_vendor,
cfg_version,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::spec::Target;
pub fn target() -> Target {
let mut base = super::hermit_base::opts();
base.max_atomic_width = Some(128);
base.features = "+strict-align,+neon,+fp-armv8".to_string();

Target {
llvm_target: "aarch64-unknown-hermit".to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::hermit_kernel_base::opts();
base.max_atomic_width = Some(128);
base.abi = "softfloat".to_string();
base.features = "+strict-align,-neon,-fp-armv8".to_string();

Target {
llvm_target: "aarch64-unknown-hermit".to_string(),
pointer_width: 64,
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: base,
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ supported_targets! {
("aarch64-unknown-hermit", aarch64_unknown_hermit),
("x86_64-unknown-hermit", x86_64_unknown_hermit),

("aarch64-unknown-none-hermitkernel", aarch64_unknown_none_hermitkernel),
("x86_64-unknown-none-hermitkernel", x86_64_unknown_none_hermitkernel),

("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
Expand Down
25 changes: 22 additions & 3 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,8 +2281,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(path.segments);
// Try to evaluate any array length constants.
let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id));
if forbid_generic && normalized_ty.needs_subst() {
let ty = tcx.at(span).type_of(def_id);
// HACK(min_const_generics): Forbid generic `Self` types
// here as we can't easily do that during nameres.
//
// We do this before normalization as we otherwise allow
// ```rust
// trait AlwaysApplicable { type Assoc; }
// impl<T: ?Sized> AlwaysApplicable for T { type Assoc = usize; }
//
// trait BindsParam<T> {
// type ArrayTy;
// }
// impl<T> BindsParam<T> for <T as AlwaysApplicable>::Assoc {
// type ArrayTy = [u8; Self::MAX];
// }
// ```
// Note that the normalization happens in the param env of
// the anon const, which is empty. This is why the
// `AlwaysApplicable` impl needs a `T: ?Sized` bound for
// this to compile if we were to normalize here.
if forbid_generic && ty.needs_subst() {
let mut err = tcx.sess.struct_span_err(
path.span,
"generic `Self` types are currently not permitted in anonymous constants",
Expand All @@ -2297,7 +2316,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.emit();
tcx.ty_error()
} else {
normalized_ty
self.normalize_ty(span, ty)
}
}
Res::Def(DefKind::AssocTy, def_id) => {
Expand Down
3 changes: 3 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ changelog-seen = 2
# Whether to build the clang compiler.
#clang = false

# Custom CMake defines to set when building LLVM.
#build-config = {}

# =============================================================================
# General build configuration options
# =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
#![feature(associated_type_bounds)]
#![feature(box_syntax)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
#![feature(const_deref)]
#![feature(const_fn_trait_bound)]
#![feature(const_mut_refs)]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
#![feature(allow_internal_unstable)]
#![feature(associated_type_bounds)]
#![feature(auto_traits)]
#![feature(cfg_target_has_atomic)]
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
#![cfg_attr(not(bootstrap), feature(cfg_target_has_atomic_equal_alignment))]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_fn_trait_bound)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![feature(box_syntax)]
#![feature(cell_update)]
#![feature(cfg_panic)]
#![feature(cfg_target_has_atomic)]
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
#![feature(const_assume)]
#![feature(const_black_box)]
#![feature(const_bool_to_option)]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
#![feature(c_variadic)]
#![feature(cfg_accessible)]
#![feature(cfg_eval)]
#![feature(cfg_target_has_atomic)]
#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))]
#![feature(cfg_target_thread_local)]
#![feature(char_error_internals)]
#![feature(char_internals)]
Expand Down
13 changes: 9 additions & 4 deletions library/std/src/sys/itron/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ unsafe impl Sync for Condvar {}
pub type MovableCondvar = Condvar;

impl Condvar {
#[inline]
pub const fn new() -> Condvar {
Condvar { waiters: SpinMutex::new(waiter_queue::WaiterQueue::new()) }
}

#[inline]
pub unsafe fn init(&mut self) {}

pub unsafe fn notify_one(&self) {
Expand Down Expand Up @@ -190,7 +192,7 @@ mod waiter_queue {
let insert_after = {
let mut cursor = head.last;
loop {
if waiter.priority <= cursor.as_ref().priority {
if waiter.priority >= cursor.as_ref().priority {
// `cursor` and all previous waiters have the same or higher
// priority than `current_task_priority`. Insert the new
// waiter right after `cursor`.
Expand All @@ -206,14 +208,16 @@ mod waiter_queue {

if let Some(mut insert_after) = insert_after {
// Insert `waiter` after `insert_after`
let insert_before = insert_after.as_ref().prev;
let insert_before = insert_after.as_ref().next;

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

waiter.next = insert_before;
if let Some(mut insert_before) = insert_before {
insert_before.as_mut().prev = Some(waiter_ptr);
} else {
head.last = waiter_ptr;
}
} else {
// Insert `waiter` to the front
Expand All @@ -240,11 +244,11 @@ mod waiter_queue {
match (waiter.prev, waiter.next) {
(Some(mut prev), Some(mut next)) => {
prev.as_mut().next = Some(next);
next.as_mut().next = Some(prev);
next.as_mut().prev = Some(prev);
}
(None, Some(mut next)) => {
head.first = next;
next.as_mut().next = None;
next.as_mut().prev = None;
}
(Some(mut prev), None) => {
prev.as_mut().next = None;
Expand All @@ -271,6 +275,7 @@ mod waiter_queue {
unsafe { waiter.as_ref().task != 0 }
}

#[inline]
pub fn pop_front(&mut self) -> Option<abi::ID> {
unsafe {
let head = self.head.as_mut()?;
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct Config {
pub llvm_polly: bool,
pub llvm_clang: bool,
pub llvm_from_ci: bool,
pub llvm_build_config: HashMap<String, String>,

pub use_lld: bool,
pub lld_enabled: bool,
Expand Down Expand Up @@ -477,6 +478,7 @@ derive_merge! {
polly: Option<bool>,
clang: Option<bool>,
download_ci_llvm: Option<StringOrBool>,
build_config: Option<HashMap<String, String>>,
}
}

Expand Down Expand Up @@ -807,6 +809,7 @@ impl Config {
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.unwrap_or(false);
config.llvm_polly = llvm.polly.unwrap_or(false);
config.llvm_clang = llvm.clang.unwrap_or(false);
config.llvm_build_config = llvm.build_config.clone().unwrap_or(Default::default());
config.llvm_from_ci = match llvm.download_ci_llvm {
Some(StringOrBool::String(s)) => {
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
Expand Down Expand Up @@ -876,6 +879,7 @@ impl Config {
check_ci_llvm!(llvm.allow_old_toolchain);
check_ci_llvm!(llvm.polly);
check_ci_llvm!(llvm.clang);
check_ci_llvm!(llvm.build_config);
check_ci_llvm!(llvm.plugins);

// CI-built LLVM can be either dynamic or static.
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ impl Step for Llvm {

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

for (key, val) in &builder.config.llvm_build_config {
cfg.define(key, val);
}

// FIXME: we don't actually need to build all LLVM tools and all LLVM
// libraries here, e.g., we just want a few components and a few
// tools. Figure out how to filter them down and only build the right
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
- [aarch64-unknown-none-hermitkernel](platform-support/aarch64-unknown-none-hermitkernel.md)
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
- [*-unknown-openbsd](platform-support/openbsd.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
Expand Down
7 changes: 4 additions & 3 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ target | std | host | notes
`aarch64-apple-tvos` | * | | ARM64 tvOS
[`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
`aarch64-unknown-hermit` | ? | |
`aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore
[`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel
`aarch64-unknown-uefi` | * | | ARM64 UEFI
`aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)
`aarch64-unknown-netbsd` | ✓ | ✓ |
Expand Down Expand Up @@ -286,10 +287,10 @@ target | std | host | notes
`x86_64-sun-solaris` | ? | | Deprecated target for 64-bit Solaris 10/11, illumos
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
`x86_64-unknown-hermit` | ? | |
`x86_64-unknown-hermit` | | | HermitCore
`x86_64-unknown-l4re-uclibc` | ? | |
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat
`x86_64-unknown-none-hermitkernel` | ? | | HermitCore kernel
`x86_64-unknown-none-hermitkernel` | * | | HermitCore kernel
`x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
`x86_64-unknown-uefi` | * | | 64-bit UEFI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# `aarch64-unknown-none-hermitkernel`

**Tier: 3**

Required to build the kernel for [HermitCore](https://github.com/hermitcore/hermit-playground)
or [RustyHermit](https://github.com/hermitcore/rusty-hermit).
The result is a bare-metal aarch64 binary in ELF format.

## Target maintainers

- Stefan Lankes, https://github.com/stlankes

## Requirements

This target is cross-compiled. There is no support for `std`, but the
library operating system provides a simple allocator to use `alloc`.

By default, Rust code generated for this target does not use any vector or
floating-point registers. This allows the generated code to build the library
operaring system, which may need to avoid the use of such
registers or which may have special considerations about the use of such
registers (e.g. saving and restoring them to avoid breaking userspace code
using the same registers). In contrast to `aarch64-unknown-none-softfloat`,
the target is completly relocatable, which is a required feature of RustyHermit.

By default, code generated with this target should run on any `aarch64`
hardware; enabling additional target features may raise this baseline.
On `aarch64-unknown-none-hermitkernel`, `extern "C"` uses the [standard System V calling
convention](https://github.com/ARM-software/abi-aa/releases/download/2021Q3/sysvabi64.pdf),
without red zones.

This target generated binaries in the ELF format.

## Building the target

Typical you should not use the target directly. The target `aarch64-unknown-hermit`
builds the _user space_ of RustyHermit and supports red zones and floating-point
operations.
To build and link the kernel to the application, the crate
[hermit-sys](https://github.com/hermitcore/rusty-hermit/tree/master/hermit-sys)
should be used by adding the following lines to the `Cargo.toml` file of
your application.

```toml
[target.'cfg(target_os = "hermit")'.dependencies]
hermit-sys = "0.1.*"
```

The crate `hermit-sys` uses the target `aarch64-unknown-none-hermitkernel`
to build the kernel.

## Building Rust programs

Rust does not yet ship pre-compiled artifacts for this target. To compile for
this target, you need to build the crate `hermit-sys` (see
"Building the target" above).

## Testing

As `aarch64-unknown-none-hermitkernel` does not support `std`
and does not support running any Rust testsuite.

## Cross-compilation toolchains and C code

If you want to compile C code along with Rust you will need an
appropriate `aarch64` toolchain.

Rust *may* be able to use an `aarch64-linux-gnu-` toolchain with appropriate
standalone flags to build for this toolchain (depending on the assumptions of
that toolchain, see below), or you may wish to use a separate
`aarch64-unknown-none` (or `aarch64-elf-`) toolchain.

On some `aarch64` hosts that use ELF binaries, you *may* be able to use the host
C toolchain, if it does not introduce assumptions about the host environment
that don't match the expectations of a standalone environment. Otherwise, you
may need a separate toolchain for standalone/freestanding development, just as
when cross-compiling from a non-`aarch64` platform.
2 changes: 1 addition & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = SpannedEvent<'a>>> Iterator
self.buf.push_back((Event::Html(format!("</a></h{}>", level).into()), 0..0));

let start_tags = format!(
"<h{level} id=\"{id}\" class=\"section-header\">\
"<h{level} id=\"{id}\">\
<a href=\"#{id}\">",
id = id,
level = level
Expand Down
Loading

0 comments on commit 502d6aa

Please sign in to comment.