~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/verify_builtin_ranges.awk

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/verify_builtin_ranges.awk (Version linux-6.12-rc7) and /scripts/verify_builtin_ranges.awk (Version linux-6.7.12)


  1 #!/usr/bin/gawk -f                                
  2 # SPDX-License-Identifier: GPL-2.0                
  3 # verify_builtin_ranges.awk: Verify address ra    
  4 # Written by Kris Van Hees <kris.van.hees@oracl    
  5 #                                                 
  6 # Usage: verify_builtin_ranges.awk modules.bui    
  7 #                                  modules.bui    
  8 #                                                 
  9                                                   
 10 # Return the module name(s) (if any) associate    
 11 #                                                 
 12 # If we have seen this object before, return i    
 13 # Otherwise, retrieve it from the correspondin    
 14 #                                                 
 15 function get_module_info(fn, mod, obj, s) {       
 16         if (fn in omod)                           
 17                 return omod[fn];                  
 18                                                   
 19         if (match(fn, /\/[^/]+$/) == 0)           
 20                 return "";                        
 21                                                   
 22         obj = fn;                                 
 23         mod = "";                                 
 24         fn = substr(fn, 1, RSTART) "." substr(    
 25         if (getline s <fn == 1) {                 
 26                 if (match(s, /DKBUILD_MODFILE=    
 27                         mod = substr(s, RSTART    
 28                         gsub(/['"]/, "", mod);    
 29                 } else if (match(s, /RUST_MODF    
 30                         mod = substr(s, RSTART    
 31         } else {                                  
 32                 print "ERROR: Failed to read:     
 33                       "  For kernels built wit    
 34                       "  and execute this scri    
 35                       >"/dev/stderr";             
 36                 close(fn);                        
 37                 total = 0;                        
 38                 exit(1);                          
 39         }                                         
 40         close(fn);                                
 41                                                   
 42         # A single module (common case) also r    
 43         # of a module.  Some of those objects     
 44         # name (e.g. core).  We check the asso    
 45         # they do not match, the object is not    
 46         if (mod !~ / /) {                         
 47                 if (!(mod in mods))               
 48                         mod = "";                 
 49         }                                         
 50                                                   
 51         gsub(/([^/ ]*\/)+/, "", mod);             
 52         gsub(/-/, "_", mod);                      
 53                                                   
 54         # At this point, mod is a single (vali    
 55         # module names (that do not need valid    
 56         omod[obj] = mod;                          
 57                                                   
 58         return mod;                               
 59 }                                                 
 60                                                   
 61 # Return a representative integer value for a     
 62 #                                                 
 63 # Since all kernel addresses fall within the s    
 64 # strip off the first 6 hex digits before perf    
 65 # thereby avoiding integer overflows.             
 66 #                                                 
 67 function addr2val(val) {                          
 68         sub(/^0x/, "", val);                      
 69         if (length(val) == 16)                    
 70                 val = substr(val, 5);             
 71         return strtonum("0x" val);                
 72 }                                                 
 73                                                   
 74 # Determine the kernel build directory to use     
 75 #                                                 
 76 BEGIN {                                           
 77         if (ARGC < 6) {                           
 78                 print "Syntax: verify_builtin_    
 79                       "          <builtin-file    
 80                       >"/dev/stderr";             
 81                 total = 0;                        
 82                 exit(1);                          
 83         }                                         
 84 }                                                 
 85                                                   
 86 # (1) Load the built-in module address range d    
 87 #                                                 
 88 ARGIND == 1 {                                     
 89         ranges[FNR] = $0;                         
 90         rcnt++;                                   
 91         next;                                     
 92 }                                                 
 93                                                   
 94 # (2) Annotate System.map symbols with module     
 95 #                                                 
 96 ARGIND == 2 {                                     
 97         addr = addr2val($1);                      
 98         name = $3;                                
 99                                                   
100         while (addr >= mod_eaddr) {               
101                 if (sect_symb) {                  
102                         if (sect_symb != name)    
103                                 next;             
104                                                   
105                         sect_base = addr - sec    
106                         if (dbg)                  
107                                 printf "[%s] B    
108                         sect_symb = 0;            
109                 }                                 
110                                                   
111                 if (++ridx > rcnt)                
112                         break;                    
113                                                   
114                 $0 = ranges[ridx];                
115                 sub(/-/, " ");                    
116                 if ($4 != "=") {                  
117                         sub(/-/, " ");            
118                         mod_saddr = strtonum("    
119                         mod_eaddr = strtonum("    
120                         $1 = $2 = $3 = "";        
121                         sub(/^ +/, "");           
122                         mod_name = $0;            
123                                                   
124                         if (dbg)                  
125                                 printf "[%s] %    
126                 } else {                          
127                         sect_name = $1;           
128                         sect_off = strtonum("0    
129                         sect_symb = $5;           
130                 }                                 
131         }                                         
132                                                   
133         idx = addr"-"name;                        
134         if (addr >= mod_saddr && addr < mod_ea    
135                 sym2mod[idx] = mod_name;          
136                                                   
137         next;                                     
138 }                                                 
139                                                   
140 # Once we are done annotating the System.map,     
141 #                                                 
142 FNR == 1 && ARGIND == 3 {                         
143         delete ranges;                            
144 }                                                 
145                                                   
146 # (3) Build a lookup map of built-in module na    
147 #                                                 
148 # Lines from modules.builtin will be like:        
149 #       kernel/crypto/lzo-rle.ko                  
150 # and we record the object name "crypto/lzo-rl    
151 #                                                 
152 ARGIND == 3 {                                     
153         sub(/kernel\//, "");                      
154         sub(/\.ko$/, "");                         
155                                                   
156         mods[$1] = 1;                             
157         next;                                     
158 }                                                 
159                                                   
160 # (4) Get a list of symbols (per object).         
161 #                                                 
162 # Symbols by object are read from vmlinux.map,    
163 # if vmlinux is found to have inked in vmlinux    
164 #                                                 
165                                                   
166 # If we were able to get the data we need from    
167 # process vmlinux.o.map.                          
168 #                                                 
169 FNR == 1 && ARGIND == 5 && total > 0 {            
170         if (dbg)                                  
171                 printf "Note: %s is not needed    
172         exit;                                     
173 }                                                 
174                                                   
175 # First determine whether we are dealing with     
176 #                                                 
177 ARGIND >= 4 && FNR == 1 && NF == 7 && $1 == "V    
178         map_is_lld = 1;                           
179         next;                                     
180 }                                                 
181                                                   
182 # (LLD) Convert a section record fronm lld for    
183 #                                                 
184 ARGIND >= 4 && map_is_lld && NF == 5 && /[0-9]    
185         $0 = $5 " 0x"$1 " 0x"$3 " load address    
186 }                                                 
187                                                   
188 # (LLD) Convert an object record from lld form    
189 #                                                 
190 ARGIND >= 4 && map_is_lld && NF == 5 && $5 ~ /    
191         if (/\.a\(/ && !/ vmlinux\.a\(/)          
192                 next;                             
193                                                   
194         gsub(/\)/, "");                           
195         sub(/:\(/, " ");                          
196         sub(/ vmlinux\.a\(/, " ");                
197         $0 = " "$6 " 0x"$1 " 0x"$3 " " $5;        
198 }                                                 
199                                                   
200 # (LLD) Convert a symbol record from lld forma    
201 #                                                 
202 ARGIND >= 4 && map_is_lld && NF == 5 && $5 ~ /    
203         $0 = "  0x" $1 " " $5;                    
204 }                                                 
205                                                   
206 # (LLD) We do not need any other ldd linker ma    
207 #                                                 
208 ARGIND >= 4 && map_is_lld && /^[0-9a-f]{16} /     
209         next;                                     
210 }                                                 
211                                                   
212 # Handle section records with long section nam    
213 #                                                 
214 ARGIND >= 4 && !map_is_lld && NF == 1 && /^[^     
215         s = $0;                                   
216         getline;                                  
217         $0 = s " " $0;                            
218 }                                                 
219                                                   
220 # Next section - previous one is done.            
221 #                                                 
222 ARGIND >= 4 && /^[^ ]/ {                          
223         sect = 0;                                 
224 }                                                 
225                                                   
226 # Get the (top level) section name.               
227 #                                                 
228 ARGIND >= 4 && /^\./ {                            
229         # Explicitly ignore a few sections tha    
230         if ($1 ~ /^\.orc_/ || $1 ~ /_sites$/ |    
231                 next;                             
232                                                   
233         # Sections with a 0-address can be ign    
234         if (ARGIND == 4 && $2 ~ /^0x0+$/)         
235                 next;                             
236                                                   
237         sect = $1;                                
238                                                   
239         next;                                     
240 }                                                 
241                                                   
242 # If we are not currently in a section we care    
243 #                                                 
244 !sect {                                           
245         next;                                     
246 }                                                 
247                                                   
248 # Handle object records with long section name    
249 #                                                 
250 ARGIND >= 4 && /^ [^ \*]/ && NF == 1 {            
251         # If the section name is long, the rem    
252         # the next line.                          
253         s = $0;                                   
254         getline;                                  
255         $0 = s " " $0;                            
256 }                                                 
257                                                   
258 # Objects linked in from static libraries are     
259 # If the object is vmlinux.o, we need to consu    
260 # symbol information                              
261 #                                                 
262 ARGIND == 4 && /^ [^ ]/ && NF == 4 {              
263         if ($4 ~ /\.a\(/)                         
264                 next;                             
265                                                   
266         idx = sect":"$1;                          
267         if (!(idx in sect_addend)) {              
268                 sect_addend[idx] = addr2val($2    
269                 if (dbg)                          
270                         printf "ADDEND %s = %0    
271         }                                         
272         if ($4 == "vmlinux.o") {                  
273                 need_o_map = 1;                   
274                 next;                             
275         }                                         
276 }                                                 
277                                                   
278 # If data from vmlinux.o.map is needed, we onl    
279 # records from vmlinux.map to determine which     
280 # to in vmlinux.o.map.  So skip everything els    
281 #                                                 
282 ARGIND == 4 && need_o_map {                       
283         next;                                     
284 }                                                 
285                                                   
286 # Get module information for the current objec    
287 #                                                 
288 ARGIND >= 4 && /^ [^ ]/ && NF == 4 {              
289         msect = $1;                               
290         mod_name = get_module_info($4);           
291         mod_eaddr = addr2val($2) + addr2val($3    
292                                                   
293         next;                                     
294 }                                                 
295                                                   
296 # Process a symbol record.                        
297 #                                                 
298 # Evaluate the module information obtained fro    
299 # as follows:                                     
300 #  - For all symbols in a given object:           
301 #     - If the symbol is annotated with the sa    
302 #       belongs to, count it as a match.          
303 #     - Otherwise:                                
304 #        - If the symbol is known to have dupl    
305 #          in a built-in module, disregard it.    
306 #        - If the symbol us not annotated with    
307 #          object belongs to built-in modules,    
308 #        - Otherwise, count it as a mismatch.     
309 #                                                 
310 ARGIND >= 4 && /^ / && NF == 2 && $1 ~ /^0x/ {    
311         idx = sect":"msect;                       
312         if (!(idx in sect_addend))                
313                 next;                             
314                                                   
315         addr = addr2val($1);                      
316                                                   
317         # Handle the rare but annoying case wh    
318         # the byte *after* the module range.      
319         # considered part of the current objec    
320         # module address range.  Unfortunately    
321         # start of another built-in module, so    
322         # ignore it.                              
323         if (mod_name && addr == mod_eaddr)        
324                 next;                             
325                                                   
326         # If we are processing vmlinux.o.map,     
327         # of the section to the relative addre    
328         #                                         
329         if (ARGIND == 5)                          
330                 addr += sect_addend[idx];         
331                                                   
332         idx = addr"-"$2;                          
333         mod = "";                                 
334         if (idx in sym2mod) {                     
335                 mod = sym2mod[idx];               
336                 if (sym2mod[idx] == mod_name)     
337                         mod_matches++;            
338                         matches++;                
339                 } else if (mod_name == "") {      
340                         print $2 " in " mod "     
341                         mismatches++;             
342                 } else {                          
343                         print $2 " in " mod "     
344                         mismatches++;             
345                 }                                 
346         } else if (mod_name != "") {              
347                 print $2 " should be in " mod_    
348                 missing++;                        
349         } else                                    
350                 matches++;                        
351                                                   
352         total++;                                  
353                                                   
354         next;                                     
355 }                                                 
356                                                   
357 # Issue the comparison report.                    
358 #                                                 
359 END {                                             
360         if (total) {                              
361                 printf "Verification of %s:\n"    
362                 printf "  Correct matches:  %6    
363                 printf "    Module matches: %6    
364                 printf "  Mismatches:       %6    
365                 printf "  Missing:          %6    
366                                                   
367                 if (mismatches || missing)        
368                         exit(1);                  
369         }                                         
370 }                                                 
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php