2 # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
13 open STDOUT,">$output" || die "can't open $output: $!";
15 $flavour = "linux32" if (!$flavour or $flavour eq "void");
18 my $dotinlocallabels=($flavour=~/linux/)?1:0;
20 ################################################################
21 # directives which need special treatment on different platforms
22 ################################################################
24 if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
25 elsif ($flavour =~ /win64/) { ".arch\t".join(',',@_); }
29 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
33 SWITCH: for ($flavour) {
34 /linux/ && return ".section\t.rodata";
35 /ios/ && return ".section\t__TEXT,__const";
40 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
41 elsif ($flavour =~ /win64/) { ""; }
42 else { ".hidden\t".join(',',@_); }
45 my @args = split(/,\s*/,shift);
47 my $global = \$GLOBALS{$name};
50 if ($flavour =~ /ios32/) {
51 $ret = ".comm\t_$name,@args[1]\n";
52 $ret .= ".non_lazy_symbol_pointer\n";
54 $ret .= ".indirect_symbol\t_$name\n";
57 } else { $ret = ".comm\t".join(',',@args); }
64 my $global = \$GLOBALS{$name};
67 SWITCH: for ($flavour) {
68 /ios/ && do { $name = "_$name";
73 $ret = ".globl $name" if (!$ret);
80 return; # return nothing
83 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
84 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
85 "#ifdef __thumb2__\n".
90 elsif ($flavour =~ /win64/) { if (join(',',@_) =~ /(\w+),%function/) {
91 # See https://sourceware.org/binutils/docs/as/Pseudo-Ops.html
92 # Per https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-symbol-table,
93 # the type for functions is 0x20, or 32.
102 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
106 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
107 else { ".long\t".join(',',@_); }
110 my $line = join(",",@_);
111 if ($line =~ /^"(.*)"$/)
112 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
118 my ($args,$comment) = split(m|\s*//|,shift);
119 "\tadrp\t$args\@PAGE";
120 } if ($flavour =~ /ios64/);
124 my ($r,$sfx,$start,$end) = @_;
126 join(",",map("$r$_$sfx",($start..$end)));
135 while ($line =~ m/\G[^@\/\{\"]*/g) {
136 if ($line =~ m/\G(@|\/\/|$)/gc) {
139 elsif ($line =~ m/\G\{/gc) {
140 my $saved_pos = pos($line);
141 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
142 pos($line) = $saved_pos;
143 $line =~ m/\G[^\}]*\}/g;
145 elsif ($line =~ m/\G\"/gc) {
146 $line =~ m/\G[^\"]*\"/g;
150 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
152 if ($flavour =~ /ios64/) {
153 $line =~ s/#:lo12:(\w+)/$1\@PAGEOFF/;
161 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
163 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
164 $line =~ s|^\s+||; # ... and skip whitespace in beginning...
165 $line =~ s|\s+$||; # ... and at the end
168 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
169 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
173 $line =~ s|(^[\.\w]+)\:\s*||;
176 printf "%s:",($GLOBALS{$label} or $label);
180 if ($line !~ m/^[#@]/) {
181 $line =~ s|^\s*(\.?)(\S+)\s*||;
182 my $c = $1; $c = "\t" if ($c eq "");
185 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
186 $opcode = eval("\$$1_$2");
188 $opcode = eval("\$$mnemonic");
191 my $arg=expand_line($line);
193 if (ref($opcode) eq 'CODE') {
194 $line = &$opcode($arg);
195 } elsif ($mnemonic) {
196 $line = $c.$mnemonic;
197 $line.= "\t$arg" if ($arg ne "");
201 print $line if ($line);
205 close STDOUT or die "error closing STDOUT: $!";