Unable to run asm code on OpenBSD (amd64)
authorTheo Buehler <tb@openbsd.org>
Fri, 1 Mar 2024 07:07:42 +0000 (08:07 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 17 Apr 2024 07:38:06 +0000 (09:38 +0200)
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)

20 files changed:
crypto/aes/asm/aes-x86_64.pl
crypto/aes/asm/aesni-sha1-x86_64.pl
crypto/aes/asm/aesni-sha256-x86_64.pl
crypto/aes/asm/aesni-x86_64.pl
crypto/aes/asm/bsaes-x86_64.pl
crypto/aes/asm/vpaes-x86_64.pl
crypto/bn/asm/rsaz-x86_64.pl
crypto/bn/asm/x86_64-mont5.pl
crypto/camellia/asm/cmll-x86_64.pl
crypto/chacha/asm/chacha-x86_64.pl
crypto/ec/asm/ecp_nistz256-x86_64.pl
crypto/modes/asm/aesni-gcm-x86_64.pl
crypto/modes/asm/ghash-x86_64.pl
crypto/poly1305/asm/poly1305-x86_64.pl
crypto/sha/asm/keccak1600-x86_64.pl
crypto/sha/asm/sha1-mb-x86_64.pl
crypto/sha/asm/sha1-x86_64.pl
crypto/sha/asm/sha256-mb-x86_64.pl
crypto/sha/asm/sha512-x86_64.pl
crypto/whrlpool/asm/wp-x86_64.pl

index 25f7ded947ed6ad86c2862f6a51b2e2d972bc868..a878c8666297ac4273d42d4deacdb2f8de3800a0 100755 (executable)
@@ -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,
index dbe33a3f1a02ea3da910debdbd33b258cc9b149a..9b58f31381ee7898681b37bdba4f283c12d592a4 100644 (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");
index 5521766a6a7dcf3f3df589b610f4784a17c0b306..5c8bb0fbccc6009b4efe58b64c33916d62da4dfb 100644 (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
 ___
 
 ######################################################################
index 09c8f78890ed2af7e54939b28fed132a85753d2b..fde5633f4b7a0e62fd3576b0049b60478ed61d91 100644 (file)
@@ -4743,6 +4743,7 @@ ___
 }
 \f
 $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,
index 6498cfe908c87a762f43c9f083ced9fef6368a2e..002a51a6038bfa5e01efdb3e7dbe813ab4ff1ed1 100644 (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,
index 845528f41ac2a37d8a2bedad05a0227710643a02..eb8937684cabe4672b6a9b28e06f927822f87b75 100644 (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) {
index 5c7d526fa37a8d9b983359dbc505413c53f5d07d..e004b4b3b5822c129312a0c3c42c84979c251617 100755 (executable)
@@ -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
 ___
 }
 
index 1faea0bcf89723774a0e3c3719e1430c9497a9f5..2c48e5647199c493aaf11581efdbdb8a99f1d77d 100755 (executable)
@@ -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,
index 7e069614d9157a9229ef7a262e2cb37e0825e110..0dcf2bf6f52932d44b0f45d5dfe5e1202d71f93f 100644 (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
index cdb900c037fd4717f5b779195d956ebbacdf2b6d..18eebbb97bc874507a6eb5ce861374c48e147247 100755 (executable)
@@ -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
index 430b14c86d8dbda02de76270c8bc119bd8a71f06..feeb8c5cb3972794a009e17841466e975cf3b7ff 100755 (executable)
@@ -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
index eaf4d9c755fbb2566bde0e3d636ff86149a03027..47f1fd7a2fda83989b835f246fc192f394647870 100644 (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) {
index 6709f96492ed3719fe0c199df037b96da35f035e..c7fb2a856dc605ed182ae9449cd62ccfa6e0a6eb 100644 (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 @@ ___
 }
 \f
 $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
 ___
 \f
 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
index 4cddca1c514c04ff72b7b0b36caa2ec1c117b1a2..5223207b83334ec79af1f57af3c3f823e9c08ca4 100755 (executable)
@@ -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.=<<___;
index 78aa5c64aff0e9f95de92cc60c047caf0fd3dcf7..f5f2cd0742e81f26ac04ddf8f9d12ba151ebde94 100755 (executable)
@@ -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
index 67faba136d05c2f760bcf7bd0af4cdb524c31379..6136c5c8785d0205ef311c2d32d4a385d9106954 100644 (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) {
index c66b8fca875e87133d040ad3ff12a4719e7b8572..a398b1c28f862ba49f64940a218e62785e6d1544 100755 (executable)
@@ -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.=<<___;
index fa2ca86046ccacf32b12a2562f487473a786cb6e..0c9f8b1ca0f52a7a8d879d07ddeecb298e7d5dd5 100644 (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) {
index 1bd0256954b36344bb3d64722c1186e3d4628730..6073520918c582ce6a77baccecc733817f01d494 100755 (executable)
@@ -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
 ___
 }
 
index f94152af9769ebb06e3c284bcaabc8cad7fa3c17..10f9ad13976d21c13c27cfc1d5ead4ecb1614495 100644 (file)
@@ -236,6 +236,7 @@ $code.=<<___;
 .cfi_endproc
 .size  $func,.-$func
 
+.section .rodata align=64
 .align 64
 .type  $table,\@object
 $table: