Skip to content

Commit

Permalink
Unable to run asm code on OpenBSD (amd64)
Browse files Browse the repository at this point in the history
In order to get asm code running on OpenBSD we must place
all constants into .rodata sections.

davidben@ also pointed out we need to adjust `x86_64-xlate.pl` perlasm
script to adjust read-olny sections for various flavors (OSes). Those
changes were cherry-picked from boringssl.

closes #23312

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #23997)
  • Loading branch information
botovq authored and t8m committed Apr 17, 2024
1 parent fc807a0 commit 25391ac
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 4 deletions.
2 changes: 2 additions & 0 deletions crypto/aes/asm/aes-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@ ()
}

$code.=<<___;
.section .rodata align=64
.align 64
.LAES_Te:
___
Expand Down Expand Up @@ -2643,6 +2644,7 @@ ()
.long 0x1b1b1b1b, 0x1b1b1b1b, 0, 0
.asciz "AES for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___

# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
Expand Down
2 changes: 2 additions & 0 deletions crypto/aes/asm/aesni-sha1-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,7 @@ ()
}}}
}
$code.=<<___;
.section .rodata align=64
.align 64
K_XX_XX:
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
Expand All @@ -1749,6 +1750,7 @@ ()
.asciz "AESNI-CBC+SHA1 stitch for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___
if ($shaext) {{{
($in0,$out,$len,$key,$ivp,$ctx,$inp)=("%rdi","%rsi","%rdx","%rcx","%r8","%r9","%r10");
Expand Down
2 changes: 2 additions & 0 deletions crypto/aes/asm/aesni-sha256-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
.cfi_endproc
.size $func,.-$func
.section .rodata align=64
.align 64
.type $TABLE,\@object
$TABLE:
Expand Down Expand Up @@ -210,6 +211,7 @@
.long 0,0,0,0, 0,0,0,0
.asciz "AESNI-CBC+SHA256 stitch for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___

######################################################################
Expand Down
2 changes: 2 additions & 0 deletions crypto/aes/asm/aesni-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4743,6 +4743,7 @@ sub aesni_generate8 {
}

$code.=<<___;
.section .rodata align=64
.align 64
.Lbswap_mask:
.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Expand All @@ -4765,6 +4766,7 @@ sub aesni_generate8 {
.asciz "AES for Intel AES-NI, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___

# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
Expand Down
5 changes: 4 additions & 1 deletion crypto/aes/asm/bsaes-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,7 @@ sub bitslice_key {
.align 16
ossl_bsaes_xts_encrypt:
.cfi_startproc
endbranch
mov %rsp, %rax
.Lxts_enc_prologue:
push %rbp
Expand Down Expand Up @@ -2581,6 +2582,7 @@ sub bitslice_key {
.align 16
ossl_bsaes_xts_decrypt:
.cfi_startproc
endbranch
mov %rsp, %rax
.Lxts_dec_prologue:
push %rbp
Expand Down Expand Up @@ -3003,6 +3005,7 @@ sub bitslice_key {
}
$code.=<<___;
.type _bsaes_const,\@object
.section .rodata align=64
.align 64
_bsaes_const:
.LM0ISR: # InvShiftRows constants
Expand Down Expand Up @@ -3054,9 +3057,9 @@ sub bitslice_key {
.quad 0x02060a0e03070b0f, 0x0004080c0105090d
.L63:
.quad 0x6363636363636363, 0x6363636363636363
.asciz "Bit-sliced AES for x86_64/SSSE3, Emilia Käsper, Peter Schwabe, Andy Polyakov"
.align 64
.size _bsaes_const,.-_bsaes_const
.asciz "Bit-sliced AES for x86_64/SSSE3, Emilia Käsper, Peter Schwabe, Andy Polyakov"
___

# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
Expand Down
3 changes: 2 additions & 1 deletion crypto/aes/asm/vpaes-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@
## ##
########################################################
.type _vpaes_consts,\@object
.section .rodata align=64
.align 64
_vpaes_consts:
.Lk_inv: # inv, inva
Expand Down Expand Up @@ -1101,9 +1102,9 @@
.Lk_dsbo: # decryption sbox final output
.quad 0x1387EA537EF94000, 0xC7AA6DB9D4943E2D
.quad 0x12D7560F93441D00, 0xCA4B8159D8C58E9C
.asciz "Vector Permutation AES for x86_64/SSSE3, Mike Hamburg (Stanford University)"
.align 64
.size _vpaes_consts,.-_vpaes_consts
.asciz "Vector Permutation AES for x86_64/SSSE3, Mike Hamburg (Stanford University)"
___

if ($win64) {
Expand Down
2 changes: 2 additions & 0 deletions crypto/bn/asm/rsaz-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2248,10 +2248,12 @@
.cfi_endproc
.size rsaz_512_gather4,.-rsaz_512_gather4
.section .rodata align=64
.align 64
.Linc:
.long 0,0, 1,1
.long 2,2, 2,2
.previous
___
}

Expand Down
2 changes: 2 additions & 0 deletions crypto/bn/asm/x86_64-mont5.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3577,11 +3577,13 @@
___
}
$code.=<<___;
.section .rodata align=64
.align 64
.Linc:
.long 0,0, 1,1
.long 2,2, 2,2
.asciz "Montgomery Multiplication with scatter/gather for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___

# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
Expand Down
2 changes: 2 additions & 0 deletions crypto/camellia/asm/cmll-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ sub _rotl128 {
sub S3033 { my $i=shift; $i=@SBOX[$i]; $i=($i>>1|$i<<7)&0xff; $i=$i<<24|$i<<8|$i; sprintf("0x%08x",$i); }

$code.=<<___;
.section .rodata align=64
.align 64
.LCamellia_SIGMA:
.long 0x3bcc908b, 0xa09e667f, 0x4caa73b2, 0xb67ae858
Expand All @@ -682,6 +683,7 @@ sub _rotl128 {
$_rsp="48(%rsp)";

$code.=<<___;
.text
.globl Camellia_cbc_encrypt
.type Camellia_cbc_encrypt,\@function,6
.align 16
Expand Down
2 changes: 2 additions & 0 deletions crypto/chacha/asm/chacha-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
.extern OPENSSL_ia32cap_P
.section .rodata align=64
.align 64
.Lzero:
.long 0,0,0,0
Expand Down Expand Up @@ -133,6 +134,7 @@
.Lsigma:
.asciz "expand 32-byte k"
.asciz "ChaCha20 for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___

sub AUTOLOAD() # thunk [simplified] 32-bit style perlasm
Expand Down
4 changes: 3 additions & 1 deletion crypto/ec/asm/ecp_nistz256-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
.extern OPENSSL_ia32cap_P
# The polynomial
.section .rodata align=4096
.align 64
.Lpoly:
.quad 0xffffffffffffffff, 0x00000000ffffffff, 0x0000000000000000, 0xffffffff00000001
Expand All @@ -107,6 +108,7 @@
.quad 0xf3b9cac2fc632551, 0xbce6faada7179e84, 0xffffffffffffffff, 0xffffffff00000000
.LordK:
.quad 0xccd1c8aaee00bc4f
.previous
___

{
Expand Down Expand Up @@ -4723,7 +4725,7 @@ ()
die "insane number of elements" if ($#arr != 64*16*37-1);

print <<___;
.text
.section .rodata align=4096
.globl ecp_nistz256_precomputed
.type ecp_nistz256_precomputed,\@object
.align 4096
Expand Down
2 changes: 2 additions & 0 deletions crypto/modes/asm/aesni-gcm-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@
___

$code.=<<___;
.section .rodata align=64
.align 64
.Lbswap_mask:
.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Expand All @@ -955,6 +956,7 @@
.Lone_lsb:
.byte 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.asciz "AES-NI GCM module for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
.align 64
___
if ($win64) {
Expand Down
4 changes: 4 additions & 0 deletions crypto/modes/asm/ghash-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ sub reduction_alg9 { # 17/11 times faster than Intel version
.align 16
gcm_init_clmul:
.cfi_startproc
endbranch
.L_init_clmul:
___
$code.=<<___ if ($win64);
Expand Down Expand Up @@ -1027,6 +1028,7 @@ sub reduction_alg9 { # 17/11 times faster than Intel version
.align 32
gcm_init_avx:
.cfi_startproc
endbranch
___
if ($avx) {
my ($Htbl,$Xip)=@_4args;
Expand Down Expand Up @@ -1609,6 +1611,7 @@ sub reduction_avx {
}

$code.=<<___;
.section .rodata align=64
.align 64
.Lbswap_mask:
.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
Expand Down Expand Up @@ -1662,6 +1665,7 @@ sub reduction_avx {
.asciz "GHASH for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___

# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
Expand Down
8 changes: 8 additions & 0 deletions crypto/poly1305/asm/poly1305-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ sub poly1305_iteration {
.align 32
poly1305_blocks:
.cfi_startproc
endbranch
.Lblocks:
shr \$4,$len
jz .Lno_data # too short
Expand Down Expand Up @@ -303,6 +304,7 @@ sub poly1305_iteration {
.align 32
poly1305_emit:
.cfi_startproc
endbranch
.Lemit:
mov 0($ctx),%r8 # load hash value
mov 8($ctx),%r9
Expand Down Expand Up @@ -524,6 +526,7 @@ sub poly1305_iteration {
.align 32
poly1305_blocks_avx:
.cfi_startproc
endbranch
mov 20($ctx),%r8d # is_base2_26
cmp \$128,$len
jae .Lblocks_avx
Expand Down Expand Up @@ -1384,6 +1387,7 @@ sub poly1305_iteration {
.align 32
poly1305_emit_avx:
.cfi_startproc
endbranch
cmpl \$0,20($ctx) # is_base2_26?
je .Lemit
Expand Down Expand Up @@ -1448,6 +1452,7 @@ sub poly1305_iteration {
.align 32
poly1305_blocks_avx2:
.cfi_startproc
endbranch
mov 20($ctx),%r8d # is_base2_26
cmp \$128,$len
jae .Lblocks_avx2
Expand Down Expand Up @@ -2144,6 +2149,7 @@ sub poly1305_iteration {
.align 32
poly1305_blocks_avx512:
.cfi_startproc
endbranch
.Lblocks_avx512:
mov \$15,%eax
kmovw %eax,%k2
Expand Down Expand Up @@ -3778,6 +3784,7 @@ sub poly1305_iteration {
___
} } }
$code.=<<___;
.section .rodata align=64
.align 64
.Lconst:
.Lmask24:
Expand Down Expand Up @@ -3809,6 +3816,7 @@ sub poly1305_iteration {
.Lx_mask42:
.quad 0x3ffffffffff,0x3ffffffffff,0x3ffffffffff,0x3ffffffffff
.quad 0x3ffffffffff,0x3ffffffffff,0x3ffffffffff,0x3ffffffffff
.previous
___
}
$code.=<<___;
Expand Down
1 change: 1 addition & 0 deletions crypto/sha/asm/keccak1600-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
___
}
$code.=<<___;
.section .rodata align=256
.align 256
.quad 0,0,0,0,0,0,0,0
.type iotas,\@object
Expand Down
3 changes: 2 additions & 1 deletion crypto/sha/asm/sha1-mb-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ sub BODY_40_59_avx {
___
} }}}
$code.=<<___;
.section .rodata align=256
.align 256
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
Expand All @@ -1389,6 +1389,7 @@ sub BODY_40_59_avx {
.long 0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f # pbswap
.byte 0xf,0xe,0xd,0xc,0xb,0xa,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0
.asciz "SHA1 multi-block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___

if ($win64) {
Expand Down
2 changes: 2 additions & 0 deletions crypto/sha/asm/sha1-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ ()
}
}
$code.=<<___;
.section .rodata align=64
.align 64
K_XX_XX:
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
Expand All @@ -1845,6 +1846,7 @@ ()
.long 0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f # pbswap mask
.long 0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f # pbswap mask
.byte 0xf,0xe,0xd,0xc,0xb,0xa,0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0x0
.previous
___
}}}
$code.=<<___;
Expand Down
2 changes: 2 additions & 0 deletions crypto/sha/asm/sha256-mb-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ sub ROUND_16_XX_avx {
___
} }}}
$code.=<<___;
.section .rodata align=256
.align 256
K256:
___
Expand Down Expand Up @@ -1389,6 +1390,7 @@ sub TABLE {
.long 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
.long 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
.asciz "SHA256 multi-block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___

if ($win64) {
Expand Down
4 changes: 4 additions & 0 deletions crypto/sha/asm/sha512-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ ()

if ($SZ==4) {
$code.=<<___;
.section .rodata align=64
.align 64
.type $TABLE,\@object
$TABLE:
Expand Down Expand Up @@ -461,9 +462,11 @@ ()
.long 0xffffffff,0xffffffff,0x03020100,0x0b0a0908
.long 0xffffffff,0xffffffff,0x03020100,0x0b0a0908
.asciz "SHA256 block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___
} else {
$code.=<<___;
.section .rodata align=64
.align 64
.type $TABLE,\@object
$TABLE:
Expand Down Expand Up @@ -551,6 +554,7 @@ ()
.quad 0x0001020304050607,0x08090a0b0c0d0e0f
.quad 0x0001020304050607,0x08090a0b0c0d0e0f
.asciz "SHA512 block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___
}

Expand Down

0 comments on commit 25391ac

Please sign in to comment.