Print this page
NEX-5205 adjunct support for check_rtime
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
        
@@ -20,10 +20,11 @@
 # CDDL HEADER END
 #
 
 #
 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2015, Nexenta Systems Inc.
 #
 
 #
 # Check ELF information.
 #
@@ -52,11 +53,11 @@
 # ldd(1) can be executed against these configuration files so that objects in a
 # proto area bind to their dependencies in the same proto area.
 
 
 # Define all global variables (required for strict)
-use vars  qw($Prog $Env $Ena64 $Tmpdir);
+use vars  qw($Prog $Env $Ena64 $Tmpdir $Adjunct $Proto);
 use vars  qw($LddNoU $Conf32 $Conf64);
 use vars  qw(%opt);
 use vars  qw($ErrFH $ErrTtl $InfoFH $InfoTtl $OutCnt1 $OutCnt2);
 
 # An exception file is used to specify regular expressions to match
@@ -869,18 +870,19 @@
 
         close FIND_ELF;
 }
 
 
-## AltObjectConfig(file)
+## AltObjectConfig(proto, adjunct)
 #
 # Recurse through a directory hierarchy looking for appropriate dependencies
 # to map from their standard system locations to the proto area via a crle
 # config file.
 #
 # entry:
-#       file - File of ELF objects, in 'find_elf -r' format, to examine.
+#       proto, adjunct - Files of ELF objects, in 'find_elf -r' format, to
+#       examine.
 #
 # exit:
 #       Scripts are generated for the 32 and 64-bit cases to run crle
 #       and create runtime configuration files that will establish
 #       alternative dependency mappings for the objects identified.
@@ -899,19 +901,21 @@
         my $LineNum;
         my $obj_path;
         my $obj_active = 0;
         my $obj_class;
 
