sbsv1_os/e32toolp/e32util/makedef.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # all variables called *Path* are set up to end with a backslash
       
    15 # all variables called *Path or *File are stored as absolute (file)paths
       
    16 # all variables called UpPath* are stored as relative paths
       
    17 # 
       
    18 #
       
    19 
       
    20 use strict   ;
       
    21 
       
    22 use FindBin;		# for FindBin::Bin
       
    23 use Getopt::Long;
       
    24 
       
    25 my $PerlBinPath;	# fully qualified pathname of the directory containing this script
       
    26 my $EntryPoint;         
       
    27 my $InternalEntryPoint;
       
    28 
       
    29 # establish the path to the Perl binaries
       
    30 BEGIN {
       
    31 	require 5.005_03;				# check user has a version of perl that will cope
       
    32 	$PerlBinPath = $FindBin::Bin;	# X:/epoc32/tools
       
    33 
       
    34 	if ($^O eq "MSWin32")
       
    35 		{	
       
    36 		$PerlBinPath =~ s/\//\\/g;		# X:\epoc32\tools
       
    37 		}
       
    38 }
       
    39 use lib $PerlBinPath;
       
    40 
       
    41 use Defutl;
       
    42 use E32tpver;
       
    43 use Pathutl;
       
    44 use File::Copy;
       
    45 
       
    46 my %Options;	# command line option information
       
    47 
       
    48 my $NamedSymLkup = 0;			# This flag is used to enable named lookup on emulator
       
    49 my $IgnoreUnfrozenExports = 0;	# This flag is used to ignore the 'unfrozen exports' warnings. This is 
       
    50 								# required for STDEXEs which export symbols just to enable 'named lookup'
       
    51 								# from within the STDEXE (via 'dlsym') and are never exposed outside (via def files or
       
    52 								# import libraries.
       
    53 my $ExportEntrypointE32Dll = 0;	 # Workaround: To export entry point _E32DLL for target type STDDLL
       
    54 
       
    55 # THE MAIN PROGRAM SECTION
       
    56 ##########################
       
    57 
       
    58 {
       
    59 
       
    60 	my $INFILE;
       
    61 	my $FRZFILE;
       
    62 	my $OUTFILE;
       
    63 	my @ObjFiles;
       
    64 
       
    65 	# process the command-line
       
    66 	unless (GetOptions(\%Options, '1=s', '2=s', 'deffile=s', 'frzfile=s', 'inffile=s', 'overwrite', 'absent=s', 'ignore_unfrozen_noncallable', 'SystemTargetType', 'sym_name_lkup', 'ignore_unfrozen_exports','export_entrypoint_E32Dll')) {
       
    67 		exit 1;
       
    68 	}
       
    69 	unless (@ARGV==1) {
       
    70 		&Usage;
       
    71 	}
       
    72 
       
    73 #	check the flags
       
    74 
       
    75 	if (($Options{deffile} and $Options{inffile}) or (not ($Options{deffile} or $Options{inffile}))) {
       
    76 		die "MAKEDEF ERROR: Must specify either -Deffile [file] or -Inf [file]\n";
       
    77 	}
       
    78 	if ($Options{2} && !$Options{1}) {
       
    79 		die "MAKEDEF ERROR: Can't specify second export name and not first export name\n";
       
    80 	}
       
    81 
       
    82 #	process the flags
       
    83 	if ($Options{deffile}) {
       
    84 		$INFILE=$Options{deffile};
       
    85 		unless (-e $INFILE) {
       
    86 			die "MAKEDEF ERROR: $INFILE: Deffile not found\n";
       
    87 		}
       
    88 	}
       
    89 	else {
       
    90 		$INFILE=$Options{inffile};
       
    91 		unless (-e $INFILE) {
       
    92 			die "MAKEDEF ERROR: $INFILE: Inffile not found\n";
       
    93 		}
       
    94 	}
       
    95 	if ($Options{frzfile}) {
       
    96 		$FRZFILE=$Options{frzfile};
       
    97 #		check the frozen .DEF file exists
       
    98 		unless (-e $FRZFILE) {
       
    99 			die "MAKEDEF ERROR: $FRZFILE: Frzfile not found\n";
       
   100 		}
       
   101 	}
       
   102 	$OUTFILE=pop @ARGV;
       
   103 
       
   104 
       
   105 	$NamedSymLkup = $Options{sym_name_lkup};
       
   106 	$IgnoreUnfrozenExports = $Options{ignore_unfrozen_exports};
       
   107 	$ExportEntrypointE32Dll = $Options{export_entrypoint_E32Dll};	# Workaround: To export entry point _E32DLL for target type STDDLL
       
   108 
       
   109 #	Read the Frozen .DEF file if specified
       
   110 	my @FrzDataStruct;
       
   111 	if ($FRZFILE) {
       
   112 		eval { &Def_ReadFileL(\@FrzDataStruct, $FRZFILE); };
       
   113 		die $@ if $@;
       
   114 		if ($Options{1}) {
       
   115 #			Check that frozen def file matches the -1 and -2 arguments given, if any
       
   116 			my $export1="";
       
   117 			my $export2="";
       
   118 			foreach my $FrzRef (@FrzDataStruct) {
       
   119 				next unless $$FrzRef{Name};		# ignore lines not containing an export
       
   120 				if ($$FrzRef{Ordinal} == 1) {
       
   121 					$export1 = $$FrzRef{Name};
       
   122 					next;
       
   123 				}
       
   124 				if ($$FrzRef{Ordinal} == 2) {
       
   125 					$export2 = $$FrzRef{Name};
       
   126 					next;
       
   127 				}
       
   128 				if ($Options{1} && ($Options{1} ne $export1)) {
       
   129 					die "MAKEDEF ERROR: $FRZFILE: Frzfile ordinal 1 does not match command line\n";
       
   130 				}
       
   131 				if ($Options{2} && ($Options{2} ne $export2)) {
       
   132 					die "MAKEDEF ERROR: $FRZFILE: Frzfile ordinal 2 does not match command line\n";
       
   133 				}
       
   134 			}
       
   135 		}
       
   136 	}
       
   137 	elsif ($Options{1}) {
       
   138 #		create an export structure for the names passed on the command line
       
   139 		push @FrzDataStruct, {
       
   140 			Name=>$Options{1},
       
   141 			ExportName=>$Options{1},
       
   142 			Ordinal=>1
       
   143 		};
       
   144 		if ($Options{2}) {
       
   145 			push @FrzDataStruct, {
       
   146 				Name=>$Options{2},
       
   147 				ExportName=>$Options{2},
       
   148 				Ordinal=>2
       
   149 			};
       
   150 		}
       
   151 	}
       
   152 
       
   153 #	Read the Input .DEF file
       
   154 	my @InDataStruct;
       
   155 	if ($Options{deffile}) {
       
   156 		eval { &Def_ReadFileL(\@InDataStruct, $INFILE); };
       
   157 	}
       
   158 	else {
       
   159 		eval { &ReadInfFileL(\@InDataStruct, $INFILE); };
       
   160 	}
       
   161 	die $@ if $@;
       
   162 
       
   163 #	Compare the frozen .DEF data with the input .DEF or export info file data
       
   164 	my (@NewDataStruct, @MissingDataStruct, @MatchedDataStruct);
       
   165 	eval { &CompareFrzInL (\@NewDataStruct, \@MissingDataStruct, \@MatchedDataStruct, \@FrzDataStruct, \@InDataStruct); };
       
   166 	die $@ if $@;
       
   167 
       
   168 	# MAKEDEF should generate a warning if the def file has no exports (old or new)
       
   169 	# and the associated MMP 'targettype' is not a System Target type.
       
   170 	print "MAKEDEF WARNING: $OUTFILE has no EXPORTS\n" unless (@MatchedDataStruct || @NewDataStruct || $Options{SystemTargetType});
       
   171 
       
   172 #	Create the output .DEF file
       
   173 	eval { &CreateDefFileL(\@NewDataStruct, \@MatchedDataStruct, $OUTFILE, $FRZFILE); };
       
   174 	die $@ if $@;
       
   175 
       
   176 #	report missing frozen export errors
       
   177 	if (@MissingDataStruct) {
       
   178 		my @Errors;
       
   179 		my $Num=@MissingDataStruct;
       
   180 		my $Ref;
       
   181 		if ($FRZFILE) {
       
   182 			push @Errors, "MAKEDEF ERROR: $Num Frozen Export(s) missing from object files (POSSIBLE COMPATIBILITY BREAK):\n";
       
   183 			foreach $Ref (@MissingDataStruct) {
       
   184 				push @Errors, "  $FRZFILE($$Ref{LineNum}) : $$Ref{Name} \@$$Ref{Ordinal}\n";
       
   185 			}
       
   186 		}
       
   187 		else {
       
   188 			push @Errors, "MAKEDEF ERROR: command-line: $Num Frozen Export(s) missing from object files (POSSIBLE COMPATIBILITY BREAK):\n";
       
   189 			foreach $Ref (@MissingDataStruct) {
       
   190 				push @Errors, "  $$Ref{Name} \@$$Ref{Ordinal}\n";
       
   191 			}
       
   192 		}
       
   193 		die "\n", @Errors;
       
   194 	}
       
   195 	elsif ($Options{overwrite} && -w $FRZFILE) #sag
       
   196 		{
       
   197 		print "Copying $OUTFILE to $FRZFILE\n";
       
   198 		rename $FRZFILE, "$FRZFILE.bak";
       
   199 		copy($OUTFILE, $FRZFILE);
       
   200 		}
       
   201 
       
   202 	exit 0;
       
   203 }
       
   204 
       
   205 #######################################################################
       
   206 # SUBROUTINES
       
   207 #######################################################################
       
   208 
       
   209 sub Usage () {
       
   210 
       
   211 	print(
       
   212 		"\n",
       
   213 		"MAKEDEF - .DEF file generator (Build ",&E32tpver,")\n",
       
   214 		"\n",
       
   215 		"MAKEDEF {options} [Output .DEF file]\n",
       
   216 		"\n",
       
   217 		"options:   (case-insensitive)\n",
       
   218 		"  -Deffile [Input .DEF file]\n",
       
   219 		"  -Inffile [Input export information file]\n",
       
   220 		"  -Frzfile [Frozen .DEF file]\n",
       
   221 		"  -1 [first export name] {-2 [second export name]}\n",
       
   222 		"  -Overwrite\n",
       
   223 		"  -Absent [symbol to use for absent exports]\n",
       
   224 		"  -ignore_unfrozen_noncallable\n",
       
   225 		"  -SystemTargetType\n",
       
   226 		"  -sym_name_lkup [Enable symbol lookup by name]\n",
       
   227 		"  -ignore_unfrozen_exports \n",
       
   228 		"\n",
       
   229 		"Either specify -Deffile or -Inffile, and\n",
       
   230 		"either -Frzfile or -1 {-2} if required.\n"
       
   231 	);
       
   232 	exit 1;
       
   233 }
       
   234 
       
   235 sub ReadInfFileL ($$$) {
       
   236 	my ($DataStructRef, $FILE)=@_;
       
   237 
       
   238 #	open export information file for reading
       
   239 	open (FILE, "<$FILE") or die "could not open $FILE: $!";
       
   240 
       
   241 #	read the export info. file, and create dummy frozen .DEF file text
       
   242 	my $LineNum=0;
       
   243 	my $Ordinal=0;
       
   244 	my $Comment='';
       
   245 	my $Name='';
       
   246 	my $InfType=0;	# dumpbin output
       
   247 	my %exports;	# MWLD workaround - record mangled names in case we don't see the demangled ones
       
   248 	my $Line;
       
   249 	while ($Line=<FILE>) {
       
   250 	        my $Data=0;
       
   251 			my $SymbolSize=0;
       
   252 		$LineNum++;
       
   253 		if ($InfType == 0) {
       
   254 			if ($Line =~ /\*\*\* ARCHIVE SYMBOL TABLE.* \*\*\*/o) {
       
   255 				$InfType=1;	# mwld disassembly output
       
   256 				next;
       
   257 			}
       
   258 			if ($Line =~ /^\s+(\?\S+)(\s+\((.*)\))?$/o) {
       
   259 #                   ??0TAgnAlarmDefaults@@QAE@XZ (public: __thiscall TAgnAlarmDefaults::TAgnAlarmDefaults(void))
       
   260 				$Name=$1;
       
   261 				$Comment=$3;
       
   262 			} 
       
   263 			elsif ($Line =~ /^\s+_(\S+)(\s+\((.*)\))?$/o) {
       
   264 # frozen ordinals like "UserNoLongerSupported01" seem to inherit a leading underscore in the dumpbin output
       
   265 				$Name=$1;
       
   266 				$Comment=$3;
       
   267 			}
       
   268 			elsif ($Line =~ /^\s+_(\S+) DATA (\d+)(\s+\((.*)\))?$/o) {
       
   269 #				Mark the data symbols and retain their sizes
       
   270 				$Name=$1;
       
   271 				$Data=1;
       
   272 				$SymbolSize=$2;
       
   273 				$Comment=$4;
       
   274 			}
       
   275 			else {
       
   276 				next;
       
   277 			}
       
   278 		}
       
   279 		else {
       
   280 			# The Windows CW linker produces .inf files with a 'something' unmangled comment at the end, the Linux CW linker doesn't
       
   281 			if ($Line =~ /^\s*\d+\s+\(.+\)\s+__imp_((.)(\S+))(\s+'__declspec\(dllimport\)\s+(.*)')?$/o) {
       
   282 					if ($2 eq "_") {
       
   283 							$Name = $3;		# C symbol, so remove leading underscore
       
   284 							$Comment = $5 if ($4);	# name isn't mangled anyway
       
   285 					} else {
       
   286 							$Name = $1;		# C++ mangled name
       
   287 							$Comment = $5 if ($4);	# can't unmangle names...
       
   288 					}
       
   289 
       
   290 					# One side-effect of ignoring comments if they're not present is that Windows entry points need to be
       
   291 					# specifically ignored.  Previously they were ignored by virture of the fact they had no comment.
       
   292 					next if ($Name eq "_E32Dll" || $Name eq "_E32Startup");
       
   293 
       
   294 					$Comment = $4 ? $5 : $Name;
       
   295 					
       
   296 					# need to save both the line number and
       
   297 					# comment
       
   298 					my %entry;
       
   299 					$entry{'lineNum'} = $LineNum;
       
   300 					$entry{'comment'} = $Comment;
       
   301 					$exports{$Name}=\%entry;
       
   302 					next;
       
   303 			}
       
   304 			if ($Line =~ /\*\*\* Unmangled Symbols \*\*\*/o) {
       
   305 				# Currently for Linux "Unmangled Symbols" section is blank
       
   306 				<FILE>; 
       
   307 				$Line = <FILE>; 
       
   308 				$LineNum+=2;
       
   309 				if ($^O eq "MSWin32") {
       
   310 					if ($Line !~ /^\s*\d+:\s+(\S+)$/o) {
       
   311 						print STDERR "MAKEDEF WARNING: unknown inf file format\n";
       
   312 						next;
       
   313 					}
       
   314 				}
       
   315 				$Name = $1;
       
   316 # Workaround: if MWLD can't demangle the name, we will see only the __imp_ version.
       
   317 				if ($Name =~ /^__imp_(\S+)$/o) {
       
   318 					$Name = $1;
       
   319 				}
       
   320 				$Line = <FILE>; 
       
   321 				$LineNum++;
       
   322 				next if ($Line !~ /^\s+(.+)$/o);
       
   323 				$Comment = $1;
       
   324 			}
       
   325 			elsif ($Line =~ /^0x\S{8}\s+__imp__(\S+)$/o) {
       
   326 				$Name = $1;	# leading underscore already removed
       
   327 				$Comment = '';	# a C symbol, and therefore not mangled
       
   328 			}
       
   329 			else {
       
   330 				next;
       
   331 			}
       
   332 		}
       
   333 # Check for WINS entrypoint symbols
       
   334 		if ($Name eq "_E32Dll" || $Name eq "_E32Startup") {
       
   335 			$EntryPoint = $Name;
       
   336 			# when mwld resolves an exported symbol S coming from
       
   337 			# the def file, it looks both for S() and _S() in
       
   338 			# every object file but only for _S() in static
       
   339 			# libraries.
       
   340 			#
       
   341 			# As a consequence, we need to distinguish the
       
   342 			# internal entry point name from the external one.
       
   343 			$InternalEntryPoint = "_$Name" if ($InfType != 0);
       
   344 			my $entry = $exports{$Name};
       
   345 			$entry->{'lineNum'} = 0; # indicates processed name
       
   346 			next;
       
   347 		}
       
   348 		$Ordinal++;
       
   349 		$Comment='' if (!defined $Comment);
       
   350 		push @$DataStructRef, {
       
   351 			Ordinal=>$Ordinal,
       
   352 			Name=>$Name,
       
   353 			Data=>$Data,
       
   354 			Size=>$SymbolSize,
       
   355 			ExportName=>$Name,
       
   356 			Comment=>$Comment,
       
   357 			LineNum=>$LineNum
       
   358 		};
       
   359 		my $entry = $exports{$Name};
       
   360 		$entry->{'lineNum'} = 0; # indicates processed name
       
   361 	}
       
   362 	foreach $Name (keys %exports) {
       
   363 	    	my $entry = $exports{$Name};
       
   364 		$LineNum = $entry->{'lineNum'};
       
   365 		if ($LineNum > 0) {
       
   366 			$Ordinal++;
       
   367 			push @$DataStructRef, {
       
   368 				Ordinal=>$Ordinal,
       
   369 				Name=>$Name,
       
   370 				ExportName=>$Name,
       
   371 				Comment=> $entry->{'comment'},
       
   372 				LineNum=>$LineNum
       
   373 			};
       
   374 		}
       
   375 	}
       
   376 }
       
   377 
       
   378 sub CompareFrzInL ($$$$$) {
       
   379 	my ($NewStructRef, $MissingStructRef, $MatchedStructRef, $FrzStructRef, $InStructRef)=@_;
       
   380 	my $AbsentSubst = $Options{absent};
       
   381 	my $IgnoreNoncallable = $Options{ignore_unfrozen_noncallable};
       
   382 	
       
   383 #	compare the input export data with the frozen data
       
   384 
       
   385 #	this function trashes the frozen .DEF data structure and the new .DEF data structure
       
   386 
       
   387 #	nullify non-export statements in the structures
       
   388 	foreach (@$FrzStructRef,@$InStructRef) {
       
   389 		next if $$_{Name};
       
   390 		undef $_;
       
   391 	}
       
   392 
       
   393 	my $LastOrdinal=0;
       
   394 
       
   395 	my $FrzRef;
       
   396 	my $InRef;
       
   397 	FRZLOOP: foreach $FrzRef (@$FrzStructRef) {
       
   398 		next unless $$FrzRef{Name};		# ignore lines in the .DEF file not containing an export
       
   399 		if ($LastOrdinal<$$FrzRef{Ordinal}) {
       
   400 			$LastOrdinal=$$FrzRef{Ordinal};
       
   401 		}
       
   402 		foreach $InRef (@$InStructRef) {
       
   403 			next unless defined $InRef; # ignore nullified entries in the temporary array
       
   404 #			does the function name match?
       
   405 			if ($$InRef{Name} eq $$FrzRef{Name}) {
       
   406 #				give the generated export the same number as the corresponding frozen one
       
   407 				$$InRef{Ordinal}=$$FrzRef{Ordinal};
       
   408 				$$InRef{Data}=$$FrzRef{Data};
       
   409 				$$InRef{Size}=$$FrzRef{Size};
       
   410 #				if the export is marked as absent, redirect it appropriately
       
   411 				if ($$FrzRef{Absent}) {
       
   412 					if ($AbsentSubst) {
       
   413 						$$InRef{Name} = $AbsentSubst;
       
   414 						$$InRef{ExportName} = sprintf("\"_._.absent_export_%d\"", $$InRef{Ordinal});
       
   415 					}
       
   416 				}
       
   417 				push @$MatchedStructRef, $InRef;
       
   418 				undef $InRef;
       
   419 				next FRZLOOP;
       
   420 			}
       
   421 		}
       
   422 #		these frozen exports haven't been found in the object files
       
   423 #		first check for ABSENT declarations
       
   424 		if ($AbsentSubst and $$FrzRef{Absent}) {
       
   425 			$$FrzRef{Name} = $AbsentSubst;
       
   426 			$$FrzRef{ExportName} = sprintf("\"_._.absent_export_%d\"", $$FrzRef{Ordinal});
       
   427 			push @$MatchedStructRef, $FrzRef;
       
   428 			next FRZLOOP;
       
   429 		}
       
   430 
       
   431 #		No - it's really missing
       
   432 		push @$MissingStructRef, $FrzRef;
       
   433 #		put a comment in the generated .DEF file to that effect
       
   434 		$$FrzRef{Missing}=1;
       
   435 		push @$MatchedStructRef, $FrzRef;
       
   436 	}
       
   437 
       
   438 #	all the exports left in the new .DEF file aren't frozen - give them the right ordinals
       
   439 	foreach $InRef (@$InStructRef) {
       
   440 		next unless defined $InRef; # ignore nullified entries
       
   441 		if ($$InRef{Name} =~ /^_ZTV|_ZTI/) {
       
   442 			# EABI non-callable exports
       
   443 			next if ($IgnoreNoncallable);	
       
   444 		}
       
   445 		$LastOrdinal++;
       
   446 		$$InRef{Ordinal}=$LastOrdinal;
       
   447 		push @$NewStructRef, $InRef;
       
   448 	}
       
   449 }
       
   450 
       
   451 sub CreateDefFileL ($$$$) {
       
   452 #	creates a new .DEF file
       
   453 	my ($NewStructRef, $MatchedStructRef, $FILE, $FRZFILE)=@_;
       
   454 
       
   455 	my @Text=("EXPORTS\n");
       
   456 	my $LineNum=1;
       
   457 
       
   458 
       
   459 	my $InRef;
       
   460 	foreach $InRef (@$MatchedStructRef) {
       
   461 		my $Comment='';
       
   462 		if ($$InRef{Comment}) {
       
   463 			$Comment=" ; $$InRef{Comment}";
       
   464 		}
       
   465 		if ($$InRef{Missing}) {
       
   466 			push @Text, '; MISSING:';
       
   467 		}
       
   468 		my $Data = "";
       
   469 		if( defined $$InRef{Data} && $$InRef{Data} == 1) {
       
   470 		$Data = " DATA $$InRef{Size}" ;
       
   471 		}
       
   472 		my $r3unused = $$InRef{R3Unused} ? " R3UNUSED" : "";
       
   473 
       
   474 #		A def file entry with the keyword 'NONAME' indicates the MW linker that a named-lookup is not enabled. 
       
   475 #		Note that although it may seem, but named lookup is either enabled or disabled on a per-binary basis and not
       
   476 #		per-symbol.
       
   477 		my $noname = $NamedSymLkup ? "": " NONAME";
       
   478 		if ($$InRef{ExportName} and ($$InRef{ExportName} ne $$InRef{Name})) {
       
   479 			push @Text, "\t$$InRef{ExportName}=$$InRef{Name} \@ $$InRef{Ordinal} $noname$Data$r3unused$Comment\n";
       
   480 		} else {
       
   481 			push @Text, "\t$$InRef{Name} \@ $$InRef{Ordinal} $noname$Data$r3unused$Comment\n";
       
   482 		}
       
   483 		$LineNum++;
       
   484 		next;
       
   485 	}
       
   486 	if (@$NewStructRef) {
       
   487 
       
   488 #		warn about unfrozen exports and add them to the end of the generated .DEF file
       
   489 		my $Num=@$NewStructRef;
       
   490 		my @Warnings;
       
   491 
       
   492 		if(!$IgnoreUnfrozenExports) {
       
   493 			my $warning = "MAKEDEF WARNING: $Num export(s) not yet Frozen";
       
   494 
       
   495 			if ($FRZFILE)
       
   496 				{
       
   497 				$warning .= " in $FRZFILE";
       
   498 				}
       
   499 
       
   500 			$warning .= ":\n";
       
   501 
       
   502 			push @Warnings, $warning;
       
   503 		}
       
   504 
       
   505 		push @Text, "; NEW:\n";
       
   506 		$LineNum++;
       
   507 		foreach $InRef (@$NewStructRef) {
       
   508 			my $Comment='';
       
   509 			if ($$InRef{Comment}) {
       
   510 				$Comment=" ; $$InRef{Comment}";
       
   511 			}
       
   512 			my $Data = "";
       
   513 			if(defined $$InRef{Data} && $$InRef{Data} == 1){
       
   514 			$Data = " DATA $$InRef{Size}";
       
   515 			}
       
   516 			my $r3unused = $$InRef{R3Unused} ? " R3UNUSED" : "";
       
   517 			my $noname = $NamedSymLkup ? "": " NONAME";
       
   518 			if ($$InRef{ExportName} and ($$InRef{ExportName} ne $$InRef{Name})) {
       
   519 				push @Text, "\t$$InRef{ExportName}=$$InRef{Name} \@ $$InRef{Ordinal} $noname$Data$r3unused$Comment\n";
       
   520 			} else {
       
   521 				push @Text, "\t$$InRef{Name} \@ $$InRef{Ordinal} $noname$Data$r3unused$Comment\n";
       
   522 			}
       
   523 			$LineNum++;
       
   524 			if(!$IgnoreUnfrozenExports) {
       
   525 				push @Warnings, "  $FILE($LineNum) : $$InRef{Name} \@$$InRef{Ordinal}\n";
       
   526 			}
       
   527 			next;
       
   528 		}
       
   529 		print @Warnings;
       
   530 	}
       
   531 	if ($EntryPoint) {
       
   532 		push @Text, "\t$EntryPoint";
       
   533 		push @Text, "=$InternalEntryPoint" if ($InternalEntryPoint);
       
   534 		push @Text, "\t; Entry point for emulation\n";
       
   535 	}
       
   536 	elsif ($ExportEntrypointE32Dll) {		# Workaround: To export entry point _E32DLL for target type STDDLL
       
   537 		push @Text, "\t_E32Dll";
       
   538 		push @Text, "=__E32Dll" ;
       
   539 		push @Text, "\t; Entry point for STDDLL emulation\n";
       
   540 	}
       
   541 
       
   542 #	add a terminating newline
       
   543 	push @Text, "\n";
       
   544 
       
   545 #	write the new .DEF file
       
   546 	eval { &Def_WriteFileL(\@Text, $FILE); };
       
   547 	die $@ if $@;
       
   548 }
       
   549