Skip to content

Commit 7c3b64f

Browse files
author
Jorge Aparicio
committed
check that we don't have any call to panic in our implementations
1 parent 9502cd7 commit 7c3b64f

File tree

3 files changed

+75
-44
lines changed

3 files changed

+75
-44
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ c = []
2626
weak = ["rlibc/weak"]
2727

2828
[workspace]
29+
30+
[profile.release]
31+
lto = true

ci/run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ case $1 in
2828
;;
2929
esac
3030

31+
# Verify that there are no undefined symbols to `panic` within our implementations
32+
case $1 in
33+
thumb*)
34+
xargo build --features c --target $1 --bin intrinsics --release
35+
;;
36+
*)
37+
cargo build --features c --target $1 --bin intrinsics --release
38+
;;
39+
esac
40+
3141
# Look out for duplicated symbols when we include the compiler-rt (C) implementation
3242
PREFIX=$(echo $1 | sed -e 's/unknown-//')-
3343
case $1 in

src/bin/intrinsics.rs

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -302,52 +302,70 @@ mod intrinsics {
302302

303303
#[cfg(feature = "c")]
304304
fn run() {
305+
use core::ptr;
305306
use intrinsics::*;
306307

307-
aeabi_d2f(2.);
308-
aeabi_d2i(2.);
309-
aeabi_d2l(2.);
310-
aeabi_d2uiz(2.);
311-
aeabi_d2ulz(2.);
312-
aeabi_dadd(2., 3.);
313-
aeabi_dcmpeq(2., 3.);
314-
aeabi_dcmpgt(2., 3.);
315-
aeabi_dcmplt(2., 3.);
316-
aeabi_ddiv(2., 3.);
317-
aeabi_dmul(2., 3.);
318-
aeabi_dsub(2., 3.);
319-
aeabi_f2d(2.);
320-
aeabi_f2iz(2.);
321-
aeabi_f2lz(2.);
322-
aeabi_f2uiz(2.);
323-
aeabi_f2ulz(2.);
324-
aeabi_fadd(2., 3.);
325-
aeabi_fcmpeq(2., 3.);
326-
aeabi_fcmpgt(2., 3.);
327-
aeabi_fcmplt(2., 3.);
328-
aeabi_fdiv(2., 3.);
329-
aeabi_fmul(2., 3.);
330-
aeabi_fsub(2., 3.);
331-
aeabi_i2d(2);
332-
aeabi_i2f(2);
333-
aeabi_idiv(2, 3);
334-
aeabi_idivmod(2, 3);
335-
aeabi_l2d(2);
336-
aeabi_l2f(2);
337-
aeabi_ldivmod(2, 3);
338-
aeabi_lmul(2, 3);
339-
aeabi_ui2d(2);
340-
aeabi_ui2f(2);
341-
aeabi_uidiv(2, 3);
342-
aeabi_uidivmod(2, 3);
343-
aeabi_ul2d(2);
344-
aeabi_ul2f(2);
345-
aeabi_uldivmod(2, 3);
346-
moddi3(2, 3);
347-
mulodi4(2, 3);
348-
powidf2(2., 3);
349-
powisf2(2., 3);
350-
umoddi3(2, 3);
308+
// We use volatile load/stores to prevent LLVM from optimizing away the intrinsics during LTO
309+
macro_rules! arg {
310+
() => {
311+
unsafe {
312+
ptr::read_volatile(0x0 as *const _)
313+
}
314+
}
315+
}
316+
317+
macro_rules! ret {
318+
($e:expr) => {
319+
unsafe {
320+
ptr::write_volatile(0x0 as *mut _, $e)
321+
}
322+
}
323+
}
324+
325+
ret!(aeabi_d2f(arg!()));
326+
ret!(aeabi_d2i(arg!()));
327+
ret!(aeabi_d2l(arg!()));
328+
ret!(aeabi_d2uiz(arg!()));
329+
ret!(aeabi_d2ulz(arg!()));
330+
ret!(aeabi_dadd(arg!(), arg!()));
331+
ret!(aeabi_dcmpeq(arg!(), arg!()));
332+
ret!(aeabi_dcmpgt(arg!(), arg!()));
333+
ret!(aeabi_dcmplt(arg!(), arg!()));
334+
ret!(aeabi_ddiv(arg!(), arg!()));
335+
ret!(aeabi_dmul(arg!(), arg!()));
336+
ret!(aeabi_dsub(arg!(), arg!()));
337+
ret!(aeabi_f2d(arg!()));
338+
ret!(aeabi_f2iz(arg!()));
339+
ret!(aeabi_f2lz(arg!()));
340+
ret!(aeabi_f2uiz(arg!()));
341+
ret!(aeabi_f2ulz(arg!()));
342+
ret!(aeabi_fadd(arg!(), arg!()));
343+
ret!(aeabi_fcmpeq(arg!(), arg!()));
344+
ret!(aeabi_fcmpgt(arg!(), arg!()));
345+
ret!(aeabi_fcmplt(arg!(), arg!()));
346+
ret!(aeabi_fdiv(arg!(), arg!()));
347+
ret!(aeabi_fmul(arg!(), arg!()));
348+
ret!(aeabi_fsub(arg!(), arg!()));
349+
ret!(aeabi_i2d(arg!()));
350+
ret!(aeabi_i2f(arg!()));
351+
ret!(aeabi_idiv(arg!(), arg!()));
352+
ret!(aeabi_idivmod(arg!(), arg!()));
353+
ret!(aeabi_l2d(arg!()));
354+
ret!(aeabi_l2f(arg!()));
355+
ret!(aeabi_ldivmod(arg!(), arg!()));
356+
ret!(aeabi_lmul(arg!(), arg!()));
357+
ret!(aeabi_ui2d(arg!()));
358+
ret!(aeabi_ui2f(arg!()));
359+
ret!(aeabi_uidiv(arg!(), arg!()));
360+
ret!(aeabi_uidivmod(arg!(), arg!()));
361+
ret!(aeabi_ul2d(arg!()));
362+
ret!(aeabi_ul2f(arg!()));
363+
ret!(aeabi_uldivmod(arg!(), arg!()));
364+
ret!(moddi3(arg!(), arg!()));
365+
ret!(mulodi4(arg!(), arg!()));
366+
ret!(powidf2(arg!(), arg!()));
367+
ret!(powisf2(arg!(), arg!()));
368+
ret!(umoddi3(arg!(), arg!()));
351369
}
352370

353371
#[cfg(all(feature = "c", not(thumb)))]

0 commit comments

Comments
 (0)