Skip to content

Commit

Permalink
Avoid out of range pc-relative fixup value
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Feb 26, 2024
1 parent 0a470e4 commit 52caa44
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
24 changes: 23 additions & 1 deletion crypto/fipsmodule/sha/asm/sha256-armv4.pl
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ ()
.arch armv7-a
.fpu neon
.LK256_shortcut_neon:
@ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode.
#if defined(__thumb2__)
.word K256-(.LK256_add_neon+4)
#else
.word K256-(.LK256_add_neon+8)
#endif
.global sha256_block_data_order_neon
.type sha256_block_data_order_neon,%function
.align 5
Expand All @@ -491,7 +499,21 @@ ()
stmdb sp!,{r4-r12,lr}
sub $H,sp,#16*4+16
adr $Ktbl,K256
@ K256 is just at the boundary of being easily referenced by an ADR from
@ this function. In Arm mode, when building with __ARM_ARCH=6, it does
@ not fit. By moving code around, we could make it fit, but this is too
@ fragile. For simplicity, just load the offset from
@ .LK256_shortcut_neon.
@
@ TODO(davidben): adrl would avoid a load, but clang-assembler does not
@ support it. We might be able to emulate it with a macro, but Android's
@ did not work when I tried it.
@ https://android.googlesource.com/platform/ndk/+/refs/heads/master/docs/ClangMigration.md#arm
ldr $Ktbl,.LK256_shortcut_neon
.LK256_add_neon:
add $Ktbl,pc,$Ktbl
bic $H,$H,#15 @ align for 128-bit stores
mov $t2,sp
mov sp,$H @ alloca
Expand Down
24 changes: 23 additions & 1 deletion generated-src/ios-arm/crypto/fipsmodule/sha256-armv4.S
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,14 @@ Lrounds_16_xx:



LK256_shortcut_neon:
@ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode.
#if defined(__thumb2__)
.word K256-(LK256_add_neon+4)
#else
.word K256-(LK256_add_neon+8)
#endif

.globl _sha256_block_data_order_neon
.private_extern _sha256_block_data_order_neon
#ifdef __thumb2__
Expand All @@ -1901,7 +1909,21 @@ LNEON:
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr}

sub r11,sp,#16*4+16
adr r14,K256

@ K256 is just at the boundary of being easily referenced by an ADR from
@ this function. In Arm mode, when building with __ARM_ARCH=6, it does
@ not fit. By moving code around, we could make it fit, but this is too
@ fragile. For simplicity, just load the offset from
@ .LK256_shortcut_neon.
@
@ TODO(davidben): adrl would avoid a load, but clang-assembler does not
@ support it. We might be able to emulate it with a macro, but Android's
@ did not work when I tried it.
@ https://android.googlesource.com/platform/ndk/+/refs/heads/master/docs/ClangMigration.md#arm
ldr r14,LK256_shortcut_neon
LK256_add_neon:
add r14,pc,r14

bic r11,r11,#15 @ align for 128-bit stores
mov r12,sp
mov sp,r11 @ alloca
Expand Down
24 changes: 23 additions & 1 deletion generated-src/linux-arm/crypto/fipsmodule/sha256-armv4.S
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,14 @@ sha256_block_data_order:
.arch armv7-a
.fpu neon

.LK256_shortcut_neon:
@ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode.
#if defined(__thumb2__)
.word K256-(.LK256_add_neon+4)
#else
.word K256-(.LK256_add_neon+8)
#endif

.globl sha256_block_data_order_neon
.hidden sha256_block_data_order_neon
.type sha256_block_data_order_neon,%function
Expand All @@ -1897,7 +1905,21 @@ sha256_block_data_order_neon:
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr}

sub r11,sp,#16*4+16
adr r14,K256

@ K256 is just at the boundary of being easily referenced by an ADR from
@ this function. In Arm mode, when building with __ARM_ARCH=6, it does
@ not fit. By moving code around, we could make it fit, but this is too
@ fragile. For simplicity, just load the offset from
@ .LK256_shortcut_neon.
@
@ TODO(davidben): adrl would avoid a load, but clang-assembler does not
@ support it. We might be able to emulate it with a macro, but Android's
@ did not work when I tried it.
@ https://android.googlesource.com/platform/ndk/+/refs/heads/master/docs/ClangMigration.md#arm
ldr r14,.LK256_shortcut_neon
.LK256_add_neon:
add r14,pc,r14

bic r11,r11,#15 @ align for 128-bit stores
mov r12,sp
mov sp,r11 @ alloca
Expand Down

0 comments on commit 52caa44

Please sign in to comment.