Browse Source

Report on misuses of shared symbols, and excessively large static symbols.

tags/v0.9.3
Michael Brown 20 years ago
parent
commit
35ab3bf808
1 changed files with 55 additions and 9 deletions
  1. 55
    9
      src/util/symcheck.pl

+ 55
- 9
src/util/symcheck.pl View File

44
   };
44
   };
45
 }
45
 }
46
 
46
 
47
-# Build up requires and provides tables for global symbols
47
+# Build up requires, provides and shares symbol tables for global
48
+# symbols
49
+#
48
 my $globals = {};
50
 my $globals = {};
49
 while ( ( my $object, my $symbols ) = each %$symtab ) {
51
 while ( ( my $object, my $symbols ) = each %$symtab ) {
50
   while ( ( my $symbol, my $info ) = each %$symbols ) {
52
   while ( ( my $symbol, my $info ) = each %$symbols ) {
51
     if ( $info->{global} ) {
53
     if ( $info->{global} ) {
52
-      my $category = ( ( $info->{type} eq 'U' ? "requires" : "provides" ) );
54
+      my $category = ( ( $info->{type} eq 'U' ? "requires" :
55
+			 ( $info->{type} eq 'C' ? "shares" : "provides" ) ) );
53
       $globals->{$symbol}->{$category}->{$object} = 1;
56
       $globals->{$symbol}->{$category}->{$object} = 1;
54
     }
57
     }
55
   }
58
   }
61
 while ( ( my $symbol, my $info ) = each %$globals ) {
64
 while ( ( my $symbol, my $info ) = each %$globals ) {
62
   my @provides = keys %{$info->{provides}};
65
   my @provides = keys %{$info->{provides}};
63
   my @requires = keys %{$info->{requires}};
66
   my @requires = keys %{$info->{requires}};
67
+  my @shares = keys %{$info->{shares}};
68
+
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
+  }
64
 
75
 
65
-  if ( @provides == 0 ) {
66
-    # No object provides this symbol
76
+  if ( ( @requires > 0 ) && ( @provides == 0 ) ) {
77
+    # No object provides this symbol, but some objects require it.
67
     $problems->{$_}->{nonexistent}->{$symbol} = 1 foreach @requires;
78
     $problems->{$_}->{nonexistent}->{$symbol} = 1 foreach @requires;
68
-  } elsif ( @provides > 1 ) {
69
-    # Symbol defined in multiple objects
70
-    $problems->{$_}->{multiples}->{$symbol} = 1 foreach @provides;
71
   }
79
   }
72
-  if ( @requires == 0 ) {
73
-    # Symbol not required
80
+
81
+  if ( ( @requires == 0 ) && ( @provides > 0 ) ) {
82
+    # No object requires this symbol, but some objects provide it.
74
     $problems->{$_}->{unused}->{$symbol} = 1 foreach @provides;
83
     $problems->{$_}->{unused}->{$symbol} = 1 foreach @provides;
75
   }
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;
89
+  }
90
+
91
+  if ( ( @shares > 0 ) && ( @provides > 0 ) ) {
92
+    # A shared symbol is being initialised by an object
93
+    $problems->{$_}->{shared}->{$symbol} = 1 foreach @provides;
94
+  }
95
+
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
+  if ( @provides > 1 ) {
102
+    # A non-shared symbol is defined in multiple objects
103
+    $problems->{$_}->{multiples}->{$symbol} = 1 foreach @provides;
104
+  }
105
+}
106
+
107
+# Check for excessively large local symbols
108
+#
109
+while ( ( my $object, my $symbols ) = each %$symtab ) {
110
+  while ( ( my $symbol, my $info ) = each %$symbols ) {
111
+    if ( ( ! $info->{global} ) &&
112
+	 ( $info->{type} ne 't' ) &&
113
+	 ( $info->{size} >= WARNING_SIZE ) ) {
114
+      $problems->{$object}->{large}->{$symbol} = 1;
115
+    }
116
+  }
76
 }
117
 }
77
 
118
 
78
 # Print out error messages
119
 # Print out error messages
83
   my @nonexistent = sort keys %{$problems->{$object}->{nonexistent}};
124
   my @nonexistent = sort keys %{$problems->{$object}->{nonexistent}};
84
   my @multiples = sort keys %{$problems->{$object}->{multiples}};
125
   my @multiples = sort keys %{$problems->{$object}->{multiples}};
85
   my @unused = sort keys %{$problems->{$object}->{unused}};
126
   my @unused = sort keys %{$problems->{$object}->{unused}};
127
+  my @shared = sort keys %{$problems->{$object}->{shared}};
128
+  my @large = sort keys %{$problems->{$object}->{large}};
86
 
129
 
87
   print "WARN $object provides unused symbol $_\n" foreach @unused;
130
   print "WARN $object provides unused symbol $_\n" foreach @unused;
88
   $warnings += @unused;
131
   $warnings += @unused;
132
+  print "WARN $object has large static symbol $_\n" foreach @large;
133
+  $warnings += @large;
89
   print "ERR  $object requires non-existent symbol $_\n" foreach @nonexistent;
134
   print "ERR  $object requires non-existent symbol $_\n" foreach @nonexistent;
90
   $errors += @nonexistent;
135
   $errors += @nonexistent;
91
   foreach my $symbol ( @multiples ) {
136
   foreach my $symbol ( @multiples ) {
95
 	." (also provided by @other_objects)\n";
140
 	." (also provided by @other_objects)\n";
96
   }
141
   }
97
   $errors += @multiples;
142
   $errors += @multiples;
143
+  print "ERR  $object misuses shared symbol $_\n" foreach @shared;
98
 }
144
 }
99
 
145
 
100
 print "$errors error(s), $warnings warning(s)\n";
146
 print "$errors error(s), $warnings warning(s)\n";

Loading…
Cancel
Save