line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SPVM::Builder::LinkInfo; |
2
|
|
|
|
|
|
|
|
3
|
280
|
|
|
280
|
|
68529
|
use strict; |
|
280
|
|
|
|
|
538
|
|
|
280
|
|
|
|
|
7889
|
|
4
|
280
|
|
|
280
|
|
1334
|
use warnings; |
|
280
|
|
|
|
|
521
|
|
|
280
|
|
|
|
|
6030
|
|
5
|
280
|
|
|
280
|
|
1337
|
use Config; |
|
280
|
|
|
|
|
603
|
|
|
280
|
|
|
|
|
11912
|
|
6
|
280
|
|
|
280
|
|
1811
|
use Carp 'confess'; |
|
280
|
|
|
|
|
615
|
|
|
280
|
|
|
|
|
14074
|
|
7
|
280
|
|
|
280
|
|
1820
|
use File::Basename 'dirname'; |
|
280
|
|
|
|
|
610
|
|
|
280
|
|
|
|
|
195652
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Fields |
10
|
|
|
|
|
|
|
sub config { |
11
|
276
|
|
|
276
|
1
|
2391
|
my $self = shift; |
12
|
276
|
100
|
|
|
|
1591
|
if (@_) { |
13
|
1
|
|
|
|
|
3
|
$self->{config} = $_[0]; |
14
|
1
|
|
|
|
|
3
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
else { |
17
|
275
|
|
|
|
|
1423
|
return $self->{config}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub output_file { |
22
|
611
|
|
|
611
|
1
|
2144
|
my $self = shift; |
23
|
611
|
100
|
|
|
|
2749
|
if (@_) { |
24
|
1
|
|
|
|
|
7
|
$self->{output_file} = $_[0]; |
25
|
1
|
|
|
|
|
3
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
610
|
|
|
|
|
3853
|
return $self->{output_file}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub object_files { |
33
|
956
|
|
|
956
|
1
|
2329
|
my $self = shift; |
34
|
956
|
100
|
|
|
|
3723
|
if (@_) { |
35
|
2
|
|
|
|
|
4
|
$self->{object_files} = $_[0]; |
36
|
2
|
|
|
|
|
5
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
954
|
|
|
|
|
5246
|
return $self->{object_files}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Class Methods |
44
|
|
|
|
|
|
|
sub new { |
45
|
344
|
|
|
344
|
1
|
1628
|
my $class = shift; |
46
|
|
|
|
|
|
|
|
47
|
344
|
|
|
|
|
5164
|
my $self = {@_}; |
48
|
|
|
|
|
|
|
|
49
|
344
|
|
|
|
|
2289
|
bless $self, $class; |
50
|
|
|
|
|
|
|
|
51
|
344
|
100
|
|
|
|
2776
|
unless (defined $self->object_files) { |
52
|
1
|
|
|
|
|
4
|
$self->object_files([]); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
344
|
|
|
|
|
1591
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Instance Methods |
59
|
|
|
|
|
|
|
sub create_link_command { |
60
|
2
|
|
|
2
|
1
|
16
|
my ($self) = @_; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
39
|
my $config = $self->config; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
56
|
my $ld = $config->ld; |
65
|
2
|
|
|
|
|
42
|
my $output_file = $self->output_file; |
66
|
2
|
|
|
|
|
30
|
my $object_files = $self->object_files; |
67
|
2
|
|
|
|
|
44
|
my $object_file_names = [map { $_->to_string; } @$object_files]; |
|
117
|
|
|
|
|
284
|
|
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
36
|
my $link_command_args = $self->create_link_command_args; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Note: Arguments of the link command(these contain -l flags) must be |
72
|
|
|
|
|
|
|
# after object file names for resolving symbol names properly |
73
|
2
|
|
|
|
|
60
|
my @link_command = ($ld, '-o', $output_file, @$object_file_names, @$link_command_args); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
34
|
return \@link_command; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub create_link_command_args { |
79
|
263
|
|
|
263
|
1
|
1244
|
my ($self) = @_; |
80
|
|
|
|
|
|
|
|
81
|
263
|
|
|
|
|
1857
|
my $config = $self->config; |
82
|
|
|
|
|
|
|
|
83
|
263
|
|
|
|
|
1249
|
my @merged_ldflags; |
84
|
|
|
|
|
|
|
|
85
|
263
|
50
|
|
|
|
1844
|
if (defined $config->ld_optimize) { |
86
|
263
|
|
|
|
|
2535
|
push @merged_ldflags, split(/ +/, $config->ld_optimize); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
263
|
|
|
|
|
2292
|
my $output_type = $config->output_type; |
90
|
263
|
100
|
|
|
|
1824
|
if ($output_type eq 'dynamic_lib') { |
91
|
259
|
|
|
|
|
923
|
push @merged_ldflags, @{$config->dynamic_lib_ldflags}; |
|
259
|
|
|
|
|
2497
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
263
|
|
|
|
|
1809
|
my $ldflags = $config->ldflags; |
95
|
263
|
|
|
|
|
1018
|
push @merged_ldflags, @{$config->ldflags}; |
|
263
|
|
|
|
|
1246
|
|
96
|
|
|
|
|
|
|
|
97
|
263
|
|
|
|
|
910
|
push @merged_ldflags, @{$config->thread_ldflags}; |
|
263
|
|
|
|
|
2639
|
|
98
|
|
|
|
|
|
|
|
99
|
263
|
|
|
|
|
1619
|
my $lib_dirs = $config->lib_dirs; |
100
|
|
|
|
|
|
|
|
101
|
263
|
|
|
|
|
1369
|
my @lib_dirs_ldflags = map { "-L$_" } @$lib_dirs; |
|
2
|
|
|
|
|
27
|
|
102
|
263
|
|
|
|
|
964
|
push @merged_ldflags, @lib_dirs_ldflags; |
103
|
|
|
|
|
|
|
|
104
|
263
|
|
|
|
|
876
|
my @lib_ldflags; |
105
|
263
|
|
|
|
|
1502
|
my $libs = $config->libs; |
106
|
263
|
|
|
|
|
2301
|
for my $lib (@$libs) { |
107
|
4
|
|
|
|
|
22
|
my $lib_ldflag; |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
|
|
|
31
|
unless (ref $lib) { |
110
|
0
|
|
|
|
|
0
|
$lib = SPVM::Builder::LibInfo->new(name => $lib); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
57
|
$lib_ldflag = $lib->to_arg; |
114
|
4
|
|
|
|
|
22
|
push @lib_ldflags, $lib_ldflag; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
263
|
|
|
|
|
1149
|
push @merged_ldflags, @lib_ldflags; |
118
|
|
|
|
|
|
|
|
119
|
263
|
|
|
|
|
2025
|
return \@merged_ldflags; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub to_cmd { |
123
|
2
|
|
|
2
|
1
|
32
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
51
|
my $link_command = $self->create_link_command; |
126
|
2
|
|
|
|
|
102
|
my $link_command_string = "@$link_command"; |
127
|
|
|
|
|
|
|
|
128
|
2
|
|
|
|
|
39
|
return $link_command_string; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 Name |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
SPVM::Builder::LinkInfo - Link Information |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 Description |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The SPVM::Builder::LinkInfo class has methods to manipulate link information. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 Usage |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $link_info = SPVM::Builder::LinkInfo->new(%fields); |
144
|
|
|
|
|
|
|
my $link_command_string = $link_info->to_cmd; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 Fields |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 config |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $config = $link_info->config; |
151
|
|
|
|
|
|
|
$link_info->config($config); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Gets and sets the C field. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This field is a L object used to link the object files. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 output_file |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $output_file = $link_info->output_file; |
160
|
|
|
|
|
|
|
$link_info->output_file($output_file); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Gets and sets the C field. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This field is an output file. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 object_files |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $object_files = $link_info->object_files; |
169
|
|
|
|
|
|
|
$link_info->object_files($object_files); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Gets and sets the C field. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This field is an array reference of L objects. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 Class Methods |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 new |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $link_info = SPVM::Builder::LinkInfo->new(%fields); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Creates a new C object with L"Fields">. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Default Field Values: |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
If a field is not defined, the field is set to the following default value. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over 2 |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * L"config"> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
undef |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * L"output_file"> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
undef |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item * L"object_files"> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
[] |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 Instance Methods |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 create_link_command |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my $link_command = $link_info->create_link_command; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Creates a link command, and returns it. The return value is an array reference. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
The following one is an example of the return value. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
[qw(cc -o dylib.so foo.o bar.o -shared -O2 -Llibdir -lz)] |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 create_link_command_args |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
my $link_command_args = $link_info->create_link_command_args; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Creates the parts of the arguments of the link command from the information of the L"config"> field, and returns it. The return value is an array reference. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The C<-o> option and the object file names are not contained. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
The following one is an example of the return value. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
[qw(-shared -O2 -Llibdir -lz)] |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 to_cmd |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $link_command_string = $link_info->to_cmd; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Calls the L method and joins all elements of the returned array reference with a space, and returns it. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
The following one is an example of the return value. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
"cc -o dylib.so foo.o bar.o -shared -O2 -Llibdir -lz" |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 Copyright & License |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Copyright (c) 2023 Yuki Kimoto |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
MIT License |