-
Notifications
You must be signed in to change notification settings - Fork 377
Open
Description
The following code in memory.rs
emits strange assembly code causing an infinite loop:
// T is specialized to some struct sized 336..
#[naked]
#[inline(never)]
#[link_section = ".text.copy_user"]
unsafe extern "C" fn write_user<T>(dst: *mut T, src: *const T) -> usize {
dst.copy_from_nonoverlapping(src, 1);
0
}
Generated assembly:
ffffffffc02000d6 <_ZN5rcore6memory12copy_to_user10write_user17h75f60bbde319fcafE>:
ffffffffc02000d6: 15000613 li a2,336 // struct size. 3rd argument of memcpy.
ffffffffc02000da: 00086097 auipc ra,0x86 // WHY IS IT USING ra FOR INTERMEDIATE ADDRESS CALCULATION?
ffffffffc02000de: 0f0080e7 jalr 240(ra) # ffffffffc02861ca <memcpy> // now ra = ffffffffc02000e2 <li a0, 0>
ffffffffc02000e2: 4501 li a0,0 // BANG!
ffffffffc02000e4: 8082 ret // goto BANG!
It seems that rustc
optimizing copy_from_nonoverlapping
into memcpy
(in the naked function) results in this issue, but I'm not sure.
Metadata
Metadata
Assignees
Labels
No labels