Unable to run asm code on OpenBSD (amd64)

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 https://github.com/openssl/openssl/pull/23997)
This commit is contained in:
Theo Buehler 2024-03-01 08:07:42 +01:00 committed by Tomas Mraz
parent fc807a0349
commit 25391acc14
20 changed files with 51 additions and 4 deletions

View File

@ -2221,6 +2221,7 @@ ___
}
$code.=<<___;
.section .rodata align=64
.align 64
.LAES_Te:
___
@ -2643,6 +2644,7 @@ $code.=<<___;
.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,

View File

@ -1738,6 +1738,7 @@ ___
}}}
}
$code.=<<___;
.section .rodata align=64
.align 64
K_XX_XX:
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
@ -1749,6 +1750,7 @@ K_XX_XX:
.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");

View File

@ -168,6 +168,7 @@ $code.=<<___;
.cfi_endproc
.size $func,.-$func
.section .rodata align=64
.align 64
.type $TABLE,\@object
$TABLE:
@ -210,6 +211,7 @@ $TABLE:
.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
___
######################################################################

View File

@ -4743,6 +4743,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
@ -4765,6 +4766,7 @@ $code.=<<___;
.asciz "AES for Intel AES-NI, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___
# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,

View File

@ -2182,6 +2182,7 @@ $code.=<<___;
.align 16
ossl_bsaes_xts_encrypt:
.cfi_startproc
endbranch
mov %rsp, %rax
.Lxts_enc_prologue:
push %rbp
@ -2581,6 +2582,7 @@ $code.=<<___;
.align 16
ossl_bsaes_xts_decrypt:
.cfi_startproc
endbranch
mov %rsp, %rax
.Lxts_dec_prologue:
push %rbp
@ -3003,6 +3005,7 @@ ___
}
$code.=<<___;
.type _bsaes_const,\@object
.section .rodata align=64
.align 64
_bsaes_const:
.LM0ISR: # InvShiftRows constants
@ -3054,9 +3057,9 @@ _bsaes_const:
.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,

View File

@ -1006,6 +1006,7 @@ _vpaes_preheat:
## ##
########################################################
.type _vpaes_consts,\@object
.section .rodata align=64
.align 64
_vpaes_consts:
.Lk_inv: # inv, inva
@ -1101,9 +1102,9 @@ _vpaes_consts:
.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) {

View File

@ -2248,10 +2248,12 @@ $code.=<<___;
.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
___
}

View File

@ -3577,11 +3577,13 @@ $code.=<<___;
___
}
$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,

View File

