diff --git a/Cargo.lock b/Cargo.lock index 80acf227698..b5a6c942079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1915,9 +1915,8 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +version = "0.2.101" +source = "git+file:///Users/Jess/Git/rust-crate-libc/.git?rev=0b6604ff2c8e5555782c3b2c5c3b488bf8394ab3#0b6604ff2c8e5555782c3b2c5c3b488bf8394ab3" dependencies = [ "rustc-std-workspace-core", ] diff --git a/Cargo.toml b/Cargo.toml index 3822da2ccd5..ff94189337e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,5 +113,7 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' } rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } +libc = { git = "file:///Users/Jess/Git/rust-crate-libc/.git", rev = "0b6604ff2c8e5555782c3b2c5c3b488bf8394ab3" } + [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 964b7cace9c..d7f14b72f46 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -275,8 +275,10 @@ fn main() { "stdc++" }; - // RISC-V requires libatomic for sub-word atomic operations - if target.starts_with("riscv") { + // RISC-V GCC erroneously requires libatomic for sub-word atomic operations. + // FreeBSD uses Clang as its system compiler and provides no libatomic in + // its base system so does not want this. + if target.starts_with("riscv") && !target.contains("freebsd") { println!("cargo:rustc-link-lib=atomic"); } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 273221360b8..e65d2ea6961 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -805,6 +805,7 @@ fn $module() { ("powerpc-unknown-freebsd", powerpc_unknown_freebsd), ("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd), ("powerpc64le-unknown-freebsd", powerpc64le_unknown_freebsd), + ("riscv64gc-unknown-freebsd", riscv64gc_unknown_freebsd), ("x86_64-unknown-freebsd", x86_64_unknown_freebsd), ("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly), diff --git a/library/std/build.rs b/library/std/build.rs index 726157c1f1a..b46968f4d97 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -4,7 +4,8 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").expect("TARGET was not set"); if target.contains("freebsd") { - if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() { + // RISC-V first appeared in FreeBSD 12 so lacks FreeBSD 11's syscalls. + if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() || target.starts_with("riscv64") { println!("cargo:rustc-cfg=freebsd12"); } } else if target.contains("linux") diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 1e220ea30ab..3ce7a048536 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -68,7 +68,8 @@ macro_rules! type_alias { target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc", - target_arch = "powerpc64" + target_arch = "powerpc64", + target_arch = "riscv64" ) ), all( @@ -110,7 +111,8 @@ macro_rules! type_alias { target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc", - target_arch = "powerpc64" + target_arch = "powerpc64", + target_arch = "riscv64" ) ), all( diff --git a/library/stdarch b/library/stdarch --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 89b0e355bc3cff5cddec2290c84f36eb3a026aad +Subproject commit 89b0e355bc3cff5cddec2290c84f36eb3a026aad-dirty diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 0e306cb7211..5f513786ebb 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -248,9 +248,11 @@ fn run(self, builder: &Builder<'_>) -> PathBuf { } } - if target.starts_with("riscv") { - // In RISC-V, using C++ atomics require linking to `libatomic` but the LLVM build - // system check cannot detect this. Therefore it is set manually here. + if target.starts_with("riscv") && !target.contains("freebsd") { + // RISC-V GCC erroneously requires linking against `libatomic` when using 1-byte and + // 2-byte C++ atomics but the LLVM build system check cannot detect this. Therefore it + // is set manually here. FreeBSD uses Clang as its system compiler and provides no + // libatomic in its base system so does not want this. if !builder.config.llvm_tools_enabled { cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic"); } else {