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';
31 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
32 unlink "$obj.KSPLICE_primary" if (-e
"$obj.KSPLICE_primary");
33 unlink "$obj.KSPLICE_helper" if (-e
"$obj.KSPLICE_helper");
34 open OUT
, '>', "$out.tmp";
36 rename "$out.tmp", $out;
41 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
43 unlink "$obj.KSPLICE_pre" if (-e
"$obj.KSPLICE_pre");
49 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
50 my $obj_old = "$obj.KSPLICE_pre";
51 return do_snap
($out) if (!-e
$obj_old);
53 if (system('cmp', '-s', '--', $obj_old, $obj) == 0) {
55 return empty_diff
($out);
58 my ($bits, $sections, $entrysyms) = split("\n", runsuc
("objdiff", $obj_old, $obj));
59 die if ($bits ne '32' && $bits ne '64');
60 return empty_diff
($out) if ($sections eq '' && $entrysyms eq '');
62 copy
($obj, "$obj.KSPLICE_primary");
63 copy
($obj_old, "$obj.KSPLICE_helper");
65 open OBJ
, '<', $obj or die;
66 open OBJ_OLD
, '<', $obj_old or die;
67 my $tag = Digest
::MD5
->new->addfile(*OBJ
)->addfile(*OBJ_OLD
)->hexdigest;
71 my $relocs_primary = runsuc
("objmanip", "$obj.KSPLICE_primary", "keep-primary", "____${tag}", "_post", split(/\s/, $sections));
72 runsuc
("objmanip", "$obj.KSPLICE_primary", "globalize", "____${tag}_post");
74 my $relocs_helper = runsuc
("objmanip", "$obj.KSPLICE_helper", "keep-helper", "____${tag}", "_pre");
75 runsuc
("objmanip", "$obj.KSPLICE_helper", "globalize", "____${tag}_pre");
78 foreach my $sym (split(/\s/, $entrysyms)) {
79 $patchlist .= "${sym}____${tag}_pre ${sym}____${tag}_post\n";
82 open OUT
, '>', "$out.tmp";
83 print OUT
"$bits\n$patchlist\n$relocs_primary\n$relocs_helper\n";
85 rename "$out.tmp", $out;
91 my ($outbits, $patchlist, $relocs_primary, $relocs_helper) = (undef, '', '', '');
92 foreach my $in (@ins) {
94 my ($obj) = $in =~ /^(.*)\.KSPLICE$/ or die;
99 chomp(my $bits = <IN
>);
100 die if (defined $outbits && $outbits ne $bits);
103 $patchlist .= $_ while (($_ = <IN
>) ne "\n");
104 $relocs_primary .= $_ while (($_ = <IN
>) ne "\n");
105 $relocs_helper .= $_ while (($_ = <IN
>) ne "\n");
110 return empty_diff
($out) unless (defined $outbits);
112 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
114 copy
"$objs[0].KSPLICE_primary", "$obj.KSPLICE_primary";
115 copy
"$objs[0].KSPLICE_helper", "$obj.KSPLICE_helper";
117 system("ld", "-r", "-o",
118 map { "$_.KSPLICE_primary" } ($obj, @objs));
119 system("ld", "-r", "-o",
120 map { "$_.KSPLICE_helper" } ($obj, @objs));
123 open OUT
, '>', "$out.tmp";
124 print OUT
"$outbits\n$patchlist\n$relocs_primary\n$relocs_helper\n";
126 rename "$out.tmp", $out;
132 'combine' => \
&do_combine
,
135 my ($cmd, @args) = @ARGV;
136 if (exists $handlers{$cmd}) {
137 my $handler = $handlers{$cmd};
140 print "Usage: ksplice.pl ", join('|', keys %handlers), " ...\n";