Print <ABSENT> if a STACK is NULL.
[openssl.git] / util / incore
index ee495ee352071c4bf7a80eb7bf63b5285d895528..26fcf95033fca7d79db11080de5a35409b0ca299 100755 (executable)
@@ -1,7 +1,11 @@
-#!/usr/bin/env perl
-#
-# Copyrifgr (c) 2011 The OpenSSL Project.
+#! /usr/bin/env perl
+# Copyright 2011-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
+
 # The script embeds fingerprint into ELF executable object, either
 # application binary or shared library.
 
 # The script embeds fingerprint into ELF executable object, either
 # application binary or shared library.
 
@@ -34,6 +38,7 @@
        @e_ident{magic,class,data,version,osabi,abiver,pad}=
                unpack("a4C*",$elf);
 
        @e_ident{magic,class,data,version,osabi,abiver,pad}=
                unpack("a4C*",$elf);
 
+       $!=42;          # signal fipsld to revert to two-step link
        die "not ELF file" if ($e_ident{magic} ne chr(0177)."ELF");
 
        my $elf_bits   = $e_ident{class}*32;    # 32 or 64
        die "not ELF file" if ($e_ident{magic} ne chr(0177)."ELF");
 
        my $elf_bits   = $e_ident{class}*32;    # 32 or 64
@@ -370,17 +375,23 @@ $FIPS_rodata_start        = $exe->Lookup("FIPS_rodata_start")             or die;
 $FIPS_rodata_end       = $exe->Lookup("FIPS_rodata_end")               or die;
 $FIPS_signature                = $exe->Lookup("FIPS_signature")                or die;
 
 $FIPS_rodata_end       = $exe->Lookup("FIPS_rodata_end")               or die;
 $FIPS_signature                = $exe->Lookup("FIPS_signature")                or die;
 
-if (!$legacy_mode) {
-    $FIPS_text_start   = $exe->Lookup("FIPS_text_startX");
-    $FIPS_text_end     = $exe->Lookup("FIPS_text_endX");
+# new cross-compile support
+$FIPS_text_startX      = $exe->Lookup("FIPS_text_startX");
+$FIPS_text_endX                = $exe->Lookup("FIPS_text_endX");
 
 
-    if (!$FIPS_text_start || !$FIPS_text_end) {
+if (!$legacy_mode) {
+    if (!$FIPS_text_startX || !$FIPS_text_endX) {
        print STDERR "@ARGV[$#ARGV] is not cross-compiler aware.\n";
        print STDERR "@ARGV[$#ARGV] is not cross-compiler aware.\n";
-       exit(1);
+       exit(42);       # signal fipsld to revert to two-step link
     }
 
     $FINGERPRINT_ascii_value
     }
 
     $FINGERPRINT_ascii_value
-                       = $exe->Lookup("FINGERPRINT_ascii_value")       or die;
+                       = $exe->Lookup("FINGERPRINT_ascii_value");
+
+}
+if ($FIPS_text_startX && $FIPS_text_endX) {
+    $FIPS_text_start = $FIPS_text_startX;
+    $FIPS_text_end   = $FIPS_text_endX;
 }
 
 sysopen(FD,@ARGV[$#ARGV],$legacy_mode?0:2) or die "$!";        # 2 is read/write
 }
 
 sysopen(FD,@ARGV[$#ARGV],$legacy_mode?0:2) or die "$!";        # 2 is read/write
@@ -432,9 +443,12 @@ $fingerprint = FIPS_incore_fingerprint();
 
 if ($legacy_mode) {
     print unpack("H*",$fingerprint);
 
 if ($legacy_mode) {
     print unpack("H*",$fingerprint);
-} else {
+} elsif (defined($FINGERPRINT_ascii_value)) {
     seek(FD,$FINGERPRINT_ascii_value->{st_offset},0)   or die "$!";
     print FD unpack("H*",$fingerprint)                 or die "$!";
     seek(FD,$FINGERPRINT_ascii_value->{st_offset},0)   or die "$!";
     print FD unpack("H*",$fingerprint)                 or die "$!";
+} else {
+    seek(FD,$FIPS_signature->{st_offset},0)            or die "$!";
+    print FD $fingerprint                              or die "$!";
 }
 
 close (FD);
 }
 
 close (FD);