Skip to content

Commit fd0cb0c

Browse files
Change weak! and linkat! to macros 2.0
`weak!` is needed in a test in another module. With macros 1.0, importing `weak!` would require reordering module declarations in `std/src/lib.rs`, which is a bit too evil.
1 parent 5022c06 commit fd0cb0c

File tree

8 files changed

+38
-4
lines changed

8 files changed

+38
-4
lines changed

library/std/src/sys/unix/android.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use libc::{c_int, c_void, sighandler_t, size_t, ssize_t};
2222
use libc::{ftruncate, pread, pwrite};
2323

24-
use super::{cvt, cvt_r};
24+
use super::{cvt, cvt_r, weak::weak};
2525
use crate::io;
2626

2727
// The `log2` and `log2f` functions apparently appeared in android-18, or at

library/std/src/sys/unix/fs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ use crate::sys::time::SystemTime;
1212
use crate::sys::{cvt, cvt_r};
1313
use crate::sys_common::{AsInner, FromInner};
1414

15+
#[cfg(any(
16+
all(target_os = "linux", target_env = "gnu"),
17+
target_os = "macos",
18+
target_os = "ios",
19+
))]
20+
use crate::sys::weak::syscall;
21+
#[cfg(target_os = "macos")]
22+
use crate::sys::weak::weak;
23+
1524
use libc::{c_int, mode_t};
1625

1726
#[cfg(any(

library/std/src/sys/unix/kernel_copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use crate::process::{ChildStderr, ChildStdin, ChildStdout};
6161
use crate::ptr;
6262
use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering};
6363
use crate::sys::cvt;
64+
use crate::sys::weak::syscall;
6465
use libc::{EBADF, EINVAL, ENOSYS, EOPNOTSUPP, EOVERFLOW, EPERM, EXDEV};
6566

6667
#[cfg(test)]

library/std/src/sys/unix/os.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ use crate::sys::memchr;
2323
use crate::sys_common::rwlock::{StaticRWLock, StaticRWLockReadGuard};
2424
use crate::vec;
2525

26+
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
27+
use crate::sys::weak::weak;
28+
2629
use libc::{c_char, c_int, c_void};
2730

2831
const TMPBUF_SZ: usize = 128;

library/std/src/sys/unix/process/process_unix.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ use crate::sys;
99
use crate::sys::cvt;
1010
use crate::sys::process::process_common::*;
1111

12+
#[cfg(any(
13+
target_os = "macos",
14+
target_os = "freebsd",
15+
all(target_os = "linux", target_env = "gnu"),
16+
all(target_os = "linux", target_env = "musl"),
17+
))]
18+
use crate::sys::weak::weak;
19+
1220
#[cfg(target_os = "vxworks")]
1321
use libc::RTP_ID as pid_t;
1422

library/std/src/sys/unix/rand.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ mod imp {
2525
use crate::fs::File;
2626
use crate::io::Read;
2727

28+
#[cfg(any(target_os = "linux", target_os = "android"))]
29+
use crate::sys::weak::syscall;
30+
2831
#[cfg(any(target_os = "linux", target_os = "android"))]
2932
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
3033
// A weak symbol allows interposition, e.g. for perf measurements that want to
@@ -108,6 +111,7 @@ mod imp {
108111
use crate::fs::File;
109112
use crate::io::Read;
110113
use crate::sys::os::errno;
114+
use crate::sys::weak::weak;
111115
use libc::{c_int, c_void, size_t};
112116

113117
fn getentropy_fill_bytes(v: &mut [u8]) -> bool {

library/std/src/sys/unix/thread.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::ptr;
77
use crate::sys::{os, stack_overflow};
88
use crate::time::Duration;
99

10+
#[cfg(any(target_os = "linux", target_os = "solaris", target_os = "illumos"))]
11+
use crate::sys::weak::weak;
1012
#[cfg(not(any(target_os = "l4re", target_os = "vxworks")))]
1113
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
1214
#[cfg(target_os = "l4re")]

library/std/src/sys/unix/weak.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ use crate::marker;
2626
use crate::mem;
2727
use crate::sync::atomic::{self, AtomicUsize, Ordering};
2828

29-
macro_rules! weak {
29+
// Temporary null documentation to work around #57569 until the fix is beta
30+
#[cfg_attr(bootstrap, doc = "")]
31+
pub(crate) macro weak {
3032
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
33+
#[allow(non_upper_case_globals)]
3134
static $name: crate::sys::weak::Weak<unsafe extern "C" fn($($t),*) -> $ret> =
3235
crate::sys::weak::Weak::new(concat!(stringify!($name), '\0'));
3336
)
@@ -100,8 +103,10 @@ unsafe fn fetch(name: &str) -> usize {
100103
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize
101104
}
102105

106+
// Temporary null documentation to work around #57569 until the fix is beta
107+
#[cfg_attr(bootstrap, doc = "")]
103108
#[cfg(not(any(target_os = "linux", target_os = "android")))]
104-
macro_rules! syscall {
109+
pub(crate) macro syscall {
105110
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
106111
unsafe fn $name($($arg_name: $t),*) -> $ret {
107112
use super::os;
@@ -118,10 +123,12 @@ macro_rules! syscall {
118123
)
119124
}
120125

126+
#[cfg_attr(bootstrap, doc = "")]
121127
#[cfg(any(target_os = "linux", target_os = "android"))]
122-
macro_rules! syscall {
128+
pub(crate) macro syscall {
123129
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
124130
unsafe fn $name($($arg_name:$t),*) -> $ret {
131+
use weak;
125132
// This looks like a hack, but concat_idents only accepts idents
126133
// (not paths).
127134
use libc::*;

0 commit comments

Comments
 (0)