diff --git a/crypto/curve25519/asm/x25519-asm-arm.S b/crypto/curve25519/asm/x25519-asm-arm.S index c2f6122c3..04d0362bd 100644 --- a/crypto/curve25519/asm/x25519-asm-arm.S +++ b/crypto/curve25519/asm/x25519-asm-arm.S @@ -23,7 +23,7 @@ #endif #endif -#if !defined(OPENSSL_NO_ASM) && defined(__arm__) && !defined(__APPLE__) +#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__ELF__) #include "ring_core_generated/prefix_symbols_asm.h" @@ -2127,7 +2127,7 @@ mov sp,r12 vpop {q4,q5,q6,q7} bx lr -#endif /* !OPENSSL_NO_ASM && __arm__ && !__APPLE__ */ +#endif /* !OPENSSL_NO_ASM && __ARMEL__ && __ELF__ */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/crypto/perlasm/arm-xlate.pl b/crypto/perlasm/arm-xlate.pl index 4727dfc96..d15a0cb10 100755 --- a/crypto/perlasm/arm-xlate.pl +++ b/crypto/perlasm/arm-xlate.pl @@ -151,6 +151,28 @@ sub expand_line { return $line; } +my ($arch_defines, $target_defines); +if ($flavour =~ /32/) { + $arch_defines = "defined(__ARMEL__)"; +} elsif ($flavour =~ /64/) { + $arch_defines = "defined(__AARCH64EL__)"; +} else { + die "unknown architecture: $flavour"; +} +if ($flavour =~ /linux/) { + # Although the flavour is specified as "linux", it is really used by all + # ELF platforms. + $target_defines = "defined(__ELF__)"; +} elsif ($flavour =~ /ios/) { + # Although the flavour is specified as "ios", it is really used by all Apple + # platforms. + $target_defines = "defined(__APPLE__)"; +} elsif ($flavour =~ /win/) { + $target_defines = "defined(_WIN32)"; +} else { + die "unknown target: $flavour"; +} + print <<___; // This file is generated from a similarly-named Perl script in the BoringSSL // source tree. Do not edit by hand. @@ -162,15 +184,10 @@ sub expand_line { #define OPENSSL_NO_ASM #endif -#if !defined(OPENSSL_NO_ASM) +#if !defined(OPENSSL_NO_ASM) && $arch_defines && $target_defines ___ -print "#if defined(__arm__)\n" if ($flavour eq "linux32"); -print "#if defined(__aarch64__)\n" if ($flavour eq "linux64" || $flavour eq "win64"); - -print <<___; -#include "ring_core_generated/prefix_symbols_asm.h" -___ +print "#include \"ring_core_generated/prefix_symbols_asm.h\"\n"; while(my $line=<>) { @@ -239,10 +256,12 @@ sub expand_line { print "\n"; } -print "#endif\n" if ($flavour eq "linux32" || $flavour eq "linux64" || $flavour eq "win64"); -print "#endif // !OPENSSL_NO_ASM\n"; - -# See https://www.airs.com/blog/archives/518. -print ".section\t.note.GNU-stack,\"\",\%progbits\n" if ($flavour =~ /linux/); +print <<___; +#endif // !OPENSSL_NO_ASM && $arch_defines && $target_defines +#if defined(__ELF__) +// See https://www.airs.com/blog/archives/518. +.section .note.GNU-stack,"",\%progbits +#endif +___ close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/perlasm/x86_64-xlate.pl b/crypto/perlasm/x86_64-xlate.pl index efd2fd22c..7f5dd4002 100755 --- a/crypto/perlasm/x86_64-xlate.pl +++ b/crypto/perlasm/x86_64-xlate.pl @@ -72,6 +72,7 @@ my $gas=1; $gas=0 if ($output =~ /\.asm$/); my $elf=1; $elf=0 if (!$gas); +my $apple=0; my $win64=0; my $prefix=""; my $decor=".L"; @@ -91,7 +92,7 @@ $prefix=`echo __USER_LABEL_PREFIX__ | $ENV{CC} -E -P -`; $prefix =~ s|\R$||; # Better chomp } -elsif ($flavour eq "macosx") { $gas=1; $elf=0; $prefix="_"; $decor="L\$"; } +elsif ($flavour eq "macosx") { $gas=1; $elf=0; $apple=1; $prefix="_"; $decor="L\$"; } elsif ($flavour eq "masm") { $gas=0; $elf=0; $masm=$masmref; $win64=1; $decor="\$L\$"; } elsif ($flavour eq "nasm") { $gas=0; $elf=0; $nasm=$nasmref; $win64=1; $decor="\$L\$"; $PTR=""; } elsif (!$gas) { die "unknown flavour $flavour"; } @@ -1146,13 +1147,15 @@ sub rxb { } if ($nasm) { + die "unknown target" unless ($win64); print <<___; +\%ifidn __OUTPUT_FORMAT__, win64 default rel -%define XMMWORD -%define YMMWORD -%define ZMMWORD +\%define XMMWORD +\%define YMMWORD +\%define ZMMWORD -%include "ring_core_generated/prefix_symbols_nasm.inc" +\%include "ring_core_generated/prefix_symbols_nasm.inc" ___ } elsif ($masm) { print <<___; @@ -1161,14 +1164,24 @@ sub rxb { } if ($gas) { - print <<___; + my $target; + if ($elf) { + # The "elf" target is really ELF with SysV ABI, but every ELF platform + # uses the SysV ABI. + $target = "defined(__ELF__)"; + } elsif ($apple) { + $target = "defined(__APPLE__)"; + } else { + die "unknown target: $flavour"; + } + print <<___; #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) #define OPENSSL_NO_ASM #endif #endif -#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) +#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && $target #include "ring_core_generated/prefix_symbols_asm.h" ___ } @@ -1255,10 +1268,21 @@ sub rxb { } print "\n$current_segment\tENDS\n" if ($current_segment && $masm); -print "END\n" if ($masm); -print "#endif\n" if ($gas); -# See https://www.airs.com/blog/archives/518. -print ".section\t.note.GNU-stack,\"\",\@progbits\n" if ($elf); +if ($masm) { + print "END\n"; +} elsif ($gas) { + print <<___; +#endif +#if defined(__ELF__) +// See https://www.airs.com/blog/archives/518. +.section .note.GNU-stack,"",\%progbits +#endif +___ +} elsif ($nasm) { + print "\%endif\n"; +} else { + die "unknown assembler"; +} close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/perlasm/x86asm.pl b/crypto/perlasm/x86asm.pl index 7f02cdcad..b2a9883a6 100644 --- a/crypto/perlasm/x86asm.pl +++ b/crypto/perlasm/x86asm.pl @@ -284,18 +284,40 @@ sub ::asm_finish ___ if ($win32) { print <<___ unless $masm; -%include "ring_core_generated/prefix_symbols_nasm.inc" +\%include "ring_core_generated/prefix_symbols_nasm.inc" +\%ifidn __OUTPUT_FORMAT__, win32 ___ + print @out; + print "\%endif\n"; } else { + my $target; + if ($elf) { + $target = "defined(__ELF__)"; + } elsif ($macosx) { + $target = "defined(__APPLE__)"; + } else { + die "unknown target"; + } + print <<___; -#if defined(__i386__) +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) +#define OPENSSL_NO_ASM +#endif +#endif + +#if !defined(OPENSSL_NO_ASM) && defined(__i386__) && $target #include "ring_core_generated/prefix_symbols_asm.h" +___ + print @out; + print <<___; +#endif // !defined(OPENSSL_NO_ASM) && defined(__i386__) && $target +#if defined(__ELF__) +// See https://www.airs.com/blog/archives/518. +.section .note.GNU-stack,"",\%progbits +#endif ___ } - print @out; - print "#endif\n" unless ($win32); - # See https://www.airs.com/blog/archives/518. - print ".section\t.note.GNU-stack,\"\",\@progbits\n" if ($elf); } sub ::asm_init diff --git a/crypto/poly1305/poly1305_arm_asm.S b/crypto/poly1305/poly1305_arm_asm.S index 04b9a2651..93f46e811 100644 --- a/crypto/poly1305/poly1305_arm_asm.S +++ b/crypto/poly1305/poly1305_arm_asm.S @@ -4,7 +4,7 @@ #endif #endif -#if defined(__arm__) && !defined(OPENSSL_NO_ASM) && !defined(__APPLE__) +#if defined(__ARMEL__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__) #pragma GCC diagnostic ignored "-Wlanguage-extension-token" @@ -2022,7 +2022,7 @@ vst1.8 d4,[r0,: 64] add sp,sp,#0 bx lr -#endif /* __arm__ && !OPENSSL_NO_ASM && !__APPLE__ */ +#endif /* __ARMEL__ && !OPENSSL_NO_ASM && __ELF__ */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits