DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#!/usr/bin/perl -w
#
# 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");
        print(TMP "*(.gnu.linkonce.t.$line)\n");
    }
    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]*$/) {
        defined($line = <LD>) || die("Premature end of ld input");
        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.
#
rename($tmpFile, $linkScript) || die("$linkScript: $!");