Skip to content

Commit 6f2e91f

Browse files
committed
Replace the bl! macro with asm_sym
`bl!` is being used to add a leading underscore on Apple targets. `asm_sym` has been around since 2022 and handles platform-specific symbol names automatically, so make use of this instead. I have verified that `armv7s-apple-ios` still builds correctly.
1 parent 614ab5e commit 6f2e91f

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

compiler-builtins/src/arm.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
#![cfg(not(feature = "no-asm"))]
2-
#![allow(unused_imports)]
32

4-
use core::intrinsics;
5-
6-
// Apple symbols have a leading underscore.
7-
#[cfg(target_vendor = "apple")]
8-
macro_rules! bl {
9-
($func:literal) => {
10-
concat!("bl _", $func)
11-
};
3+
// Interfaces used by naked trampolines.
4+
extern "C" {
5+
fn __udivmodsi4(a: u32, b: u32, rem: *mut u32) -> u32;
6+
fn __udivmoddi4(a: u64, b: u64, rem: *mut u64) -> u64;
7+
fn __divmoddi4(a: i64, b: i64, rem: *mut i64) -> i64;
128
}
13-
#[cfg(not(target_vendor = "apple"))]
14-
macro_rules! bl {
15-
($func:literal) => {
16-
concat!("bl ", $func)
17-
};
9+
10+
extern "aapcs" {
11+
fn __aeabi_idiv(a: i32, b: i32) -> i32;
1812
}
1913

2014
intrinsics! {
@@ -27,10 +21,11 @@ intrinsics! {
2721
"push {{lr}}",
2822
"sub sp, sp, #4",
2923
"mov r2, sp",
30-
bl!("__udivmodsi4"),
24+
"bl {trampoline}",
3125
"ldr r1, [sp]",
3226
"add sp, sp, #4",
3327
"pop {{pc}}",
28+
trampoline = sym crate::arm::__udivmodsi4
3429
);
3530
}
3631

@@ -41,23 +36,25 @@ intrinsics! {
4136
"sub sp, sp, #16",
4237
"add r4, sp, #8",
4338
"str r4, [sp]",
44-
bl!("__udivmoddi4"),
39+
"bl {trampoline}",
4540
"ldr r2, [sp, #8]",
4641
"ldr r3, [sp, #12]",
4742
"add sp, sp, #16",
4843
"pop {{r4, pc}}",
44+
trampoline = sym crate::arm::__udivmoddi4
4945
);
5046
}
5147

5248
#[unsafe(naked)]
5349
pub unsafe extern "C" fn __aeabi_idivmod() {
5450
core::arch::naked_asm!(
5551
"push {{r0, r1, r4, lr}}",
56-
bl!("__aeabi_idiv"),
52+
"bl {trampoline}",
5753
"pop {{r1, r2}}",
5854
"muls r2, r2, r0",
5955
"subs r1, r1, r2",
6056
"pop {{r4, pc}}",
57+
trampoline = sym crate::arm::__aeabi_idiv,
6158
);
6259
}
6360

@@ -68,11 +65,12 @@ intrinsics! {
6865
"sub sp, sp, #16",
6966
"add r4, sp, #8",
7067
"str r4, [sp]",
71-
bl!("__divmoddi4"),
68+
"bl {trampoline}",
7269
"ldr r2, [sp, #8]",
7370
"ldr r3, [sp, #12]",
7471
"add sp, sp, #16",
7572
"pop {{r4, pc}}",
73+
trampoline = sym crate::arm::__divmoddi4,
7674
);
7775
}
7876

0 commit comments

Comments
 (0)