bintools/elftools/deputil.pm
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 #
       
     2 # Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 package DepUtil;
       
    18 
       
    19 require Exporter;
       
    20 @ISA=qw(Exporter);
       
    21 
       
    22 @EXPORT=qw(
       
    23 	GenDependencies
       
    24 );
       
    25 use strict;
       
    26 my ($interworking, $outfile, $genpath, $libpath, $librariesRef, $gVerbose);
       
    27 sub GenDependencies {
       
    28 	($interworking, $outfile, $genpath, $libpath, $librariesRef, $gVerbose) = @_;
       
    29 	my @dsoList;
       
    30 	foreach my $alib (@$librariesRef) {
       
    31 #	.lib files are archive file. Get the corresponding dso file which is in ELF.
       
    32 		if($alib =~ /(.*)\.lib$/) {
       
    33 			my $dso = "$1.dso";
       
    34 			if(-e $dso){
       
    35 				push @dsoList, $dso;
       
    36 				}
       
    37 		}
       
    38 		elsif($alib =~ /.*\.dso$/) {
       
    39 			if(-e $alib){
       
    40 				push @dsoList, $alib;
       
    41 				}
       
    42 		}
       
    43 	}
       
    44 	my @linkAsList=();
       
    45 	foreach my $dso (@dsoList) {
       
    46 #	Get the linkas names of the libraries
       
    47 		open PIPE, "getexports -s $dso |";
       
    48 		while(<PIPE>) {
       
    49 			if($_ =~ /(\S+)/){
       
    50 			push @linkAsList, $1;
       
    51 			}
       
    52 	 	}
       
    53 		close PIPE;
       
    54 	}
       
    55 	GenLinkerSteeringFileForDeps(\@linkAsList) if($outfile);
       
    56 }
       
    57 
       
    58 sub GenLinkerSteeringFileForDeps {
       
    59 #	Generate the linker steering file to indicate in the final ELF file 
       
    60 #	about the static dependencies. This list gives the list and order of
       
    61 #	library names in which name lookup shall happen. Whether they were
       
    62 #	actually linked-in in the final ELF shall be determined by the import
       
    63 #	table. The import table fails to maintain the linking order and is
       
    64 #	achieved through these linker directives.
       
    65 
       
    66 	my ($LinkAsNamesRef) = @_;
       
    67 	my $depfile = "$genpath\\$outfile.dep";
       
    68 	open OUTFILE, ">$depfile" or
       
    69 		die "Can't create file $depfile\n";
       
    70 	print OUTFILE "; This is a generated file for Static Dependency listing";
       
    71 	print OUTFILE "; causing the linker to create DT_NEEDED tag(s) in the dynamic array\n\n";
       
    72 
       
    73 	foreach my $name (@$LinkAsNamesRef) {
       
    74 		print OUTFILE "\n\tREQUIRE \"$name\"";
       
    75 	}
       
    76 	print OUTFILE "\n";
       
    77 	close OUTFILE;
       
    78 }
       
    79 
       
    80 1;