-        my $prefix = OpenFindElf($file, \*FIND_ELF);
+        my $prefix;
+FILE:
+        while ($prefix = OpenFindElf($file, \*FIND_ELF)) {
 
-LINE:
+        LINE:
         while ($line = onbld_elfmod::GetLine(\*FIND_ELF, \$LineNum)) {
               ITEM: {
 
                         if ($line =~ /^OBJECT\s/i) {
-                                my ($item, $class, $type, $verdef, $obj) =
-                                    split(/\s+/, $line, 5);
+                                        my ($item, $class, $type, $verdef, $obj)
+                                            = split(/\s+/, $line, 5);
 
                                 if ($type eq 'DYN') {
                                         $obj_active = 1;
                                         $obj_path = $obj;
                                         $obj_class = $class;
@@ -920,15 +924,16 @@
                                         $obj_active = 0;
                                 }
                                 last ITEM;
                         }
 
-                        # We need to follow links to sharable objects so
-                        # that any dependencies are expressed in all their
-                        # available forms. We depend on ALIAS lines directly
-                        # following the object they alias, so if we have
-                        # a current object, this alias belongs to it.
+                                # We need to follow links to sharable objects
+                                # so that any dependencies are expressed in all
+                                # their available forms. We depend on ALIAS
+                                # lines directly following the object they
+                                # alias, so if we have a current object, this
+                                # alias belongs to it.
                         if ($obj_active && ($line =~ /^ALIAS\s/i)) {
                                 my ($item, $real_obj, $obj) =
                                     split(/\s+/, $line, 3);
                                 $obj_path = $obj;
                                 last ITEM;
@@ -946,39 +951,53 @@
                     ($obj_path =~ $EXRE_nocrlealt);
 
                 my $Dir = $full;
                 $Dir =~ s/^(.*)\/.*$/$1/;
 
-                # Create a crle(1) script for the dependency we've found.
-                # We build separate scripts for the 32 and 64-bit cases.
-                # We create and initialize each script when we encounter
-                # the first object that needs it.
+                        # Create a crle(1) script for the dependency we've
+                        # found. We build separate scripts for the 32 and 64-bit
+                        # cases. We create and initialize each script when we
+                        # encounter the first object that needs it.
                 if ($obj_class == 32) {
                         if (!$Crle32) {
                                 $Crle32 = "$Tmpdir/$Prog.crle32.$$";
-                                open(CRLE32, "> $Crle32") ||
-                                    die "$Prog: open failed: $Crle32: $!";
+                                        open(CRLE32, "> $Crle32") || die
+                                            "$Prog: open failed: $Crle32: $!";
                                 print CRLE32 "#!/bin/sh\ncrle \\\n";
                         }
                         print CRLE32 "\t-o $Dir -a /$obj_path \\\n";
                 } elsif ($Ena64) {
                         if (!$Crle64) {
                                 $Crle64 = "$Tmpdir/$Prog.crle64.$$";
-                                open(CRLE64, "> $Crle64") ||
-                                    die "$Prog: open failed: $Crle64: $!";
+                                        open(CRLE64, "> $Crle64") || die
+                                            "$Prog: open failed: $Crle64: $!";
                                 print CRLE64 "#!/bin/sh\ncrle -64\\\n";
                         }
                         print CRLE64 "\t-o $Dir -a /$obj_path \\\n";
                 }
         }
 
         close FIND_ELF;
+                if ($file eq $_[0]) {
+                        $file = $_[1];
+                        next FILE;
+                }
 
+                last FILE;
+        }
 
         # Now that the config scripts are complete, use them to generate
         # runtime linker config files.
+        $Adjunct //= "";
+
         if ($Crle64) {
+                print CRLE64
+                        "\t-l ${Proto}/lib/64:${Proto}/usr/lib/64 \\\n";
+
+                print CRLE64
+                    "\t-l ${Adjunct}/lib/64:${Adjunct}/usr/lib/64 \\\n";
+
                 $Conf64 = "$Tmpdir/$Prog.conf64.$$";
                 print CRLE64 "\t-c $Conf64\n";
 
                 chmod 0755, $Crle64;
                 close CRLE64;
@@ -987,10 +1006,13 @@
 
                 # Done with the script
                 unlink $Crle64;
         }
         if ($Crle32) {
+                print CRLE32 "\t-l ${Proto}/lib:${Proto}/usr/lib \\\n";
+                print CRLE32 "\t-l ${Adjunct}/lib:${Adjunct}/usr/lib \\\n";
+
                 $Conf32 = "$Tmpdir/$Prog.conf32.$$";
                 print CRLE32 "\t-c $Conf32\n";
 
                 chmod 0755, $Crle32;
                 close CRLE32;
@@ -1049,16 +1071,18 @@
 # $Env is used with all calls to ldd. It is set by AltObjectConfig to
 # cause an alternate object mapping runtime config file to be used.
 $Env = '';
 
 # Check that we have arguments.
-if ((getopts('D:d:E:e:f:I:imosvw:', \%opt) == 0) ||
+if ((getopts('A:a:D:d:E:e:f:I:imosvw:', \%opt) == 0) ||
     (!$opt{f} && ($#ARGV == -1))) {
-        print "usage: $Prog [-imosv] [-D depfile | -d depdir] [-E errfile]\n";
+        print "usage: $Prog [-imosv] [-A depfile | -a depdir ] [-D depfile | -d depdir] [-E errfile]\n";
         print "\t\t[-e exfile] [-f listfile] [-I infofile] [-w outdir]\n";
         print "\t\t[file | dir]...\n";
         print "\n";
+        print "\t[-A depfile]\testablish adjunct dependencies from 'find_elf -r' file list\n";
+        print "\t[-a depdir]\testablish adjunct dependencies from under directory\n";
         print "\t[-D depfile]\testablish dependencies from 'find_elf -r' file list\n";
         print "\t[-d depdir]\testablish dependencies from under directory\n";
         print "\t[-E errfile]\tdirect error output to file\n";
         print "\t[-e exfile]\texceptions file\n";
         print "\t[-f listfile]\tuse file list produced by find_elf -r\n";
@@ -1070,10 +1094,11 @@
         print "\t[-v]\t\tprocess version definition entries\n";
         print "\t[-w outdir]\tinterpret all files relative to given directory\n";
         exit 1;
 }
 
+die "$Prog: -A and -a options are mutually exclusive\n" if ($opt{A} && $opt{a});
 die "$Prog: -D and -d options are mutually exclusive\n" if ($opt{D} && $opt{d});
 
 $Tmpdir = "/tmp" if (!($Tmpdir = $ENV{TMPDIR}) || (! -d $Tmpdir));
 
 # If -w, change working directory to given location
@@ -1082,11 +1107,10 @@
 # Locate and process the exceptions file
 onbld_elfmod::LoadExceptionsToEXRE('check_rtime');
 
 # Is there a proto area available, either via the -d option, or because
 # we are part of an activated workspace?
-my $Proto;
 if ($opt{d}) {
         # User specified dependency directory - make sure it exists.
         -d $opt{d} || die "$Prog: $opt{d} is not a directory\n";
         $Proto = $opt{d};
 } elsif ($ENV{CODEMGR_WS}) {
@@ -1095,28 +1119,44 @@
         # Without a user specified dependency directory see if we're
         # part of a codemanager workspace and if a proto area exists.
         $Proto = $Root if ($Root = $ENV{ROOT}) && (-d $Root);
 }
 
+# Is there an adjunct proto area available, either via the -a option,
+# or because we are part of an activated workspace?
+if ($opt{a}) {
+        # User specified dependency directory - make sure it exists.
+        -d $opt{a} || die "$Prog: $opt{a} is not a directory\n";
+        $Adjunct = $opt{a};
+} elsif ($ENV{CODEMGR_WS}) {
+        my $Root;
+
+        # Without a user specified dependency directory see if we're
+        # part of a codemanager workspace and if an adjunct proto area
+        # exists.
+        $Adjunct = $Root if ($Root = $ENV{ADJUNCT_PROTO}) && (-d $Root);
+}
+
 # If we are basing this analysis off the sharable objects found in
 # a proto area, then gather dependencies and construct an alternative
 # dependency mapping via a crle(1) configuration file.
 #
 # To support alternative dependency mapping we'll need ldd(1)'s
 # -e option.  This is relatively new (s81_30), so make sure
 # ldd(1) is capable before gathering any dependency information.
-if ($opt{D} || $Proto) {
+if ($opt{D} || $Proto || $Adjunct) {
         if (system('ldd -e /usr/lib/lddstub 2> /dev/null')) {
                 print "ldd: does not support -e, unable to ";
                 print "create alternative dependency mappingings.\n";
                 print "ldd: option added under 4390308 (s81_30).\n\n";
         } else {
-                # If -D was specified, it supplies a list of files in
+                # If -D or -A was specified, it supplies a list of files in
                 # 'find_elf -r' format, and can use it directly. Otherwise,
                 # we will run find_elf as a child process to find the
                 # sharable objects found under $Proto.
-                AltObjectConfig($opt{D} ? $opt{D} : "find_elf -frs $Proto|");
+                AltObjectConfig($opt{D} ? $opt{D} : "find_elf -frs $Proto|",
+                        $opt{A} ? $opt{A} : $Adjunct ? "find_elf -frs $Adjunct|" : "/dev/null");
         }
 }
 
 # To support unreferenced dependency detection we'll need ldd(1)'s -U
 # option.  This is relatively new (4638070), and if not available we