@@ -19,6 +19,8 @@ def get_public_symbols_from_shared_object(prefix):
19
19
nm_output_bytes = subprocess .check_output (nm_command )
20
20
nm_output = nm_output_bytes .decode (encoding = "utf-8" )
21
21
symbols = {line .split ()[2 ] for line in nm_output .splitlines ()}
22
+ symbols = symbols .difference ({"__bss_start" , "_edata" , "_end" , "_fini" ,
23
+ "_init" })
22
24
return symbols
23
25
24
26
@@ -50,11 +52,17 @@ def get_public_symbols_from_header(header_path):
50
52
content = header_file .read ()
51
53
prototypes = prototype_regex .findall (content )
52
54
function_name_regex = re .compile (r"([a-zA-Z0-9_]+)\s*\(.*\)" )
55
+ data_name_regex = re .compile (r"\s+([a-zA-Z0-9_]+)\s*;" )
53
56
for p in prototypes :
54
57
p = p .replace ("\n " , " " )
55
- f_match = function_name_regex .search (p )
56
- f_name = f_match .group (1 ) if f_match else "unknown"
57
- symbols .add (f_name )
58
+ match = function_name_regex .search (p )
59
+ if not match :
60
+ match = data_name_regex .search (p )
61
+ if not match :
62
+ print ("Invalid prototype '%s'" % p , file = sys .stderr )
63
+ continue
64
+ symbol_name = match .group (1 )
65
+ symbols .add (symbol_name )
58
66
return symbols
59
67
60
68
@@ -137,17 +145,19 @@ def main():
137
145
print ()
138
146
139
147
so_only = so_symbols .difference (header_symbols )
140
- print ("The following %d symbols are exported in binary, "
141
- "but are not present in public header files:" % len (so_only ))
142
- for s in sorted (so_only ):
143
- print (s )
144
- print ()
148
+ if so_only :
149
+ print ("The following %d symbols are exported in binary, "
150
+ "but are not present in public header files:" % len (so_only ))
151
+ for s in sorted (so_only ):
152
+ print (s )
153
+ print ()
145
154
146
155
header_only = header_symbols .difference (so_symbols )
147
- print ("The following %d symbols are present in public header files, "
148
- "but are not exported in binary:" % len (header_only ))
149
- for s in sorted (header_only ):
150
- print (s )
156
+ if header_only :
157
+ print ("The following %d symbols are present in public header files, "
158
+ "but are not exported in binary:" % len (header_only ))
159
+ for s in sorted (header_only ):
160
+ print (s )
151
161
152
162
153
163
if __name__ == "__main__" :
0 commit comments