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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;
# $Id$
#
# Drop-in replacement for "ld" that supports munching.
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.
##
## Symbols that produce a warning due to size changing.
## This is a harmless known bug with the version of gcc that comes with
## Tornado II. Anything in this list will be suppressed unless the -w
## option is used.
##
my(@symbols) = ('dequeue__t17ACE_Message_Queue1Z14ACE_NULL_SYNCHRP17ACE_Message_BlockP14ACE_Time_Value',
'activate__t17ACE_Message_Queue1Z14ACE_NULL_SYNCH',
);
$usage =
"usage: $0 [-? | [-w] [[-C <compile> --] [-m <munch>] [-n <nm>]] [-f]]] " .
"<ld command>\n";
#### To avoid quoting problems on the command line, all arguments
#### between -C and -- are combined into the single compile command.
$compile_option = 0;
$ss_change_warn = 0;
####
#### process command line args
####
while ( $#ARGV >= 0 && $ARGV[0] =~ /^-/ ) {
if ( $ARGV[0] eq '-C' ) {
$compile_option = 1;
if ( $ARGV[1] !~ /^[-].+$/ ) {
$compile = $ARGV[1]; shift;
} else {
print STDERR "$0: must provide argument for -c option\n";
die $usage;
}
} elsif ( $ARGV[0] eq '--' ) {
$compile_option = 0;
} elsif ( $ARGV[0] eq '-m' ) {
if ( $ARGV[1] !~ /^[-].+$/ ) {
$munch = $ARGV[1]; shift;
} else {
print STDERR "$0: must provide argument for -m option\n";
die $usage;
}
} elsif ( $ARGV[0] eq '-n' ) {
if ( $ARGV[1] !~ /^[-].+$/ ) {
$nm = $ARGV[1]; shift;
} else {
print STDERR "$0: must provide argument for -n option\n";
die $usage;
}
} elsif ( $ARGV[0] eq '-w' ) {
$ss_change_warn = 1;
} elsif ( $ARGV[0] eq '-?' ) {
print "$usage";
exit;
} else {
if ($compile_option) {
$compile .= " $ARGV[0]";
} else {
warn "$0: unknown option $ARGV[0]\n";
die $usage;
}
}
shift;
}
####
#### Save link command, i.e., current @ARGV, for use below.
####
@args = @ARGV;
####
#### Find full path to each library.
####
@libDirs = ();
$current_dir_in_libDirs = 0;
@libs = ();
@objs = '';
foreach $arg (@ARGV) {
if ($arg =~ /^['"]?-L([\S]+)/) {
($dir = $1) =~ s%/+$%%; #### trim any trailing slashes
push (@libDirs, $dir);
$current_dir_in_libDirs = 1 if $dir eq '.';
} elsif ($arg =~ /^['"]?-l([\S]+)/) {
push (@libs, $1);
} elsif ($arg =~ /\.o$/) {
push (@objs, $arg);
}
}
#### Add . to libDirs if it doesn't already have it.
push (@libDirs, ".") unless $current_dir_in_libDirs;
foreach $lib (@libs) {
foreach $libDir (@libDirs) {
if (-e "$libDir/lib$lib.a") {
$full_path{$lib} = "$libDir/lib$lib.a";
last;
}
}
}
####
#### Set up signal handler.
####
$done = 0;
$SIG{'HUP'} = $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'TERM'} = 'cleanup';
####
#### Munch, if $munch is non-null.
####
if ($munch) {
$munch_objs = join (' ', @objs);
$munch_libs = join (' ', values %full_path);
open (MUNCH, "$nm $munch_objs $munch_libs | $munch |") ||
&fail ("$0: unable to run \"$nm\" or \"$munch\"\n");
open (CTORDTOR, "> __ctordtor.c") ||
&fail ("$0: unable to open \"__ctordtor.c\"\n");
while (<MUNCH>) {
#### Filter out munch output that contains '.cpp'. It results from
#### .cpp files that have no text or data, e.g., .cpp files that
#### only contain template instantiations. These lines confuse g++.
print CTORDTOR unless /\.cpp/;
}
close CTORDTOR || &fail ("$0: unable to write \"__ctordtor.c\"\n");
close MUNCH;
system ("$compile -o .obj/__ctordtor.o __ctordtor.c") &&
&fail ("$0: \"$compile\" failed\n");
}
####
#### Construct the link command from @args and perform the link.
####
if ($munch) {
#### Insert ctordtor object file before first library in link command.
$arg_lib = 0;
foreach $arg (@ARGV) {
if ($arg =~ /^['"]?-l/) {
last;
}
++$arg_lib;
}
splice (@args, $arg_lib, 0, ".obj/__ctordtor.o");
}
$link_command = join (' ', @args);
if (open(PP, "$link_command 2>&1 |")) {
while(<PP>) {
my($line) = $_;
if ($ss_change_warn) {
print $line;
}
else {
my($found) = 0;
foreach my $symbol (@symbols) {
if ($line =~ /Warning: size of symbol `$symbol\'/) {
$found = 1;
}
}
if (!$found) {
print $line;
}
}
}
close(PP);
if ($? ne 0) {
fail ("$0: $link_command failed\n");
}
}
else {
fail ("$0: $link_command failed\n");
}
$done = 1;
&cleanup;
####
####
####
sub fail {
local ($message) = @_;
warn $message;
&cleanup;
}
####
#### clean up when done or on signal
####
sub cleanup {
unlink "__ctordtor.c", ".obj/__ctordtor.o";
if ($done) {
exit 0;
} else {
exit 1;
}
}
#### EOF
|