Skip to content

Commit

Permalink
Merge BoringSSL 'cdccbe1': Fully condition all assembly files.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Sep 28, 2023
2 parents 21289d3 + cdccbe1 commit c82566d
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 33 deletions.
4 changes: 2 additions & 2 deletions crypto/curve25519/asm/x25519-asm-arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
43 changes: 31 additions & 12 deletions crypto/perlasm/arm-xlate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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=<>) {

Expand Down Expand Up @@ -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: $!";
46 changes: 35 additions & 11 deletions crypto/perlasm/x86_64-xlate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"; }
Expand Down Expand Up @@ -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 <<___;
Expand All @@ -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"
___
}
Expand Down Expand Up @@ -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: $!";

Expand Down
34 changes: 28 additions & 6 deletions crypto/perlasm/x86asm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crypto/poly1305/poly1305_arm_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c82566d

Please sign in to comment.