@ -657,6 +657,7 @@ sub S0222 { my $i=shift; $i=@SBOX[$i]; $i=($i<<1|$i>>7)&0xff; $i=$i<<16|$i<<8|$i
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
@ -682,6 +683,7 @@ $_ivp="40(%rsp)";
$_rsp="48(%rsp)";
$code.=<<___;
.text
.globl Camellia_cbc_encrypt
.type Camellia_cbc_encrypt,\@function,6
.align 16

View File

@ -102,6 +102,7 @@ $code.=<<___;
.extern OPENSSL_ia32cap_P
.section .rodata align=64
.align 64
.Lzero:
.long 0,0,0,0
@ -133,6 +134,7 @@ $code.=<<___;
.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

View File

@ -85,6 +85,7 @@ $code.=<<___;
.extern OPENSSL_ia32cap_P
# The polynomial
.section .rodata align=4096
.align 64
.Lpoly:
.quad 0xffffffffffffffff, 0x00000000ffffffff, 0x0000000000000000, 0xffffffff00000001
@ -107,6 +108,7 @@ $code.=<<___;
.quad 0xf3b9cac2fc632551, 0xbce6faada7179e84, 0xffffffffffffffff, 0xffffffff00000000
.LordK:
.quad 0xccd1c8aaee00bc4f
.previous
___
{
@ -4723,7 +4725,7 @@ close TABLE;
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

View File

@ -943,6 +943,7 @@ $code.=<<___;
___
$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
@ -955,6 +956,7 @@ $code.=<<___;
.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) {

View File

@ -534,6 +534,7 @@ $code.=<<___;
.align 16
gcm_init_clmul:
.cfi_startproc
endbranch
.L_init_clmul:
___
$code.=<<___ if ($win64);
@ -1027,6 +1028,7 @@ $code.=<<___;
.align 32
gcm_init_avx:
.cfi_startproc
endbranch
___
if ($avx) {
my ($Htbl,$Xip)=@_4args;
@ -1609,6 +1611,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
@ -1662,6 +1665,7 @@ $code.=<<___;
.asciz "GHASH for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.previous
___
# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,

View File

@ -229,6 +229,7 @@ $code.=<<___;
.align 32
poly1305_blocks:
.cfi_startproc
endbranch
.Lblocks:
shr \$4,$len
jz .Lno_data # too short
@ -303,6 +304,7 @@ $code.=<<___;
.align 32
poly1305_emit:
.cfi_startproc
endbranch
.Lemit:
mov 0($ctx),%r8 # load hash value
mov 8($ctx),%r9
@ -524,6 +526,7 @@ __poly1305_init_avx:
.align 32
poly1305_blocks_avx:
.cfi_startproc
endbranch
mov 20($ctx),%r8d # is_base2_26
cmp \$128,$len
jae .Lblocks_avx
@ -1384,6 +1387,7 @@ $code.=<<___;
.align 32
poly1305_emit_avx:
.cfi_startproc
endbranch
cmpl \$0,20($ctx) # is_base2_26?
je .Lemit
@ -1448,6 +1452,7 @@ $code.=<<___;
.align 32
poly1305_blocks_avx2:
.cfi_startproc
endbranch
mov 20($ctx),%r8d # is_base2_26
cmp \$128,$len
jae .Lblocks_avx2
@ -2144,6 +2149,7 @@ $code.=<<___;
.align 32
poly1305_blocks_avx512:
.cfi_startproc
endbranch
.Lblocks_avx512:
mov \$15,%eax
kmovw %eax,%k2
@ -3778,6 +3784,7 @@ poly1305_emit_base2_44:
___
} } }
$code.=<<___;
.section .rodata align=64
.align 64
.Lconst:
.Lmask24:
@ -3809,6 +3816,7 @@ $code.=<<___;
.Lx_mask42:
.quad 0x3ffffffffff,0x3ffffffffff,0x3ffffffffff,0x3ffffffffff
.quad 0x3ffffffffff,0x3ffffffffff,0x3ffffffffff,0x3ffffffffff
.previous
___
}
$code.=<<___;

View File

@ -567,6 +567,7 @@ SHA3_squeeze:
___
}
$code.=<<___;
.section .rodata align=256
.align 256
.quad 0,0,0,0,0,0,0,0
.type iotas,\@object

View File

@ -1374,7 +1374,7 @@ $code.=<<___;
___
} }}}
$code.=<<___;
.section .rodata align=256
.align 256
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
@ -1389,6 +1389,7 @@ K_XX_XX:
.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) {

View File

@ -1832,6 +1832,7 @@ ___
}
}
$code.=<<___;
.section .rodata align=64
.align 64
K_XX_XX:
.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
@ -1845,6 +1846,7 @@ K_XX_XX:
.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.=<<___;

View File

@ -1340,6 +1340,7 @@ $code.=<<___;
___
} }}}
$code.=<<___;
.section .rodata align=256
.align 256
K256:
___
@ -1389,6 +1390,7 @@ K256_shaext:
.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) {

View File

@ -418,6 +418,7 @@ ___
if ($SZ==4) {
$code.=<<___;
.section .rodata align=64
.align 64
.type $TABLE,\@object
$TABLE:
@ -461,9 +462,11 @@ $TABLE:
.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:
@ -551,6 +554,7 @@ $TABLE:
.quad 0x0001020304050607,0x08090a0b0c0d0e0f
.quad 0x0001020304050607,0x08090a0b0c0d0e0f
.asciz "SHA512 block transform for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.previous
___
}

View File

@ -236,6 +236,7 @@ $code.=<<___;
.cfi_endproc
.size $func,.-$func
.section .rodata align=64
.align 64
.type $table,\@object
$table: