3 # Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
4 # Jeffrey Brian Arnold <jbarnold@mit.edu>,
5 # Tim Abbott <tabbott@mit.edu>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License, version 2.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 use lib
'KSPLICE_DATA_DIR';
25 $Verbose::level
= $ENV{KSPLICE_VERBOSE
} if (defined $ENV{KSPLICE_VERBOSE
});
29 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
30 unlink "$obj.KSPLICE_primary" if (-e
"$obj.KSPLICE_primary");
31 unlink "$obj.KSPLICE_helper" if (-e
"$obj.KSPLICE_helper");
32 open OUT
, '>', "$out.tmp";
34 rename "$out.tmp", $out;
39 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
41 unlink "$obj.KSPLICE_pre" if (-e
"$obj.KSPLICE_pre");
47 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
48 my $obj_old = "$obj.KSPLICE_pre";
50 die "Patch creates new object $obj" if (!-e
$obj_old);
51 if (system('cmp', '-s', '--', $obj_old, $obj) == 0) {
53 return empty_diff
($out);
56 my $objdiff = runsuc
("objdiff", $obj_old, $obj);
57 return empty_diff
($out) if($objdiff !~ m/\S/);
59 runsuc_in
($objdiff, "objmanip", $obj, "$obj.KSPLICE_primary", "keep-primary", $ENV{KSPLICE_KID
});
60 runsuc_in
($objdiff, "objmanip", $obj_old, "$obj.KSPLICE_helper", "keep-helper", $ENV{KSPLICE_KID
});
62 open OUT
, '>', "$out.tmp";
65 rename "$out.tmp", $out;
71 foreach my $in (@ins) {
73 my ($obj) = $in =~ /^(.*)\.KSPLICE$/ or die;
77 return empty_diff
($out) unless (@objs);
79 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
81 copy
"$objs[0].KSPLICE_primary", "$obj.KSPLICE_primary";
82 copy
"$objs[0].KSPLICE_helper", "$obj.KSPLICE_helper";
84 system(shellwords
($ENV{LD
}), "-r", "-o",
85 map { "$_.KSPLICE_primary" } ($obj, @objs));
86 system(shellwords
($ENV{LD
}), "-r", "-o",
87 map { "$_.KSPLICE_helper" } ($obj, @objs));
90 open OUT
, '>', "$out.tmp";
93 rename "$out.tmp", $out;
98 runsuc
("objmanip", $in, $out, "finalize");
102 my ($in, $out, @rmsyms) = @_;
103 my $relocs = runsuc
("objmanip", $in, $out, "rmsyms", @rmsyms);
106 sub do_system_map_lookup
{
108 open(SYMS
, "<", "$ENV{KSPLICE_CONFIG_DIR}/System.map") or die;
110 while (defined($line = <SYMS
>)) {
111 my ($addr, $type, $sym, $mod) = split(/\s+/, $line);
112 if ($sym eq $symarg) { print $addr; last; }
120 'combine' => \
&do_combine
,
121 'finalize' => \
&do_finalize
,
122 'rmsyms' => \
&do_rmsyms
,
123 'system_map_lookup' => \
&do_system_map_lookup
,
126 my ($cmd, @args) = @ARGV;
127 if (exists $handlers{$cmd}) {
128 my $handler = $handlers{$cmd};
131 print "Usage: ksplice-obj.pl ", join('|', keys %handlers), " ...\n";