|
@@ -7,18 +7,34 @@ use constant WARNING_SIZE => 512;
|
7
|
7
|
|
8
|
8
|
my $symtab = {};
|
9
|
9
|
|
10
|
|
-# Scan output of "nm -o -S bin/blib.a" and build up symbol table
|
|
10
|
+# Scan output of "objdump -w -t bin/blib.a" and build up symbol table
|
11
|
11
|
#
|
|
12
|
+my $object;
|
12
|
13
|
while ( <> ) {
|
13
|
14
|
chomp;
|
14
|
|
- ( my $object, undef, my $value, undef, my $size, my $type, my $symbol )
|
15
|
|
- = /^.*?:(.*?\.o):((\S+)(\s+(\S+))?)?\s+(\S)\s+(\S+)$/;
|
16
|
|
- $symtab->{$object}->{$symbol} = {
|
17
|
|
- global => ( $type eq uc $type ),
|
18
|
|
- type => ( $type ),
|
19
|
|
- value => ( $value ? hex ( $value ) : 0 ),
|
20
|
|
- size => ( $size ? hex ( $size ) : 0 ),
|
21
|
|
- };
|
|
15
|
+ if ( /^In archive/ ) {
|
|
16
|
+ # Do nothing
|
|
17
|
+ } elsif ( /^$/ ) {
|
|
18
|
+ # Do nothing
|
|
19
|
+ } elsif ( /^(\S+\.o):\s+file format/ ) {
|
|
20
|
+ $object = $1;
|
|
21
|
+ } elsif ( /^SYMBOL TABLE:/ ) {
|
|
22
|
+ # Do nothing
|
|
23
|
+ } elsif ( /^([0-9a-fA-F]+)\s(l|g|\s)......\s(\S+)\s+([0-9a-fA-F]+)\s+(\S+)$/ ) {
|
|
24
|
+ my $value = $1;
|
|
25
|
+ my $scope = $2;
|
|
26
|
+ my $section = $3;
|
|
27
|
+ my $size = $4;
|
|
28
|
+ my $symbol = $5;
|
|
29
|
+ $symtab->{$object}->{$symbol} = {
|
|
30
|
+ global => ( $scope ne "l" ),
|
|
31
|
+ section => ( $section eq "*UND*" ? undef : $section ),
|
|
32
|
+ value => ( $value ? hex ( $value ) : 0 ),
|
|
33
|
+ size => ( $size ? hex ( $size ) : 0 ),
|
|
34
|
+ };
|
|
35
|
+ } else {
|
|
36
|
+ die "Unrecognized line \"$_\"";
|
|
37
|
+ }
|
22
|
38
|
}
|
23
|
39
|
|
24
|
40
|
# Add symbols that we know will be generated or required by the linker
|
|
@@ -29,16 +45,26 @@ foreach my $object ( keys %$symtab ) {
|
29
|
45
|
$obj_symbol =~ s/\W/_/g;
|
30
|
46
|
$symtab->{LINKER}->{$obj_symbol} = {
|
31
|
47
|
global => 1,
|
32
|
|
- type => 'U',
|
|
48
|
+ section => undef,
|
33
|
49
|
value => 0,
|
34
|
50
|
size => 0,
|
35
|
51
|
};
|
36
|
52
|
}
|
37
|
|
-foreach my $link_sym qw ( _prefix _eprefix _decompress _edecompress _text
|
38
|
|
- _etext _data _edata _bss _ebss _end ) {
|
|
53
|
+foreach my $link_sym qw ( __prefix _prefix _prefix_load_offset
|
|
54
|
+ _prefix_size _prefix_progbits_size _prefix_size_pgh
|
|
55
|
+ __text16 _text16 _text16_load_offset
|
|
56
|
+ _text16_size _text16_progbits_size _text16_size_pgh
|
|
57
|
+ __data16 _data16 _data16_load_offset
|
|
58
|
+ _data16_size _data16_progbits_size _data16_size_pgh
|
|
59
|
+ __text _text __data _data _textdata_load_offset
|
|
60
|
+ _textdata_size _textdata_progbits_size
|
|
61
|
+ __rodata __bss _end
|
|
62
|
+ _payload_offset _max_align
|
|
63
|
+ _load_size _load_size_pgh _load_size_sect
|
|
64
|
+ pci_vendor_id pci_device_id ) {
|
39
|
65
|
$symtab->{LINKER}->{$link_sym} = {
|
40
|
66
|
global => 1,
|
41
|
|
- type => 'A',
|
|
67
|
+ section => '*ABS*',
|
42
|
68
|
value => 0,
|
43
|
69
|
size => 0,
|
44
|
70
|
};
|
|
@@ -51,9 +77,15 @@ my $globals = {};
|
51
|
77
|
while ( ( my $object, my $symbols ) = each %$symtab ) {
|
52
|
78
|
while ( ( my $symbol, my $info ) = each %$symbols ) {
|
53
|
79
|
if ( $info->{global} ) {
|
54
|
|
- my $category = ( ( $info->{type} eq 'U' ? "requires" :
|
55
|
|
- ( $info->{type} eq 'C' ? "shares" : "provides" ) ) );
|
56
|
|
- $globals->{$symbol}->{$category}->{$object} = 1;
|
|
80
|
+ my $category;
|
|
81
|
+ if ( ! defined $info->{section} ) {
|
|
82
|
+ $category = "requires";
|
|
83
|
+ } elsif ( $info->{section} eq "*COM*" ) {
|
|
84
|
+ $category = "shares";
|
|
85
|
+ } else {
|
|
86
|
+ $category = "provides";
|
|
87
|
+ }
|
|
88
|
+ $globals->{$symbol}->{$category}->{$object} = $info->{section};
|
57
|
89
|
}
|
58
|
90
|
}
|
59
|
91
|
}
|
|
@@ -66,26 +98,22 @@ while ( ( my $symbol, my $info ) = each %$globals ) {
|
66
|
98
|
my @requires = keys %{$info->{requires}};
|
67
|
99
|
my @shares = keys %{$info->{shares}};
|
68
|
100
|
|
69
|
|
- if ( ( @provides == 0 ) && ( @shares == 1 ) ) {
|
70
|
|
- # A symbol "shared" by just a single file is actually being
|
71
|
|
- # provided by that file; it just doesn't have an initialiser.
|
72
|
|
- @provides = @shares;
|
73
|
|
- @shares = ();
|
74
|
|
- }
|
75
|
|
-
|
76
|
|
- if ( ( @requires > 0 ) && ( @provides == 0 ) ) {
|
|
101
|
+ if ( ( @requires > 0 ) && ( @provides == 0 ) && ( @shares == 0 ) ) {
|
77
|
102
|
# No object provides this symbol, but some objects require it.
|
78
|
103
|
$problems->{$_}->{nonexistent}->{$symbol} = 1 foreach @requires;
|
79
|
104
|
}
|
80
|
105
|
|
81
|
106
|
if ( ( @requires == 0 ) && ( @provides > 0 ) ) {
|
82
|
107
|
# No object requires this symbol, but some objects provide it.
|
83
|
|
- $problems->{$_}->{unused}->{$symbol} = 1 foreach @provides;
|
84
|
|
- }
|
85
|
|
-
|
86
|
|
- if ( ( @shares > 0 ) && ( @requires > 0 ) ) {
|
87
|
|
- # A shared symbol is being referenced from another object
|
88
|
|
- $problems->{$_}->{shared}->{$symbol} = 1 foreach @requires;
|
|
108
|
+ foreach my $provide ( @provides ) {
|
|
109
|
+ if ( $provide eq "LINKER" ) {
|
|
110
|
+ # Linker-provided symbols are exempt from this check.
|
|
111
|
+ } elsif ( $info->{provides}->{$provide} =~ /^\.tbl\./ ) {
|
|
112
|
+ # Linker tables are exempt from this check.
|
|
113
|
+ } else {
|
|
114
|
+ $problems->{$provide}->{unused}->{$symbol} = 1;
|
|
115
|
+ }
|
|
116
|
+ }
|
89
|
117
|
}
|
90
|
118
|
|
91
|
119
|
if ( ( @shares > 0 ) && ( @provides > 0 ) ) {
|
|
@@ -93,11 +121,6 @@ while ( ( my $symbol, my $info ) = each %$globals ) {
|
93
|
121
|
$problems->{$_}->{shared}->{$symbol} = 1 foreach @provides;
|
94
|
122
|
}
|
95
|
123
|
|
96
|
|
- if ( ( @shares > 0 ) && ! ( $symbol =~ /^_shared_/ ) ) {
|
97
|
|
- # A shared symbol is not declared via __shared
|
98
|
|
- $problems->{$_}->{shared}->{$symbol} = 1 foreach @shares;
|
99
|
|
- }
|
100
|
|
-
|
101
|
124
|
if ( @provides > 1 ) {
|
102
|
125
|
# A non-shared symbol is defined in multiple objects
|
103
|
126
|
$problems->{$_}->{multiples}->{$symbol} = 1 foreach @provides;
|
|
@@ -110,7 +133,8 @@ while ( ( my $symbol, my $info ) = each %$globals ) {
|
110
|
133
|
while ( ( my $object, my $symbols ) = each %$symtab ) {
|
111
|
134
|
while ( ( my $symbol, my $info ) = each %$symbols ) {
|
112
|
135
|
if ( ( ! $info->{global} ) &&
|
113
|
|
- ( ! ( $info->{type} =~ /^(t|r)$/ ) ) &&
|
|
136
|
+ ( ( defined $info->{section} ) &&
|
|
137
|
+ ! ( $info->{section} =~ /^(\.text|\.rodata)/ ) ) &&
|
114
|
138
|
( $info->{size} >= WARNING_SIZE ) ) {
|
115
|
139
|
$problems->{$object}->{large}->{$symbol} = 1;
|
116
|
140
|
}
|