2002-01-24 23:07:46 +00:00
|
|
|
#!/usr/bin/perl -w
|
2001-06-20 20:21:49 +00:00
|
|
|
#
|
|
|
|
# This perl script takes an order file produced by the "order" program
|
|
|
|
# as input (specified on the command line) and outputs a script for
|
|
|
|
# GNU ld that orders functions in the specified order, assuming that
|
|
|
|
# all of the source files were compiled with the -ffunction-sections
|
|
|
|
# flag. Output goes to the file specified with "-o" flag.
|
|
|
|
|
|
|
|
use Getopt::Std;
|
|
|
|
getopts("o:");
|
|
|
|
if ($#ARGV != 0 || !defined $::opt_o) {
|
|
|
|
die("usage: mklinkscript -o script-file order-file");
|
|
|
|
}
|
|
|
|
$linkScript = $::opt_o;
|
|
|
|
$tmpFile = "$linkScript.tmp";
|
|
|
|
$orderFile = $ARGV[0];
|
|
|
|
|
|
|
|
open(LD, "ld --verbose|") || die("ld: $!");
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initial output is to a temp file so that if we fail there won't be
|
|
|
|
# broken GNU ld script lying around to confuse the build and anyone
|
|
|
|
# trying to use it.
|
|
|
|
#
|
|
|
|
open(TMP, ">$tmpFile") || die("$tmpFile: $!");
|
|
|
|
|
|
|
|
sub PrintOrder {
|
|
|
|
my $line;
|
|
|
|
open(ORDER, $orderFile) || die("$orderFile: $!");
|
|
|
|
while ($line = <ORDER>) {
|
|
|
|
chomp $line;
|
|
|
|
print(TMP "*(.text.$line)\n");
|
2002-01-24 23:07:46 +00:00
|
|
|
print(TMP "*(.gnu.linkonce.t.$line)\n");
|
2001-06-20 20:21:49 +00:00
|
|
|
}
|
|
|
|
close(ORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
$skip = 1;
|
|
|
|
LINE:
|
|
|
|
while ($line = <LD>) {
|
|
|
|
chomp $line;
|
|
|
|
if ($skip && $line =~ /^=*$/) {
|
|
|
|
$skip = 0;
|
|
|
|
next LINE;
|
|
|
|
} elsif (!$skip && $line =~ /^=*$/) {
|
|
|
|
last LINE;
|
|
|
|
}
|
|
|
|
if ($skip) {
|
|
|
|
next LINE;
|
|
|
|
}
|
|
|
|
print TMP "$line\n";
|
|
|
|
if ($line =~ /^[\s]*.text[\s]*:[\s]*$/) {
|
2002-01-24 23:07:46 +00:00
|
|
|
defined($line = <LD>) || die("Premature end of ld input");
|
2001-06-20 20:21:49 +00:00
|
|
|
print TMP "$line";
|
|
|
|
print TMP "*(.text)\n";
|
|
|
|
&PrintOrder();
|
|
|
|
<LD>; # Skip over *(.text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(LD);
|
|
|
|
close(TMP);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Everything went OK, so create the real output file.
|
|
|
|
#
|
2002-01-24 23:07:46 +00:00
|
|
|
rename($tmpFile, $linkScript) || die("$linkScript: $!");
|