Skip to content

Commit 815f70e

Browse files
authored
Update to the latest nightly Rust. (#131)
Update to nightly-2024-10-06, fix new warnings about static mut references, and a few other minor cleanups.
1 parent 287fd69 commit 815f70e

6 files changed

Lines changed: 24 additions & 22 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
rustup target add ${{ matrix.target }}
5959
if: matrix.target != ''
6060

61-
- uses: actions/cache@v3
61+
- uses: actions/cache@v4
6262
with:
6363
path: ${{ runner.tool_cache }}/qemu
6464
key: qemu-${{ matrix.target }}-${{ env.QEMU_BUILD_VERSION }}-patched

example-crates/external-start/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
8989
// linker, however origin gains control before libc can call this `main`.
9090
#[no_mangle]
9191
unsafe fn main(_argc: i32, _argv: *mut *mut u8, _envp: *mut *mut u8) -> i32 {
92+
eprintln!("Main was not supposed to be called!");
9293
core::intrinsics::abort();
9394
}

example-crates/tiny/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and `.comment` sections:
1010
objcopy -R .eh_frame -R .comment target/release/tiny even-smaller
1111
```
1212

13-
On x86-64, this produces a executable with size 408 bytes.
13+
On x86-64, this produces an executable with size 408 bytes.
1414

1515
How is this achieved?
1616

@@ -29,7 +29,7 @@ needed for our minimal test program:
2929
origin = { path = "../..", default-features = false, features = ["origin-start"] }
3030
```
3131

32-
Then, we add a `#[profile.release]` section to our Cargo.toml, to enable
32+
Then, we add a `[profile.release]` section to our Cargo.toml, to enable
3333
several optimizations:
3434

3535
```toml

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-08-19"
2+
channel = "nightly-2024-10-06"
33
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]

test-crates/origin-start/src/bin/canary.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern crate alloc;
1111
extern crate compiler_builtins;
1212

1313
use atomic_dbg::dbg;
14+
use core::cell::UnsafeCell;
1415
use core::arch::asm;
1516
use origin::{program, thread};
1617

@@ -27,7 +28,7 @@ extern "C" fn eh_personality() {}
2728
static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::GlobalDlmalloc;
2829

2930
extern "C" {
30-
static mut __stack_chk_guard: usize;
31+
static __stack_chk_guard: UnsafeCell<usize>;
3132
}
3233

3334
/// Read the canary field from its well-known location in TLS, if there is one,
@@ -47,21 +48,21 @@ fn tls_guard() -> usize {
4748

4849
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
4950
unsafe {
50-
ret = __stack_chk_guard;
51+
ret = *__stack_chk_guard.get();
5152
}
5253

5354
ret
5455
}
5556

5657
#[no_mangle]
5758
unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) -> i32 {
58-
assert_ne!(__stack_chk_guard, 0);
59-
assert_eq!(__stack_chk_guard, tls_guard());
59+
assert_ne!(*__stack_chk_guard.get(), 0);
60+
assert_eq!(*__stack_chk_guard.get(), tls_guard());
6061

6162
let thread = thread::create(
6263
|_args| {
63-
assert_ne!(__stack_chk_guard, 0);
64-
assert_eq!(__stack_chk_guard, tls_guard());
64+
assert_ne!(*__stack_chk_guard.get(), 0);
65+
assert_eq!(*__stack_chk_guard.get(), tls_guard());
6566
None
6667
},
6768
&[],
@@ -72,8 +73,8 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
7273

7374
thread::join(thread);
7475

75-
assert_ne!(__stack_chk_guard, 0);
76-
assert_eq!(__stack_chk_guard, tls_guard());
76+
assert_ne!(*__stack_chk_guard.get(), 0);
77+
assert_eq!(*__stack_chk_guard.get(), tls_guard());
7778

7879
program::exit(203);
7980
}

test-crates/origin-start/src/bin/tls.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#![feature(core_intrinsics)]
99
#![feature(thread_local)]
1010
#![feature(strict_provenance)]
11-
#![feature(const_mut_refs)]
1211

1312
extern crate alloc;
1413
extern crate compiler_builtins;
1514

1615
use alloc::boxed::Box;
1716
use atomic_dbg::dbg;
17+
use core::cell::UnsafeCell;
1818
use core::arch::asm;
1919
use core::ptr::{addr_of_mut, without_provenance_mut};
2020
use origin::{program, thread};
@@ -37,7 +37,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
3737
check_eq(TEST_DATA.0);
3838

3939
// Mutate one of the TLS fields.
40-
THREAD_LOCAL[1] = without_provenance_mut(77);
40+
(*THREAD_LOCAL.get())[1] = without_provenance_mut(77);
4141

4242
// Assert that the mutation happened properly.
4343
check_eq([TEST_DATA.0[0], without_provenance_mut(77), TEST_DATA.0[2]]);
@@ -48,14 +48,14 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
4848
check_eq([TEST_DATA.0[0], without_provenance_mut(79), TEST_DATA.0[2]]);
4949

5050
// Mutate one of the TLS fields.
51-
THREAD_LOCAL[1] = without_provenance_mut(80);
51+
(*THREAD_LOCAL.get())[1] = without_provenance_mut(80);
5252
}));
5353
thread::at_exit(Box::new(|| {
5454
// Assert that we see the value stored at the end of `main`.
5555
check_eq([TEST_DATA.0[0], without_provenance_mut(78), TEST_DATA.0[2]]);
5656

5757
// Mutate one of the TLS fields.
58-
THREAD_LOCAL[1] = without_provenance_mut(79);
58+
(*THREAD_LOCAL.get())[1] = without_provenance_mut(79);
5959
}));
6060

6161
let thread = thread::create(
@@ -64,7 +64,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
6464
check_eq(TEST_DATA.0);
6565

6666
// Mutate one of the TLS fields.
67-
THREAD_LOCAL[1] = without_provenance_mut(175);
67+
(*THREAD_LOCAL.get())[1] = without_provenance_mut(175);
6868

6969
// Assert that the mutation happened properly.
7070
check_eq([TEST_DATA.0[0], without_provenance_mut(175), TEST_DATA.0[2]]);
@@ -88,7 +88,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
8888
check_eq([TEST_DATA.0[0], without_provenance_mut(77), TEST_DATA.0[2]]);
8989

9090
// Mutate one of the TLS fields.
91-
THREAD_LOCAL[1] = without_provenance_mut(78);
91+
(*THREAD_LOCAL.get())[1] = without_provenance_mut(78);
9292

9393
// Assert that the mutation happened properly.
9494
check_eq([TEST_DATA.0[0], without_provenance_mut(78), TEST_DATA.0[2]]);
@@ -107,7 +107,7 @@ static TEST_DATA: SyncTestData = {
107107
};
108108

109109
#[thread_local]
110-
static mut THREAD_LOCAL: [*const u32; 3] = TEST_DATA.0;
110+
static THREAD_LOCAL: UnsafeCell<[*const u32; 3]> = UnsafeCell::new(TEST_DATA.0);
111111

112112
// Some variables to point to.
113113
static mut SOME_REGULAR_DATA: u32 = 909;
@@ -116,11 +116,11 @@ static mut SOME_ZERO_DATA: u32 = 0;
116116
fn check_eq(data: [*const u32; 3]) {
117117
unsafe {
118118
// Check `THREAD_LOCAL` using a static address.
119-
asm!("# {}", in(reg) THREAD_LOCAL.as_mut_ptr(), options(nostack, preserves_flags));
120-
assert_eq!(THREAD_LOCAL, data);
119+
asm!("# {}", in(reg) (*THREAD_LOCAL.get()).as_mut_ptr(), options(nostack, preserves_flags));
120+
assert_eq!(*THREAD_LOCAL.get(), data);
121121

122122
// Check `THREAD_LOCAL` using a dynamic address.
123-
let mut thread_local_addr: *mut [*const u32; 3] = addr_of_mut!(THREAD_LOCAL);
123+
let mut thread_local_addr: *mut [*const u32; 3] = THREAD_LOCAL.get();
124124
asm!("# {}", inout(reg) thread_local_addr, options(pure, nomem, nostack, preserves_flags));
125125
assert_eq!(*thread_local_addr, data);
126126
}

0 commit comments

Comments
 (0)