line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SPVM::Builder::LinkInfo; |
2
|
|
|
|
|
|
|
|
3
|
280
|
|
|
280
|
|
71044
|
use strict; |
|
280
|
|
|
|
|
613
|
|
|
280
|
|
|
|
|
8307
|
|
4
|
280
|
|
|
280
|
|
1448
|
use warnings; |
|
280
|
|
|
|
|
595
|
|
|
280
|
|
|
|
|
6264
|
|
5
|
280
|
|
|
280
|
|
1414
|
use Config; |
|
280
|
|
|
|
|
576
|
|
|
280
|
|
|
|
|
12873
|
|
6
|
280
|
|
|
280
|
|
1877
|
use Carp 'confess'; |
|
280
|
|
|
|
|
698
|
|
|
280
|
|
|
|
|
14533
|
|
7
|
280
|
|
|
280
|
|
1876
|
use File::Basename 'dirname'; |
|
280
|
|
|
|
|
683
|
|
|
280
|
|
|
|
|
203678
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Fields |
10
|
|
|
|
|
|
|
sub config { |
11
|
276
|
|
|
276
|
1
|
2138
|
my $self = shift; |
12
|
276
|
100
|
|
|
|
2031
|
if (@_) { |
13
|
1
|
|
|
|
|
3
|
$self->{config} = $_[0]; |
14
|
1
|
|
|
|
|
3
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
else { |
17
|
275
|
|
|
|
|
1801
|
return $self->{config}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub output_file { |
22
|
599
|
|
|
599
|
1
|
2173
|
my $self = shift; |
23
|
599
|
100
|
|
|
|
3073
|
if (@_) { |
24
|
1
|
|
|
|
|
8
|
$self->{output_file} = $_[0]; |
25
|
1
|
|
|
|
|
4
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
598
|
|
|
|
|
4526
|
return $self->{output_file}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub object_files { |
33
|
932
|
|
|
932
|
1
|
2797
|
my $self = shift; |
34
|
932
|
100
|
|
|
|
4259
|
if (@_) { |
35
|
2
|
|
|
|
|
5
|
$self->{object_files} = $_[0]; |
36
|
2
|
|
|
|
|
5
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
930
|
|
|
|
|
6301
|
return $self->{object_files}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Class Methods |
44
|
|
|
|
|
|
|
sub new { |
45
|
332
|
|
|
332
|
1
|
2019
|
my $class = shift; |
46
|
|
|
|
|
|
|
|
47
|
332
|
|
|
|
|
6593
|
my $self = {@_}; |
48
|
|
|
|
|
|
|
|
49
|
332
|
|
|
|
|
2484
|
bless $self, $class; |
50
|
|
|
|
|
|
|
|
51
|
332
|
100
|
|
|
|
3351
|
unless (defined $self->object_files) { |
52
|
1
|
|
|
|
|
4
|
$self->object_files([]); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
332
|
|
|
|
|
1981
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Instance Methods |
59
|
|
|
|
|
|
|
sub create_link_command { |
60
|
2
|
|
|
2
|
1
|
73
|
my ($self) = @_; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
58
|
my $config = $self->config; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
90
|
my $ld = $config->ld; |
65
|
2
|
|
|
|
|
75
|
my $output_file = $self->output_file; |
66
|
2
|
|
|
|
|
54
|
my $object_files = $self->object_files; |
67
|
2
|
|
|
|
|
61
|
my $object_file_names = [map { $_->to_string; } @$object_files]; |
|
117
|
|
|
|
|
557
|
|
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
53
|
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
|
|
|
|
|
94
|
my @link_command = ($ld, '-o', $output_file, @$object_file_names, @$link_command_args); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
62
|
return \@link_command; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub create_link_command_args { |
79
|
263
|
|
|
263
|
1
|
1585
|
my ($self) = @_; |
80
|
|
|
|
|
|
|
|
81
|
263
|
|
|
|
|
2379
|
my $config = $self->config; |
82
|
|
|
|
|
|
|
|
83
|
263
|
|
|
|
|
1355
|
my @merged_ldflags; |
84
|
|
|
|
|
|
|
|
85
|
263
|
50
|
|
|
|
2194
|
if (defined $config->ld_optimize) { |
86
|
263
|
|
|
|
|
2860
|
push @merged_ldflags, split(/ +/, $config->ld_optimize); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
263
|
|
|
|
|
2115
|
my $output_type = $config->output_type; |
90
|
263
|
100
|
|
|
|
1976
|
if ($output_type eq 'dynamic_lib') { |
91
|
259
|
|
|
|
|
1120
|
push @merged_ldflags, @{$config->dynamic_lib_ldflags}; |
|
259
|
|
|
|
|
2364
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
263
|
|
|
|
|
2006
|
my $ldflags = $config->ldflags; |
95
|
263
|
|
|
|
|
1076
|
push @merged_ldflags, @{$config->ldflags}; |
|
263
|
|
|
|
|
1512
|
|
96
|
|
|
|
|
|
|
|
97
|
263
|
|
|
|
|
1156
|
push @merged_ldflags, @{$config->thread_ldflags}; |
|
263
|
|
|
|
|
2653
|
|
98
|
|
|
|
|
|
|
|
99
|
263
|
|
|
|
|
1810
|
my $lib_dirs = $config->lib_dirs; |
100
|
|
|
|
|
|
|
|
101
|
263
|
|
|
|
|
1523
|
my @lib_dirs_ldflags = map { "-L$_" } @$lib_dirs; |
|
2
|
|
|
|
|
55
|
|
102
|
263
|
|
|
|
|
1083
|
push @merged_ldflags, @lib_dirs_ldflags; |
103
|
|
|
|
|
|
|
|
104
|
263
|
|
|
|
|
913
|
my @lib_ldflags; |
105
|
263
|
|
|
|
|
1756
|
my $libs = $config->libs; |
106
|
263
|
|
|
|
|
2619
|
for my $lib (@$libs) { |
107
|
4
|
|
|
|
|
21
|
my $lib_ldflag; |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
|
|
|
51
|
unless (ref $lib) { |
110
|
0
|
|
|
|
|
0
|
$lib = SPVM::Builder::LibInfo->new(name => $lib); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
60
|
$lib_ldflag = $lib->to_arg; |
114
|
4
|
|
|
|
|
29
|
push @lib_ldflags, $lib_ldflag; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
263
|
|
|
|
|
1527
|
push @merged_ldflags, @lib_ldflags; |
118
|
|
|
|
|
|
|
|
119
|
263
|
|
|
|
|
1870
|
return \@merged_ldflags; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub to_cmd { |
123
|
2
|
|
|
2
|
1
|
61
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
74
|
my $link_command = $self->create_link_command; |
126
|
2
|
|
|
|
|
223
|
my $link_command_string = "@$link_command"; |
127
|
|
|
|
|
|
|
|
128
|
2
|
|
|
|
|
64
|
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 |