From 90958a96eeea71dfefc43a08195292e5d3913e01 Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Thu, 26 Dec 2024 10:01:52 +0100 Subject: [PATCH] Fix heap --- .../rustc_target/src/spec/targets/x86_64_unknown_os.rs | 2 +- library/std/src/sys/alloc/os.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs index 376456ea28d..d9d2cc8aaa7 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs @@ -2,7 +2,7 @@ use crate::spec::{Target, TargetMetadata, base}; pub(crate) fn target() -> Target { let mut base = base::os::opts(); - base.cpu = "x86-64".into(); + base.cpu = "x86-64-v2".into(); Target { llvm_target: "x86_64-unknown-none".into(), metadata: TargetMetadata { diff --git a/library/std/src/sys/alloc/os.rs b/library/std/src/sys/alloc/os.rs index 68fcaa5a447..9814961a69c 100644 --- a/library/std/src/sys/alloc/os.rs +++ b/library/std/src/sys/alloc/os.rs @@ -19,11 +19,8 @@ unsafe impl GlobalAlloc for System { } let num_blocks = if layout.size() % 16 == 0 { layout.size() / 16 } else { (layout.size() / 16) + 1 }; - HEAP_USED.fetch_add(num_blocks, Ordering::Relaxed); - let ptr = unsafe { - ptr::addr_of_mut!(HEAP_DATA.0[HEAP_USED.load(Ordering::Relaxed) - num_blocks]) - as *mut u8 - }; + let heap_used = HEAP_USED.fetch_add(num_blocks, Ordering::SeqCst); + let ptr = unsafe { ptr::addr_of_mut!(HEAP_DATA.0[heap_used * 16]) as *mut u8 }; ptr }