Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / src / check-static-inits.py
1 #!/usr/bin/env python3
2
3 import sys, os, shutil, subprocess, glob, re
4
5 builddir = os.environ.get ('builddir', os.path.dirname (__file__))
6 libs = os.environ.get ('libs', '.libs')
7
8 objdump = shutil.which ('objdump')
9 if not objdump:
10         print ('check-static-inits.py: \'ldd\' not found; skipping test')
11         sys.exit (77)
12
13 if sys.version_info < (3, 5):
14         print ('check-static-inits.py: needs python 3.5 for recursive support in glob')
15         sys.exit (77)
16
17 OBJS = glob.glob (os.path.join (builddir, libs, '**', '*.o'), recursive=True)
18 if not OBJS:
19         print ('check-static-inits.py: object files not found; skipping test')
20         sys.exit (77)
21
22 stat = 0
23
24 for obj in OBJS:
25         result = subprocess.check_output ([objdump, '-t', obj]).decode ('utf-8')
26
27         # Checking that no object file has static initializers
28         for l in re.findall (r'^.*\.[cd]tors.*$', result, re.MULTILINE):
29                 if not re.match (r'.*\b0+\b', l):
30                         print ('Ouch, %s has static initializers/finalizers' % obj)
31                         stat = 1
32
33         # Checking that no object file has lazy static C++ constructors/destructors or other such stuff
34         if ('__cxa_' in result) and ('__ubsan_handle' not in result):
35                 print ('Ouch, %s has lazy static C++ constructors/destructors or other such stuff' % obj)
36                 stat = 1
37
38 sys.exit (stat)