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';
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";
49 return do_snap
($out) if (!-e
$obj_old);
51 if (system('cmp', '-s', '--', $obj_old, $obj) == 0) {
53 return empty_diff
($out);
56 my ($bits, $sections, $entrysyms) = split("\n", runsuc
("objdiff", $obj_old, $obj));
57 die if ($bits ne '32' && $bits ne '64');
58 return empty_diff
($out) if ($sections eq '' && $entrysyms eq '');
60 copy
($obj, "$obj.KSPLICE_primary");
61 copy
($obj_old, "$obj.KSPLICE_helper");
63 open OBJ
, '<', $obj or die;
64 open OBJ_OLD
, '<', $obj_old or die;
65 my $tag = Digest
::MD5
->new->addfile(*OBJ
)->addfile(*OBJ_OLD
)->hexdigest;
69 my $relocs_primary = runsuc
("objmanip", "$obj.KSPLICE_primary", "keep-primary", "____${tag}", "_post", split(/\s/, $sections));
70 runsuc
("objmanip", "$obj.KSPLICE_primary", "globalize", "____${tag}_post");
72 my $relocs_helper = runsuc
("objmanip", "$obj.KSPLICE_helper", "keep-helper", "____${tag}", "_pre");
73 runsuc
("objmanip", "$obj.KSPLICE_helper", "globalize", "____${tag}_pre");
76 foreach my $sym (split(/\s/, $entrysyms)) {
77 $patchlist .= "${sym}____${tag}_pre ${sym}____${tag}_post\n";
80 open OUT
, '>', "$out.tmp";
81 print OUT
"$bits\n$patchlist\n$relocs_primary\n$relocs_helper\n";
83 rename "$out.tmp", $out;
89 my ($outbits, $patchlist, $relocs_primary, $relocs_helper) = (undef, '', '', '');
90 foreach my $in (@ins) {
92 my ($obj) = $in =~ /^(.*)\.KSPLICE$/ or die;
97 chomp(my $bits = <IN
>);
98 die if (defined $outbits && $outbits ne $bits);
101 $patchlist .= $_ while (($_ = <IN
>) ne "\n");
102 $relocs_primary .= $_ while (($_ = <IN
>) ne "\n");
103 $relocs_helper .= $_ while (($_ = <IN
>) ne "\n");
108 return empty_diff
($out) unless (defined $outbits);
110 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
112 copy
"$objs[0].KSPLICE_primary", "$obj.KSPLICE_primary";
113 copy
"$objs[0].KSPLICE_helper", "$obj.KSPLICE_helper";
115 system("ld", "-r", "-o",
116 map { "$_.KSPLICE_primary" } ($obj, @objs));
117 system("ld", "-r", "-o",
118 map { "$_.KSPLICE_helper" } ($obj, @objs));
121 open OUT
, '>', "$out.tmp";
122 print OUT
"$outbits\n$patchlist\n$relocs_primary\n$relocs_helper\n";
124 rename "$out.tmp", $out;
130 'combine' => \
&do_combine
,
133 my ($cmd, @args) = @ARGV;
134 if (exists $handlers{$cmd}) {
135 my $handler = $handlers{$cmd};
138 print "Usage: ksplice.pl ", join('|', keys %handlers), " ...\n";