perlasm/x86_64-xlate.pl: refine sign extension in ea package.
[openssl.git] / crypto / perlasm / x86_64-xlate.pl
index f615fffbcd06377dabbe56adf6898567b494cce5..4298b3f418c89227ded643202d694be23c8deff9 100755 (executable)
@@ -262,11 +262,18 @@ my %globals;
        $self->{base}  =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
 
        # Solaris /usr/ccs/bin/as can't handle multiplications
        $self->{base}  =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
 
        # Solaris /usr/ccs/bin/as can't handle multiplications
-       # in $self->{label}, new gas requires sign extension...
+       # in $self->{label}...
        use integer;
        $self->{label} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi;
        $self->{label} =~ s/\b([0-9]+\s*[\*\/\%]\s*[0-9]+)\b/eval($1)/eg;
        use integer;
        $self->{label} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi;
        $self->{label} =~ s/\b([0-9]+\s*[\*\/\%]\s*[0-9]+)\b/eval($1)/eg;
-       $self->{label} =~ s/\b([0-9]+)\b/$1<<32>>32/eg;
+
+       # Some assemblers insist on signed presentation of 32-bit
+       # offsets, but sign extension is a tricky business in perl...
+       if ((1<<31)<<1) {
+           $self->{label} =~ s/\b([0-9]+)\b/$1<<32>>32/eg;
+       } else {
+           $self->{label} =~ s/\b([0-9]+)\b/$1>>0/eg;
+       }
 
        if (!$self->{label} && $self->{index} && $self->{scale}==1 &&
            $self->{base} =~ /(rbp|r13)/) {
 
        if (!$self->{label} && $self->{index} && $self->{scale}==1 &&
            $self->{base} =~ /(rbp|r13)/) {