From: miod Date: Fri, 13 Jan 2023 17:11:41 +0000 (+0000) Subject: Move all data tables from .text section to .rodata, and update the code to X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=676d1ceb597ab4ef4e34622c4c77334e7abfd175;p=openbsd Move all data tables from .text section to .rodata, and update the code to fetch them correctly when building PIC. Also drop unused data, and remove --no-execute-only from linker flags. ok jsing@ kettenis@ --- diff --git a/lib/libcrypto/aes/asm/aes-parisc.pl b/lib/libcrypto/aes/asm/aes-parisc.pl index f12a1c18ec2..43dbfc108da 100644 --- a/lib/libcrypto/aes/asm/aes-parisc.pl +++ b/lib/libcrypto/aes/asm/aes-parisc.pl @@ -64,12 +64,7 @@ $rounds="%r29"; $code=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif .EXPORT AES_encrypt,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR .ALIGN 64 @@ -95,11 +90,14 @@ AES_encrypt $PUSH %r17,`-$FRAME+14*$SIZE_T`(%sp) $PUSH %r18,`-$FRAME+15*$SIZE_T`(%sp) - blr %r0,$tbl ldi 3,$t0 -L\$enc_pic - andcm $tbl,$t0,$tbl - ldo L\$AES_Te-L\$enc_pic($tbl),$tbl +#ifdef __PIC__ + addil LT'L\$AES_Te, %r19 + ldw RT'L\$AES_Te(%r1), $tbl +#else + ldil L'L\$AES_Te, %t1 + ldo R'L\$AES_Te(%t1), $tbl +#endif and $inp,$t0,$t0 sub $inp,$t0,$inp @@ -439,6 +437,7 @@ L\$enc_last xor $acc15,$s3,$s3 .PROCEND + .section .rodata .ALIGN 64 L\$AES_Te .WORD 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d @@ -537,6 +536,7 @@ L\$AES_Te .BYTE 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf .BYTE 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68 .BYTE 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 + .previous ___ $code.=<<___; @@ -564,11 +564,14 @@ AES_decrypt $PUSH %r17,`-$FRAME+14*$SIZE_T`(%sp) $PUSH %r18,`-$FRAME+15*$SIZE_T`(%sp) - blr %r0,$tbl ldi 3,$t0 -L\$dec_pic - andcm $tbl,$t0,$tbl - ldo L\$AES_Td-L\$dec_pic($tbl),$tbl +#ifdef __PIC__ + addil LT'L\$AES_Td, %r19 + ldw RT'L\$AES_Td(%r1), $tbl +#else + ldil L'L\$AES_Td, %t1 + ldo R'L\$AES_Td(%t1), $tbl +#endif and $inp,$t0,$t0 sub $inp,$t0,$inp @@ -908,6 +911,7 @@ L\$dec_last xor $acc15,$s3,$s3 .PROCEND + .section .rodata .ALIGN 64 L\$AES_Td .WORD 0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96 @@ -1006,9 +1010,7 @@ L\$AES_Td .BYTE 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61 .BYTE 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26 .BYTE 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d - - .data - .STRINGZ "AES for PA-RISC, CRYPTOGAMS by " + .previous ___ foreach (split("\n",$code)) { diff --git a/lib/libcrypto/arch/hppa/Makefile.inc b/lib/libcrypto/arch/hppa/Makefile.inc index 8744a0bbb89..eb15810f380 100644 --- a/lib/libcrypto/arch/hppa/Makefile.inc +++ b/lib/libcrypto/arch/hppa/Makefile.inc @@ -1,9 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.11 2023/01/11 16:25:13 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.12 2023/01/13 17:11:41 miod Exp $ # hppa-specific libcrypto build rules -LDADD+= -Wl,--no-execute-only - # aes SRCS+= aes_core.c aes_cbc.c CFLAGS+= -DAES_ASM diff --git a/lib/libcrypto/bn/asm/parisc-mont.pl b/lib/libcrypto/bn/asm/parisc-mont.pl index 6da9574adf1..0c7aff93b9d 100644 --- a/lib/libcrypto/bn/asm/parisc-mont.pl +++ b/lib/libcrypto/bn/asm/parisc-mont.pl @@ -126,12 +126,7 @@ $fni="%fr9"; $fnm0="%fr10"; $fnm1="%fr11"; $code=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif .EXPORT bn_mul_mont,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR .ALIGN 64 @@ -214,7 +209,7 @@ $code.=<<___; flddx $idx($np),${fni} ; np[2,3] ___ $code.=<<___ if ($BN_SZ==4); -#ifndef __OpenBSD__ +#ifdef __LP64__ mtctl $hi0,%cr11 ; $hi0 still holds 31 extrd,u,*= $hi0,%sar,1,$hi0 ; executes on PA-RISC 1.0 b L\$parisc11 @@ -881,9 +876,6 @@ L\$abort .EXIT $POPMB -$FRAME(%sp),%r3 .PROCEND - - .data - .STRINGZ "Montgomery Multiplication for PA-RISC, CRYPTOGAMS by " ___ # Explicitly encode PA-RISC 2.0 instructions used in this module, so diff --git a/lib/libcrypto/modes/asm/ghash-parisc.pl b/lib/libcrypto/modes/asm/ghash-parisc.pl index 965802d3fae..3f985131050 100644 --- a/lib/libcrypto/modes/asm/ghash-parisc.pl +++ b/lib/libcrypto/modes/asm/ghash-parisc.pl @@ -81,12 +81,7 @@ $rem2="%r6"; # used in PA-RISC 2.0 code $code.=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif .EXPORT gcm_gmult_4bit,ENTRY,ARGW0=GR,ARGW1=GR .ALIGN 64 @@ -108,12 +103,14 @@ $code.=<<___ if ($SIZE_T==4); $PUSH %r11,`-$FRAME+8*$SIZE_T`(%sp) ___ $code.=<<___; - blr %r0,$rem_4bit - ldi 3,$rem -L\$pic_gmult - andcm $rem_4bit,$rem,$rem_4bit addl $inp,$len,$len - ldo L\$rem_4bit-L\$pic_gmult($rem_4bit),$rem_4bit +#ifdef __PIC__ + addil LT'L\$rem_4bit, %r19 + ldw RT'L\$rem_4bit(%r1), $rem_4bit +#else + ldil L'L\$rem_4bit, %t1 + ldo R'L\$rem_4bit(%t1), $rem_4bit +#endif ldi 0xf0,$mask0xf0 ___ $code.=<<___ if ($SIZE_T==4); @@ -363,12 +360,14 @@ $code.=<<___ if ($SIZE_T==4); $PUSH %r11,`-$FRAME+8*$SIZE_T`(%sp) ___ $code.=<<___; - blr %r0,$rem_4bit - ldi 3,$rem -L\$pic_ghash - andcm $rem_4bit,$rem,$rem_4bit addl $inp,$len,$len - ldo L\$rem_4bit-L\$pic_ghash($rem_4bit),$rem_4bit +#ifdef __PIC__ + addil LT'L\$rem_4bit, %r19 + ldw RT'L\$rem_4bit(%r1), $rem_4bit +#else + ldil L'L\$rem_4bit, %t1 + ldo R'L\$rem_4bit(%t1), $rem_4bit +#endif ldi 0xf0,$mask0xf0 ___ $code.=<<___ if ($SIZE_T==4); @@ -619,15 +618,15 @@ $code.=<<___; $POPMB -$FRAME(%sp),%r3 .PROCEND + .section .rodata .ALIGN 64 L\$rem_4bit .WORD `0x0000<<16`,0,`0x1C20<<16`,0,`0x3840<<16`,0,`0x2460<<16`,0 .WORD `0x7080<<16`,0,`0x6CA0<<16`,0,`0x48C0<<16`,0,`0x54E0<<16`,0 .WORD `0xE100<<16`,0,`0xFD20<<16`,0,`0xD940<<16`,0,`0xC560<<16`,0 .WORD `0x9180<<16`,0,`0x8DA0<<16`,0,`0xA9C0<<16`,0,`0xB5E0<<16`,0 + .previous - .data - .STRINGZ "GHASH for PA-RISC, GRYPTOGAMS by " .ALIGN 64 ___ diff --git a/lib/libcrypto/rc4/asm/rc4-parisc.pl b/lib/libcrypto/rc4/asm/rc4-parisc.pl index 7e7974430aa..24e3e0c30ba 100644 --- a/lib/libcrypto/rc4/asm/rc4-parisc.pl +++ b/lib/libcrypto/rc4/asm/rc4-parisc.pl @@ -137,12 +137,7 @@ ___ $code=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif .EXPORT RC4,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR RC4 @@ -297,20 +292,22 @@ RC4_options .PROC .CALLINFO NO_CALLS .ENTRY - blr %r0,%r28 - ldi 3,%r1 -L\$pic - andcm %r28,%r1,%r28 +#ifdef __PIC__ + addil LT'L\$opts, %r19 + ldw RT'L\$opts(%r1), %r28 +#else + ldil L'L\$opts, %t1 + ldo R'L\$opts(%t1), %r28 +#endif bv (%r2) .EXIT - ldo L\$opts-L\$pic(%r28),%r28 + nop .PROCEND - .data + .section .rodata .ALIGN 8 L\$opts .STRINGZ "rc4(4x,`$SZ==1?"char":"int"`)" - .STRINGZ "RC4 for PA-RISC, CRYPTOGAMS by " ___ $code =~ s/\`([^\`]*)\`/eval $1/gem; $code =~ s/cmpib,\*/comib,/gm if ($SIZE_T==4); diff --git a/lib/libcrypto/sha/asm/sha1-parisc.pl b/lib/libcrypto/sha/asm/sha1-parisc.pl index 6cb46564224..783c26272b3 100644 --- a/lib/libcrypto/sha/asm/sha1-parisc.pl +++ b/lib/libcrypto/sha/asm/sha1-parisc.pl @@ -146,12 +146,7 @@ ___ $code=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif .EXPORT sha1_block_data_order,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR sha1_block_data_order @@ -254,9 +249,6 @@ $code.=<<___; .EXIT $POPMB -$FRAME(%sp),%r3 .PROCEND - - .data - .STRINGZ "SHA1 block transform for PA-RISC, CRYPTOGAMS by " ___ $code =~ s/\`([^\`]*)\`/eval $1/gem; diff --git a/lib/libcrypto/sha/asm/sha512-parisc.pl b/lib/libcrypto/sha/asm/sha512-parisc.pl index 0704302d2a9..42832e29f12 100755 --- a/lib/libcrypto/sha/asm/sha512-parisc.pl +++ b/lib/libcrypto/sha/asm/sha512-parisc.pl @@ -159,13 +159,9 @@ ___ $code=<<___; .LEVEL $LEVEL -#if 0 - .SPACE \$TEXT\$ - .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY -#else .text -#endif + .section .rodata .ALIGN 64 L\$table ___ @@ -230,6 +226,7 @@ $code.=<<___ if ($SZ==4); .WORD 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 ___ $code.=<<___; + .previous .EXPORT $func,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR .ALIGN 64 @@ -262,11 +259,13 @@ $func $PUSH $inp,`-$FRAME_MARKER-3*$SIZE_T`(%sp) $PUSH $ctx,`-$FRAME_MARKER-2*$SIZE_T`(%sp) - blr %r0,$Tbl - ldi 3,$t1 -L\$pic - andcm $Tbl,$t1,$Tbl ; wipe privilege level - ldo L\$table-L\$pic($Tbl),$Tbl +#ifdef __PIC__ + addil LT'L\$table, %r19 + ldw RT'L\$table(%r1), $Tbl +#else + ldil L'L\$table, %t1 + ldo R'L\$table(%t1), $Tbl +#endif ___ $code.=<<___ if ($SZ==8 && $SIZE_T==4); #ifndef __OpenBSD__ @@ -692,9 +691,6 @@ $code.=<<___; .EXIT $POPMB -$FRAME(%sp),%r3 .PROCEND - - .data - .STRINGZ "SHA`64*$SZ` block transform for PA-RISC, CRYPTOGAMS by " ___ # Explicitly encode PA-RISC 2.0 instructions used in this module, so