Skip to content

Commit

Permalink
lib: libutils: Use ret for longjmp with Clang and BTI
Browse files Browse the repository at this point in the history
longjmp uses br instead of ret to jump to the target. Thus the target
location should have the right BTI launchpad to handle this.
clang has a bug [1] and doesn't add the BTI after setjmp causing
exception when BTI is enabled. This works well with gcc [2]
and can be tested when compiling xtests with WITH_CXX_TESTS=n.
To avoid the exception, use ret instead of br with clang and BTI.

[1] - https://bugs.llvm.org/show_bug.cgi?id=49544
[2] - https://gcc.gnu.org/legacy-ml/gcc-patches/2018-11/msg02472.html

Signed-off-by: Ruchika Gupta <ruchika.gupta@linaro.org>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
  • Loading branch information
ruchi393 authored and jforissier committed Dec 22, 2021
1 parent 5a8d8ba commit 30e743f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/libutils/isoc/arch/arm/setjmp_a64.S
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ BTI( bti c)
mov sp, x16
cmp w1, #0
cinc w0, w1, eq
/*
* clang has a bug and doesn't insert bti after setjmp
* causing BTI ecxception. Remove this when the bug is fixed.
* https://bugs.llvm.org/show_bug.cgi?id=49544
*/
#if defined(__clang__) && defined(CFG_TA_BTI)
ret
#else
// use br not ret, as ret is guaranteed to mispredict
br x30
#endif
.size longjmp, .-longjmp

BTI(emit_aarch64_feature_1_and GNU_PROPERTY_AARCH64_FEATURE_1_BTI)

0 comments on commit 30e743f

Please sign in to comment.