2017-06-12 23:53:40 +01:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
2015-04-20 18:25:46 +01:00
|
|
|
|
2016-06-21 00:09:10 +01:00
|
|
|
use strict;
|
|
|
|
|
2015-04-20 18:25:46 +01:00
|
|
|
my $flavour = shift;
|
|
|
|
my $output = shift;
|
|
|
|
open STDOUT,">$output" || die "can't open $output: $!";
|
|
|
|
|
|
|
|
$flavour = "linux32" if (!$flavour or $flavour eq "void");
|
|
|
|
|
|
|
|
my %GLOBALS;
|
|
|
|
my $dotinlocallabels=($flavour=~/linux/)?1:0;
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
# directives which need special treatment on different platforms
|
|
|
|
################################################################
|
|
|
|
my $arch = sub {
|
|
|
|
if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
|
|
|
|
else { ""; }
|
|
|
|
};
|
2015-04-20 22:18:10 +01:00
|
|
|
my $fpu = sub {
|
|
|
|
if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
|
|
|
|
else { ""; }
|
|
|
|
};
|
|
|
|
my $hidden = sub {
|
|
|
|
if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
|
|
|
|
else { ".hidden\t".join(',',@_); }
|
|
|
|
};
|
|
|
|
my $comm = sub {
|
|
|
|
my @args = split(/,\s*/,shift);
|
|
|
|
my $name = @args[0];
|
|
|
|
my $global = \$GLOBALS{$name};
|
|
|
|
my $ret;
|
|
|
|
|
|
|
|
if ($flavour =~ /ios32/) {
|
|
|
|
$ret = ".comm\t_$name,@args[1]\n";
|
|
|
|
$ret .= ".non_lazy_symbol_pointer\n";
|
|
|
|
$ret .= "$name:\n";
|
|
|
|
$ret .= ".indirect_symbol\t_$name\n";
|
|
|
|
$ret .= ".long\t0";
|
|
|
|
$name = "_$name";
|
|
|
|
} else { $ret = ".comm\t".join(',',@args); }
|
|
|
|
|
|
|
|
$$global = $name;
|
|
|
|
$ret;
|
|
|
|
};
|
2015-09-30 22:46:38 +01:00
|
|
|
my $globl = sub {
|
2015-04-20 18:25:46 +01:00
|
|
|
my $name = shift;
|
|
|
|
my $global = \$GLOBALS{$name};
|
|
|
|
my $ret;
|
|
|
|
|
|
|
|
SWITCH: for ($flavour) {
|
|
|
|
/ios/ && do { $name = "_$name";
|
|
|
|
last;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-11 16:31:49 +00:00
|
|
|
$ret = ".globl $name\n";
|
|
|
|
# All symbols in assembly files are hidden.
|
|
|
|
$ret .= &$hidden($name);
|
2015-04-20 18:25:46 +01:00
|
|
|
$$global = $name;
|
|
|
|
$ret;
|
|
|
|
};
|
|
|
|
my $global = $globl;
|
|
|
|
my $extern = sub {
|
|
|
|
&$globl(@_);
|
|
|
|
return; # return nothing
|
|
|
|
};
|
|
|
|
my $type = sub {
|
|
|
|
if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
|
2017-06-12 23:43:31 +01:00
|
|
|
elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
|
|
|
|
"#ifdef __thumb2__\n".
|
|
|
|
".thumb_func $1\n".
|
|
|
|
"#endif";
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 18:25:46 +01:00
|
|
|
else { ""; }
|
|
|
|
};
|
|
|
|
my $size = sub {
|
|
|
|
if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
|
|
|
|
else { ""; }
|
|
|
|
};
|
|
|
|
my $inst = sub {
|
|
|
|
if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
|
|
|
|
else { ".long\t".join(',',@_); }
|
|
|
|
};
|
|
|
|
my $asciz = sub {
|
|
|
|
my $line = join(",",@_);
|
|
|
|
if ($line =~ /^"(.*)"$/)
|
|
|
|
{ ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
|
|
|
|
else
|
|
|
|
{ ""; }
|
|
|
|
};
|
Support execute-only memory for AArch64 assembly.
Put data in .rodata and, rather than adr, use the combination of adrp :pg_hi21:
and add :lo12:. Unfortunately, iOS uses different syntax, so we must add more
transforms to arm-xlate.pl.
Tested manually by:
1. Use Android NDK r19-beta1
2. Follow usual instructions to configure CMake for aarch64, but pass
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -Wl,-execute-only".
3. Build. Confirm with readelf -l tool/bssl that .text is not marked
readable.
4. Push the test binaries onto a Pixel 3. Test normally and with
--cpu={none,neon,crypto}. I had to pass --gtest_filter=-*Thread* to
crypto_test. There appears to be an issue with some runtime function
that's unrelated to our assembly.
No measurable performance difference.
Going forward, to support this, we will need to apply similar changes to
all other AArch64 assembly. This is relatively straightforward, but may
be a little finicky for dual-AArch32/AArch64 files (aesv8-armx.pl).
Update-Note: Assembly syntax is a mess. There's a decent chance some
assembler will get offend.
Change-Id: Ib59b921d4cce76584320fefd23e6bb7ebd4847eb
Reviewed-on: https://boringssl-review.googlesource.com/c/33245
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2018-11-16 21:34:05 +00:00
|
|
|
my $section = sub {
|
|
|
|
if ($flavour =~ /ios/) {
|
|
|
|
if ($_[0] eq ".rodata") {
|
|
|
|
return ".section\t__TEXT,__const";
|
|
|
|
}
|
|
|
|
die "Unknown section name $_[0]";
|
|
|
|
} else {
|
|
|
|
return ".section\t" . join(",", @_);
|
|
|
|
}
|
|
|
|
};
|
2015-04-20 18:25:46 +01:00
|
|
|
|
|
|
|
sub range {
|
|
|
|
my ($r,$sfx,$start,$end) = @_;
|
|
|
|
|
|
|
|
join(",",map("$r$_$sfx",($start..$end)));
|
|
|
|
}
|
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
sub expand_line {
|
2015-04-20 18:25:46 +01:00
|
|
|
my $line = shift;
|
|
|
|
my @ret = ();
|
|
|
|
|
|
|
|
pos($line)=0;
|
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
while ($line =~ m/\G[^@\/\{\"]*/g) {
|
|
|
|
if ($line =~ m/\G(@|\/\/|$)/gc) {
|
|
|
|
last;
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
|
|
|
elsif ($line =~ m/\G\{/gc) {
|
2015-04-20 22:18:10 +01:00
|
|
|
my $saved_pos = pos($line);
|
|
|
|
$line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
|
|
|
|
pos($line) = $saved_pos;
|
|
|
|
$line =~ m/\G[^\}]*\}/g;
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
2015-04-20 22:18:10 +01:00
|
|
|
elsif ($line =~ m/\G\"/gc) {
|
|
|
|
$line =~ m/\G[^\"]*\"/g;
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
$line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
|
|
|
|
|
|
|
|
return $line;
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 19:20:23 +01:00
|
|
|
print <<___;
|
|
|
|
#if defined(__has_feature)
|
|
|
|
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
|
|
|
#define OPENSSL_NO_ASM
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(OPENSSL_NO_ASM)
|
|
|
|
___
|
|
|
|
|
2015-06-23 00:21:14 +01:00
|
|
|
print "#if defined(__arm__)\n" if ($flavour eq "linux32");
|
|
|
|
print "#if defined(__aarch64__)\n" if ($flavour eq "linux64");
|
|
|
|
|
2018-09-07 18:09:17 +01:00
|
|
|
print "#if defined(BORINGSSL_PREFIX)\n";
|
|
|
|
print "#include <boringssl_prefix_symbols_asm.h>\n";
|
|
|
|
print "#endif\n";
|
|
|
|
|
2016-06-21 00:09:10 +01:00
|
|
|
while(my $line=<>) {
|
2015-04-20 18:25:46 +01:00
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
|
|
|
|
|
2015-04-20 18:25:46 +01:00
|
|
|
$line =~ s|/\*.*\*/||; # get rid of C-style comments...
|
|
|
|
$line =~ s|^\s+||; # ... and skip white spaces in beginning...
|
|
|
|
$line =~ s|\s+$||; # ... and at the end
|
|
|
|
|
|
|
|
{
|
2015-04-20 22:18:10 +01:00
|
|
|
$line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
|
|
|
|
$line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
$line =~ s|(^[\.\w]+)\:\s*||;
|
|
|
|
my $label = $1;
|
|
|
|
if ($label) {
|
|
|
|
printf "%s:",($GLOBALS{$label} or $label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
if ($line !~ m/^[#@]/) {
|
|
|
|
$line =~ s|^\s*(\.?)(\S+)\s*||;
|
2015-04-20 18:25:46 +01:00
|
|
|
my $c = $1; $c = "\t" if ($c eq "");
|
|
|
|
my $mnemonic = $2;
|
|
|
|
my $opcode;
|
2015-04-20 22:18:10 +01:00
|
|
|
if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
|
2015-04-20 18:25:46 +01:00
|
|
|
$opcode = eval("\$$1_$2");
|
|
|
|
} else {
|
|
|
|
$opcode = eval("\$$mnemonic");
|
|
|
|
}
|
|
|
|
|
Support execute-only memory for AArch64 assembly.
Put data in .rodata and, rather than adr, use the combination of adrp :pg_hi21:
and add :lo12:. Unfortunately, iOS uses different syntax, so we must add more
transforms to arm-xlate.pl.
Tested manually by:
1. Use Android NDK r19-beta1
2. Follow usual instructions to configure CMake for aarch64, but pass
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -Wl,-execute-only".
3. Build. Confirm with readelf -l tool/bssl that .text is not marked
readable.
4. Push the test binaries onto a Pixel 3. Test normally and with
--cpu={none,neon,crypto}. I had to pass --gtest_filter=-*Thread* to
crypto_test. There appears to be an issue with some runtime function
that's unrelated to our assembly.
No measurable performance difference.
Going forward, to support this, we will need to apply similar changes to
all other AArch64 assembly. This is relatively straightforward, but may
be a little finicky for dual-AArch32/AArch64 files (aesv8-armx.pl).
Update-Note: Assembly syntax is a mess. There's a decent chance some
assembler will get offend.
Change-Id: Ib59b921d4cce76584320fefd23e6bb7ebd4847eb
Reviewed-on: https://boringssl-review.googlesource.com/c/33245
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2018-11-16 21:34:05 +00:00
|
|
|
if ($flavour =~ /ios/) {
|
|
|
|
# Mach-O and ELF use different syntax for these relocations. Note
|
|
|
|
# that we require :pg_hi21: to be explicitly listed. It is normally
|
|
|
|
# optional with adrp instructions.
|
|
|
|
$line =~ s|:pg_hi21:(\w+)|\1\@PAGE|;
|
|
|
|
$line =~ s|:lo12:(\w+)|\1\@PAGEOFF|;
|
|
|
|
} else {
|
|
|
|
# Clang's integrated assembly does not support the optional
|
|
|
|
# :pg_hi21: markers, so erase them.
|
|
|
|
$line =~ s|:pg_hi21:||;
|
|
|
|
}
|
|
|
|
|
2015-04-20 22:18:10 +01:00
|
|
|
my $arg=expand_line($line);
|
2015-04-20 18:25:46 +01:00
|
|
|
|
|
|
|
if (ref($opcode) eq 'CODE') {
|
2015-04-20 22:18:10 +01:00
|
|
|
$line = &$opcode($arg);
|
2015-04-20 18:25:46 +01:00
|
|
|
} elsif ($mnemonic) {
|
|
|
|
$line = $c.$mnemonic;
|
2015-04-21 02:07:38 +01:00
|
|
|
$line.= "\t$arg" if ($arg ne "");
|
2015-04-20 18:25:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print $line if ($line);
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2016-01-09 04:50:36 +00:00
|
|
|
print "#endif\n" if ($flavour eq "linux32" || $flavour eq "linux64");
|
2018-09-10 17:28:05 +01:00
|
|
|
print "#endif // !OPENSSL_NO_ASM\n";
|
2015-06-23 00:21:14 +01:00
|
|
|
|
2015-04-20 18:25:46 +01:00
|
|
|
close STDOUT;
|