Skip to content

Commit 992216a

Browse files
authored
Update to the latest Rust nightly. (#122)
* Update to the latest Rust nightly. On x86 and x86_64, this renames labels "0" and "1" to "2" and "3" to fix the clippy `binary_asm_labels` diagnostic. * Fix PIC code syntax on x86. * Fix "an" vs. "a" in a log message. * Switch to hard-coding the offset.
1 parent ecb4fd5 commit 992216a

13 files changed

Lines changed: 35 additions & 23 deletions

File tree

example-crates/basic/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
eprintln!("Hello from main thread");
55

66
program::at_exit(Box::new(|| {
7-
eprintln!("Hello from an `program::at_exit` handler")
7+
eprintln!("Hello from a `program::at_exit` handler")
88
}));
99
thread::at_exit(Box::new(|| {
1010
eprintln!("Hello from a main-thread `thread::at_exit` handler")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
5959
eprintln!("Hello from main thread");
6060

6161
program::at_exit(Box::new(|| {
62-
eprintln!("Hello from an `program::at_exit` handler")
62+
eprintln!("Hello from a `program::at_exit` handler")
6363
}));
6464
thread::at_exit(Box::new(|| {
6565
eprintln!("Hello from a main-thread `thread::at_exit` handler")

example-crates/no-std/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
2929
eprintln!("Hello from main thread");
3030

3131
program::at_exit(Box::new(|| {
32-
eprintln!("Hello from an `program::at_exit` handler")
32+
eprintln!("Hello from a `program::at_exit` handler")
3333
}));
3434
thread::at_exit(Box::new(|| {
3535
eprintln!("Hello from a main-thread `thread::at_exit` handler")

example-crates/origin-start-dynamic-linker/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
3030
eprintln!("Hello from main thread");
3131

3232
program::at_exit(Box::new(|| {
33-
eprintln!("Hello from an `program::at_exit` handler")
33+
eprintln!("Hello from a `program::at_exit` handler")
3434
}));
3535
thread::at_exit(Box::new(|| {
3636
eprintln!("Hello from a main-thread `thread::at_exit` handler")

example-crates/origin-start-lto/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
3030
eprintln!("Hello from main thread");
3131

3232
program::at_exit(Box::new(|| {
33-
eprintln!("Hello from an `program::at_exit` handler")
33+
eprintln!("Hello from a `program::at_exit` handler")
3434
}));
3535
thread::at_exit(Box::new(|| {
3636
eprintln!("Hello from a main-thread `thread::at_exit` handler")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unsafe fn origin_main(_argc: usize, _argv: *mut *mut u8, _envp: *mut *mut u8) ->
3030
eprintln!("Hello from main thread");
3131

3232
program::at_exit(Box::new(|| {
33-
eprintln!("Hello from an `program::at_exit` handler")
33+
eprintln!("Hello from a `program::at_exit` handler")
3434
}));
3535
thread::at_exit(Box::new(|| {
3636
eprintln!("Hello from a main-thread `thread::at_exit` handler")

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-06-23"
2+
channel = "nightly-2024-08-19"
33
components = ["rustc", "cargo", "rust-std", "rust-src", "rustfmt"]

src/arch/x86.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,21 @@ pub(super) fn dynamic_table_addr() -> *const Elf_Dyn {
5454
asm!(
5555
".weak _DYNAMIC",
5656
".hidden _DYNAMIC",
57-
"call 0f",
57+
"call 2f",
5858
".cfi_adjust_cfa_offset 4",
59-
"0:",
59+
"2:",
6060
"pop {0}",
6161
".cfi_adjust_cfa_offset -4",
62-
"1:",
63-
"add {0}, offset _GLOBAL_OFFSET_TABLE_+(1b-0b)",
62+
"3:",
63+
// Use "2" and "3" instead of "0" and "1" because "0b" and "1b" are
64+
// parsed as binary literals rather than as label references. And,
65+
// hard-code the value `1` here because the assembler doesn't support
66+
// the symbol difference expression in an instruction operand
67+
// context. Then, check that the hard-coded value is what we expect.
68+
".ifne (3b-2b)-1",
69+
".error \"The pop opcode is expected to be 1 byte long.\"",
70+
".endif",
71+
"add {0}, offset _GLOBAL_OFFSET_TABLE_+1",
6472
"lea {0}, [{0} + _DYNAMIC@GOTOFF]",
6573
out(reg) addr
6674
)
@@ -75,13 +83,17 @@ pub(super) fn ehdr_addr() -> *const Elf_Ehdr {
7583
let addr;
7684
unsafe {
7785
asm!(
78-
"call 0f",
86+
"call 2f",
7987
".cfi_adjust_cfa_offset 4",
80-
"0:",
88+
"2:",
8189
"pop {0}",
8290
".cfi_adjust_cfa_offset -4",
83-
"1:",
84-
"add {0}, offset _GLOBAL_OFFSET_TABLE_+(1b-0b)",
91+
"3:",
92+
// See the comment by similar code in `dynamic_table_addr`.
93+
".ifne (3b-2b)-1",
94+
".error \"The pop opcode is expected to be 1 byte long.\"",
95+
".endif",
96+
"add {0}, offset _GLOBAL_OFFSET_TABLE_+1",
8597
"lea {0}, [{0} + __ehdr_start@GOTOFF]",
8698
out(reg) addr
8799
)
@@ -245,7 +257,7 @@ pub(super) unsafe fn clone(
245257
// in the child.
246258
"int 0x80", // Do the `clone` system call.
247259
"test eax, eax", // Branch if we're in the parent.
248-
"jnz 0f",
260+
"jnz 2f",
249261

250262
// Child thread.
251263
"pop edi", // Load `fn_` from the child stack.
@@ -259,7 +271,7 @@ pub(super) unsafe fn clone(
259271
"jmp {entry}", // Call `entry`.
260272

261273
// Parent thread.
262-
"0:",
274+
"2:",
263275
"pop ebp", // Restore incoming register value.
264276
"pop esi", // Restore incoming register value.
265277

src/arch/x86_64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(super) unsafe fn clone(
188188
asm!(
189189
"syscall", // Do the `clone` system call.
190190
"test eax, eax", // Branch if we're in the parent thread.
191-
"jnz 0f",
191+
"jnz 2f",
192192

193193
// Child thread.
194194
"mov rdi, r9", // Pass `fn_` as the first argument.
@@ -199,7 +199,7 @@ pub(super) unsafe fn clone(
199199
"jmp {entry}", // Call `entry`.
200200

201201
// Parent thread.
202-
"0:",
202+
"2:",
203203

204204
entry = sym super::thread::entry,
205205
inlateout("rax") __NR_clone as usize => r0,

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![deny(missing_docs)]
33
#![cfg_attr(debug_assertions, allow(internal_features))]
44
#![cfg_attr(docsrs, feature(doc_cfg))]
5-
#![feature(asm_const)]
65
#![feature(naked_functions)]
76
#![cfg_attr(debug_assertions, feature(link_llvm_intrinsics))]
87
#![cfg_attr(feature = "experimental-relocate", feature(cfg_relocation_model))]

0 commit comments

Comments
 (0)