Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,12 @@ fn embed_bitcode(
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
} else {
// We need custom section flags, so emit module-level inline assembly.
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
// The "n" flags is currently not supported on RISC-V
let mut section_flags = "";
if cgcx.target_arch != "riscv64"
{
if cgcx.is_pe_coff { section_flags = "n" } else { section_flags = "e" };
}
let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
llvm::append_module_inline_asm(llmod, &asm);
let asm = create_section_with_flags_asm(".llvmcmd", section_flags, &[]);
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_metadata::fs::METADATA_FILENAME;
use rustc_middle::bug;
use rustc_session::Session;
use rustc_span::sym;
use rustc_target::spec::{Abi, Os, RelocModel, Target, ef_avr_arch};
use rustc_target::spec::{Abi, Arch, Os, RelocModel, Target, ef_avr_arch};
use tracing::debug;

use super::apple;
Expand Down Expand Up @@ -211,6 +211,12 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
return None;
};
let binary_format = sess.target.binary_format.to_object();

if sess.target.arch == Arch::RiscV64 && binary_format == BinaryFormat::Coff {
// Return None to use the fallback mechanism in create_wrapper_file
// Use this fallback specifically for RISC-V 64 UEFI
return None;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/metadata.rs:560:19:
called Result::unwrap() on an Err value: Error("unimplemented architecture Riscv64 with sub-architecture None")
stack backtrace:
0: 0x7fd4e3bee9cb - std::backtrace::Backtrace::create::h652c7106100133e9
1: 0x7fd4e3bee915 - std::backtrace::Backtrace::force_capture::hcbb8a9548a20f2ec
2: 0x7fd4db55d948 - std[e20d0b87aa1ec278]::panicking::update_hook::<alloc[d35db71d034d3387]::boxed::Box<rustc_driver_impl[709b8e3ce94d842e]::install_ice_hook::{closure#1}>>::{closure#0}
3: 0x7fd4e3bef91f - std::panicking::panic_with_hook::hd57cd463d793ed79
4: 0x7fd4e3bef6ca - std::panicking::panic_handler::{{closure}}::hddd6216c3fddee3b
5: 0x7fd4e3be6fe9 - std::sys::backtrace::__rust_end_short_backtrace::h5e7a56f283378525
6: 0x7fd4e3bc31ad - __rustc[256c90bb7e548b45]::rust_begin_unwind
7: 0x7fd4e3c60910 - core::panicking::panic_fmt::hf19c198748ef6a95
8: 0x7fd4e3c5f256 - core::result::unwrap_failed::he81173b5792ad6b0
9: 0x7fd4e2648404 - rustc_codegen_ssa[7f529d302ba2af36]::back::metadata::create_wrapper_file
10: 0x7fd4e25b485c - rustc_codegen_ssa[7f529d302ba2af36]::back::link::link_rlib
11: 0x7fd4e25a2008 - rustc_codegen_ssa[7f529d302ba2af36]::back::link::link_binary
12: 0x7fd4dba1f459 - <rustc_codegen_llvm[525d04dfcb951d0f]::LlvmCodegenBackend as rustc_codegen_ssa[7f529d302ba2af36]::traits::backend::CodegenBackend>::link
13: 0x7fd4db8eca19 - <rustc_interface[f3537463438a3ee8]::queries::Linker>::link
14: 0x7fd4db5b2b43 - rustc_span[eee2686a21fb97e]::create_session_globals_then::<(), rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
15: 0x7fd4db5aa5b9 - std[e20d0b87aa1ec278]::sys::backtrace::_rust_begin_short_backtrace::<rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
16: 0x7fd4db5ad49e - <<std[e20d0b87aa1ec278]::thread::Builder>::spawn_unchecked
<rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5b293a957d0a6e5f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
17: 0x7fd4e3be180f - std::sys::thread::unix::Thread::new::thread_start::hbaf586a9e50a98cd
18: 0x7fd4d664b9cb -
19: 0x7fd4d66cfa0c -
20: 0x0 -

rustc version: 1.93.0-dev
platform: x86_64-unknown-linux-gnu


let mut file = write::Object::new(binary_format, architecture, endianness);
file.set_sub_architecture(sub_architecture);
Expand Down
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 @@ -1708,6 +1708,7 @@ supported_targets! {
("x86_64-unknown-uefi", x86_64_unknown_uefi),
("i686-unknown-uefi", i686_unknown_uefi),
("aarch64-unknown-uefi", aarch64_unknown_uefi),
("riscv64gc-unknown-uefi", riscv64gc_unknown_uefi),

("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),

Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_target/src/spec/targets/riscv64gc_unknown_uefi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::spec::{
Arch, Target, TargetMetadata, base
};

pub(crate) fn target() -> Target {
// Get the base UEFI configuration
let mut base = base::uefi_msvc::opts();

// Override with RISC-V specific settings
base.cpu = "generic-rv64".into();
base.features = "+m,+a,+f,+d,+c".into();
base.max_atomic_width = Some(64);
base.atomic_cas = true;
base.disable_redzone = true;
base.llvm_abiname = "lp64d".into();

Target {
llvm_target: "riscv64-unknown-windows".into(),
metadata: TargetMetadata {
description: Some("Bare RISC-V (RV64IMAFDC ISA) UEFI".into()),
tier: Some(3),
host_tools: Some(false),
std: None,
},
pointer_width: 64,
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
arch: Arch::RiscV64,

options: base,
}
}
1 change: 1 addition & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
"sparc64-unknown-helenos",
// just a dummy comment so the list doesn't get onelined
"riscv64gc-unknown-redox",
"riscv64gc-unknown-uefi",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ target | std | host | notes
[`riscv64gc-unknown-nuttx-elf`](platform-support/nuttx.md) | ✓ | | RISC-V 64bit with NuttX
[`riscv64gc-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/riscv64
[`riscv64gc-unknown-redox`](platform-support/redox.md) | ✓ | | RISC-V 64bit Redox OS
[`riscv64gc-unknown-uefi`](platform-support/unknown-uefi.md) | ? | RISC-V 64bit UEFI
[`riscv64imac-unknown-nuttx-elf`](platform-support/nuttx.md) | ✓ | | RISC-V 64bit with NuttX
[`riscv64a23-unknown-linux-gnu`](platform-support/riscv64a23-unknown-linux-gnu.md) | ✓ | ✓ | RISC-V Linux (kernel 6.8.0+, glibc 2.39)
[`s390x-unknown-linux-musl`](platform-support/s390x-unknown-linux-musl.md) | ✓ | | S390x Linux (kernel 3.2, musl 1.2.5)
Expand Down
11 changes: 9 additions & 2 deletions src/doc/rustc/src/platform-support/unknown-uefi.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# `*-unknown-uefi`

**Tier: 2**

Unified Extensible Firmware Interface (UEFI) targets for application, driver,
and core UEFI binaries.

**Tier: 2**

Available targets:

- `aarch64-unknown-uefi`
- `i686-unknown-uefi`
- `x86_64-unknown-uefi`

**Tier: 3**

Available targets:

- `riscv64gc-unknown-uefi`

## Target maintainers

- [@dvdhrm](https://github.com/dvdhrm)
- [@nicholasbishop](https://github.com/nicholasbishop)
- (for `aarch64-unknown-uefi` only) [@rust-lang/arm-maintainers][arm_maintainers] ([rust@arm.com][arm_email])
- (for `riscv64gc-unknown-uefi` only) [@gjbauer](https://github.com/gjbauer)

[arm_maintainers]: https://github.com/rust-lang/team/blob/master/teams/arm-maintainers.toml
[arm_email]: mailto:rust@arm.com
Expand Down
Loading