Skip to content

Commit e0b765e

Browse files
nbdd0121sunfishcode
authored andcommitted
Remove naked_functions feature usage for x86 (#722)
Given that this function has no generics, it could easily use `global_asm!` instead. This is a backport of #722, except without the part that removes outline asm for x86, as that's still needed on the 0.37 branch. It fixes compilation errors on the 0.37 when compiled with the latest nightly, due to `asm!` in `#[naked]` functions needed to be change to `naked_asm!`. Fixes #1181.
1 parent b38dc51 commit e0b765e

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,11 @@ fn main() {
8787
// Rust's inline asm is considered experimental, so only use it if
8888
// `--cfg=rustix_use_experimental_asm` is given.
8989
if (feature_rustc_dep_of_std || vendor == "mustang" || can_compile("use std::arch::asm;"))
90-
&& (arch != "x86" || has_feature("naked_functions"))
90+
&& (arch != "x86")
9191
&& ((arch != "powerpc64" && arch != "mips" && arch != "mips64")
9292
|| rustix_use_experimental_asm)
9393
{
9494
use_feature("asm");
95-
if arch == "x86" {
96-
use_feature("naked_functions");
97-
}
9895
if rustix_use_experimental_asm {
9996
use_feature("asm_experimental_arch");
10097
}

src/backend/linux_raw/vdso_wrappers.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::time::types::{ClockId, DynamicClockId, Timespec};
1616
use super::{c, vdso};
1717
use crate::io;
1818
#[cfg(all(asm, target_arch = "x86"))]
19-
use core::arch::asm;
19+
use core::arch::global_asm;
2020
use core::mem::{transmute, MaybeUninit};
2121
use core::ptr::null_mut;
2222
use core::sync::atomic::AtomicPtr;
@@ -293,21 +293,34 @@ unsafe fn _rustix_clock_gettime_via_syscall(
293293
ret(syscall!(__NR_clock_gettime, c_int(clockid), res))
294294
}
295295

296-
/// A symbol pointing to an `int 0x80` instruction. This “function” is only
297-
/// called from assembly, and only with the x86 syscall calling convention,
298-
/// so its signature here is not its true signature.
299-
#[cfg(all(asm, target_arch = "x86"))]
300-
#[naked]
301-
unsafe extern "C" fn rustix_int_0x80() {
302-
asm!("int $$0x80", "ret", options(noreturn))
303-
}
304-
305-
// The outline version of the `rustix_int_0x80` above.
306-
#[cfg(all(not(asm), target_arch = "x86"))]
296+
#[cfg(target_arch = "x86")]
307297
extern "C" {
298+
/// A symbol pointing to an `int 0x80` instruction. This “function” is only
299+
/// called from assembly, and only with the x86 syscall calling convention.
300+
/// so its signature here is not its true signature.
301+
///
302+
/// This extern block and the `global_asm!` below can be replaced with
303+
/// `#[naked]` if it's stabilized.
308304
fn rustix_int_0x80();
309305
}
310306

307+
#[cfg(all(asm, target_arch = "x86"))]
308+
global_asm!(
309+
r#"
310+
.section .text.rustix_int_0x80,"ax",@progbits
311+
.p2align 4
312+
.weak rustix_int_0x80
313+
.hidden rustix_int_0x80
314+
.type rustix_int_0x80, @function
315+
rustix_int_0x80:
316+
.cfi_startproc
317+
int 0x80
318+
ret
319+
.cfi_endproc
320+
.size rustix_int_0x80, .-rustix_int_0x80
321+
"#
322+
);
323+
311324
fn minimal_init() {
312325
// SAFETY: Store default function addresses in static storage so that if we
313326
// end up making any system calls while we read the vDSO, they'll work.

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@
101101
#![cfg_attr(rustc_attrs, feature(rustc_attrs))]
102102
#![cfg_attr(doc_cfg, feature(doc_cfg))]
103103
#![cfg_attr(all(wasi_ext, target_os = "wasi", feature = "std"), feature(wasi_ext))]
104-
#![cfg_attr(
105-
all(linux_raw, naked_functions, target_arch = "x86"),
106-
feature(naked_functions)
107-
)]
108104
#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
109105
#![cfg_attr(core_ffi_c, feature(core_ffi_c))]
110106
#![cfg_attr(core_c_str, feature(core_c_str))]

0 commit comments

Comments
 (0)