Skip to content

Commit 9726bf3

Browse files
authored
Rename rustix_int_0x80 and protect it from multiple definitions. (#1396)
* Rename `rustix_int_0x80` and protect it from multiple definitions. In lto builds, multiple versions of the `rustix_int_0x80` assembly code can be included in the same .s file. To avoid conflicts when one of them comes from an older version of rustix, rename the symbol to `rustix_x86_int_0x80`, and to avoid conflicts with future versions, enclose the code in an `ifndef` block. Fixes #1394. * Fix compilation of tests/event/port.rs When libc/extra_trais is not enabled, `libc::timespec` does not have a `PartialEq` implementation, so compare the fields directly.
1 parent 0abc877 commit 9726bf3

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/backend/linux_raw/vdso_wrappers.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,29 +410,34 @@ unsafe extern "C" fn getcpu_via_syscall(
410410

411411
#[cfg(target_arch = "x86")]
412412
extern "C" {
413-
/// A symbol pointing to an `int 0x80` instruction. This “function” is only
414-
/// called from assembly, and only with the x86 syscall calling convention,
415-
/// so its signature here is not its true signature.
413+
/// A symbol pointing to an x86 `int 0x80` instruction. This “function”
414+
/// is only called from assembly, and only with the x86 syscall calling
415+
/// convention, so its signature here is not its true signature.
416416
///
417417
/// This extern block and the `global_asm!` below can be replaced with
418418
/// `#[naked]` if it's stabilized.
419-
fn rustix_int_0x80();
419+
fn rustix_x86_int_0x80();
420420
}
421421

422+
// This uses `.weak` so that it doesn't conflict if multiple versions of rustix
423+
// are linked in in non-lto builds, and `.ifndef` so that it doesn't conflict
424+
// if multiple versions of rustix are linked in in lto builds.
422425
#[cfg(target_arch = "x86")]
423426
global_asm!(
424427
r#"
425-
.section .text.rustix_int_0x80,"ax",@progbits
428+
.ifndef rustix_x86_int_0x80
429+
.section .text.rustix_x86_int_0x80,"ax",@progbits
426430
.p2align 4
427-
.weak rustix_int_0x80
428-
.hidden rustix_int_0x80
429-
.type rustix_int_0x80, @function
430-
rustix_int_0x80:
431+
.weak rustix_x86_int_0x80
432+
.hidden rustix_x86_int_0x80
433+
.type rustix_x86_int_0x80, @function
434+
rustix_x86_int_0x80:
431435
.cfi_startproc
432436
int 0x80
433437
ret
434438
.cfi_endproc
435-
.size rustix_int_0x80, .-rustix_int_0x80
439+
.size rustix_x86_int_0x80, .-rustix_x86_int_0x80
440+
.endif
436441
"#
437442
);
438443

@@ -478,7 +483,7 @@ fn minimal_init() {
478483
SYSCALL
479484
.compare_exchange(
480485
null_mut(),
481-
rustix_int_0x80 as *mut Function,
486+
rustix_x86_int_0x80 as *mut Function,
482487
Relaxed,
483488
Relaxed,
484489
)

tests/event/port.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ fn test_port_timeout_assumption() {
3737
assert_eq!(libc_errno::errno().0, libc::ETIME);
3838
assert_eq!(r, -1);
3939

40-
assert_eq!(timeout, orig_timeout);
40+
assert_eq!(
41+
(timeout.tv_sec, timeout.tv_nsec),
42+
(orig_timeout.tv_sec, orig_timeout.tv_nsec)
43+
);
4144
}
4245
}
4346

@@ -72,7 +75,10 @@ fn test_port_event_assumption() {
7275
let r = libc::port_get(port, &mut event, &mut timeout);
7376
assert_ne!(r, -1);
7477

75-
assert_eq!(timeout, orig_timeout);
78+
assert_eq!(
79+
(timeout.tv_sec, timeout.tv_nsec),
80+
(orig_timeout.tv_sec, orig_timeout.tv_nsec)
81+
);
7682
assert_eq!(event.portev_user, 7 as *mut c_void);
7783
}
7884
}
@@ -154,7 +160,10 @@ fn test_port_delay_assumption() {
154160
let r = libc::port_get(port, &mut event, &mut timeout);
155161
assert_ne!(r, -1, "port_get: {:?}", std::io::Error::last_os_error());
156162

157-
assert_eq!(timeout, orig_timeout);
163+
assert_eq!(
164+
(timeout.tv_sec, timeout.tv_nsec),
165+
(orig_timeout.tv_sec, orig_timeout.tv_nsec)
166+
);
158167
assert_eq!(event.portev_user, (9 + i) as *mut c_void);
159168

160169
let mut buf = [0_u8; 1];

0 commit comments

Comments
 (0)