Skip to content

Commit 2a2f6d9

Browse files
authored
Merge pull request #238 from TimNN/fix-arm
Fix incorrect names used / generated on ARM
2 parents 263a703 + 5be5465 commit 2a2f6d9

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/arm.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use core::intrinsics;
22

33
// NOTE This function and the ones below are implemented using assembly because they using a custom
4-
// calling convention which can't be implemented using a normal Rust function
4+
// calling convention which can't be implemented using a normal Rust function.
5+
// NOTE The only difference between the iOS and non-iOS versions of those functions is that the iOS
6+
// versions use 3 leading underscores in the names of called functions instead of 2.
7+
#[cfg(not(target_os = "ios"))]
58
#[naked]
69
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
710
pub unsafe fn __aeabi_uidivmod() {
@@ -15,6 +18,21 @@ pub unsafe fn __aeabi_uidivmod() {
1518
intrinsics::unreachable();
1619
}
1720

21+
#[cfg(target_os = "ios")]
22+
#[naked]
23+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
24+
pub unsafe fn __aeabi_uidivmod() {
25+
asm!("push {lr}
26+
sub sp, sp, #4
27+
mov r2, sp
28+
bl ___udivmodsi4
29+
ldr r1, [sp]
30+
add sp, sp, #4
31+
pop {pc}" ::: "memory" : "volatile");
32+
intrinsics::unreachable();
33+
}
34+
35+
#[cfg(not(target_os = "ios"))]
1836
#[naked]
1937
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
2038
pub unsafe fn __aeabi_uldivmod() {
@@ -30,6 +48,23 @@ pub unsafe fn __aeabi_uldivmod() {
3048
intrinsics::unreachable();
3149
}
3250

51+
#[cfg(target_os = "ios")]
52+
#[naked]
53+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
54+
pub unsafe fn __aeabi_uldivmod() {
55+
asm!("push {r4, lr}
56+
sub sp, sp, #16
57+
add r4, sp, #8
58+
str r4, [sp]
59+
bl ___udivmoddi4
60+
ldr r2, [sp, #8]
61+
ldr r3, [sp, #12]
62+
add sp, sp, #16
63+
pop {r4, pc}" ::: "memory" : "volatile");
64+
intrinsics::unreachable();
65+
}
66+
67+
#[cfg(not(target_os = "ios"))]
3368
#[naked]
3469
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
3570
pub unsafe fn __aeabi_idivmod() {
@@ -42,6 +77,20 @@ pub unsafe fn __aeabi_idivmod() {
4277
intrinsics::unreachable();
4378
}
4479

80+
#[cfg(target_os = "ios")]
81+
#[naked]
82+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
83+
pub unsafe fn __aeabi_idivmod() {
84+
asm!("push {r0, r1, r4, lr}
85+
bl ___aeabi_idiv
86+
pop {r1, r2}
87+
muls r2, r2, r0
88+
subs r1, r1, r2
89+
pop {r4, pc}" ::: "memory" : "volatile");
90+
intrinsics::unreachable();
91+
}
92+
93+
#[cfg(not(target_os = "ios"))]
4594
#[naked]
4695
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
4796
pub unsafe fn __aeabi_ldivmod() {
@@ -57,6 +106,22 @@ pub unsafe fn __aeabi_ldivmod() {
57106
intrinsics::unreachable();
58107
}
59108

109+
#[cfg(target_os = "ios")]
110+
#[naked]
111+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
112+
pub unsafe fn __aeabi_ldivmod() {
113+
asm!("push {r4, lr}
114+
sub sp, sp, #16
115+
add r4, sp, #8
116+
str r4, [sp]
117+
bl ___divmoddi4
118+
ldr r2, [sp, #8]
119+
ldr r3, [sp, #12]
120+
add sp, sp, #16
121+
pop {r4, pc}" ::: "memory" : "volatile");
122+
intrinsics::unreachable();
123+
}
124+
60125
// FIXME: The `*4` and `*8` variants should be defined as aliases.
61126

62127
#[cfg(not(target_os = "ios"))]

src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ macro_rules! intrinsics {
210210
$($rest:tt)*
211211
) => (
212212
#[cfg(target_arch = "arm")]
213+
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
213214
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
214215
$($body)*
215216
}

0 commit comments

Comments
 (0)