3 # Copyright (C) 2008 Ksplice, Inc.
4 # Authors: Anders Kaseorg, Jeff Arnold, Tim Abbott
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21 use lib
'KSPLICE_DATA_DIR';
24 $Verbose::level
= $ENV{KSPLICE_VERBOSE
} if (defined $ENV{KSPLICE_VERBOSE
});
28 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
29 unlink "$obj.KSPLICE_primary" if (-e
"$obj.KSPLICE_primary");
30 unlink "$obj.KSPLICE_helper" if (-e
"$obj.KSPLICE_helper");
31 open OUT
, '>', "$out.tmp";
33 rename "$out.tmp", $out;
38 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
40 unlink "$obj.KSPLICE_pre" if (-e
"$obj.KSPLICE_pre");
46 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
47 my $obj_old = "$obj.KSPLICE_pre";
49 die "Patch creates new object $obj" if (!-e
$obj_old);
50 if (system('cmp', '-s', '--', $obj_old, $obj) == 0) {
52 return empty_diff
($out);
55 runval
("$libexecdir/ksplice-objmanip", $obj, "$obj.KSPLICE_primary", "keep-primary", "$obj.KSPLICE_pre", $ENV{KSPLICE_KID
});
56 return empty_diff
($out) if (!-e
"$obj.KSPLICE_primary");
58 open OUT
, '>', "$out.tmp";
61 rename "$out.tmp", $out;
63 runval
("$libexecdir/ksplice-objmanip", $obj_old, "$obj.KSPLICE_helper", "keep-helper");
68 my ($obj) = $out =~ /^(.*)\.KSPLICE_helper$/ or die;
69 my $obj_old = "$obj.KSPLICE_pre";
70 -e
$obj_old or $obj_old = $obj;
71 runval
("$libexecdir/ksplice-objmanip", $obj_old, "$obj.KSPLICE_helper", "keep-helper");
77 runval
(shellwords
($ENV{AR
}), "rcs", $out);
81 runval
(shellwords
($ENV{LD
}), "-r", "-o", $out, @ins);
89 foreach my $in (@ins) {
90 if (my ($obj) = $in =~ /^(.*)\.KSPLICE$/) {
92 push @primaries, "$obj.KSPLICE_primary";
93 push @helpers, "$obj.KSPLICE_helper";
94 } elsif (($obj) = $in =~ /^(.*)\.KSPLICE_helper$/) {
95 push @helpers, "$obj.KSPLICE_helper"
96 unless (@helpers && $helpers[$#helpers] eq "$obj.KSPLICE_helper");
102 return empty_diff
($out) unless (@helpers);
104 my ($obj) = $out =~ /^(.*)\.KSPLICE$/ or die;
105 link_objs
("$obj.KSPLICE_primary", @primaries);
106 link_objs
("$obj.KSPLICE_helper", @helpers);
108 open OUT
, '>', "$out.tmp";
111 rename "$out.tmp", $out;
115 my ($in, $out, $target) = @_;
116 runval
("$libexecdir/ksplice-objmanip", $in, $out, "finalize", $target);
120 my ($in, $out, @rmsyms) = @_;
121 runval_in
("@rmsyms\n", "$libexecdir/ksplice-objmanip", $in, $out, "rmsyms");
124 sub do_system_map_lookup
{
126 open(SYMS
, "<", "$ENV{KSPLICE_CONFIG_DIR}/System.map") or die;
128 while (defined($line = <SYMS
>)) {
129 my ($addr, $type, $sym, $mod) = split(/\s+/, $line);
130 if ($sym eq $symarg) { print $addr; last; }
138 'helper' => \
&do_helper
,
139 'combine' => \
&do_combine
,
140 'finalize' => \
&do_finalize
,
141 'rmsyms' => \
&do_rmsyms
,
142 'system_map_lookup' => \
&do_system_map_lookup
,
145 my ($cmd, @args) = @ARGV;
146 if (exists $handlers{$cmd}) {
147 my $handler = $handlers{$cmd};
150 print "Usage: ksplice-obj.pl ", join('|', keys %handlers), " ...\n";