tokuglobals.py 1.85 KB
Newer Older
1 2 3 4
#!/usr/bin/python

import sys
import os
5
import stat
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import re

def checkglobals(libname, exceptsymbols, verbose):
    badglobals = 0
    nmcmd = "nm -g " + libname
    f = os.popen(nmcmd)
    b = f.readline()
    while b != "":
        match = re.match("^([0-9a-f]+)\s(.?)\s(.*)$", b)
        if match == None:
            match = re.match("^\s+(.*)$", b)
            if match == None:
                print "unknown", b
                badglobals = 1
        else:
            type = match.group(2)
            symbol = match.group(3)
            if verbose: print type, symbol
24
            match = re.match("^toku_|^__toku", symbol)
25 26 27 28 29 30 31 32 33
            if match == None and not exceptsymbols.has_key(symbol):
                print "non toku symbol=", symbol
                badglobals = 1
        b = f.readline()
    f.close()
    return badglobals

def main():
    verbose = 0
34
    libname = "libdb.so"
35 36 37
    for arg in sys.argv[1:]:
        if arg == "-v":
            verbose += 1
38 39 40 41 42 43 44 45
        elif arg[0:3] == "lib":
            libname = arg

    try: st = os.stat(libname)
    except: return 1
    mode = st[stat.ST_MODE]
    if not (mode & stat.S_IREAD): return 1

46 47 48
    exceptsymbols = {}
    for n in [ "_init", "_fini", "_end", "_edata", "__bss_start" ]:
        exceptsymbols[n] = 1
49 50 51 52 53 54 55 56
    for n in [ "db_env_create", "db_create", "db_strerror", "db_version", "log_compare", 
               "db_env_set_func_fsync", 
               "db_env_set_func_free", 
               "db_env_set_func_malloc", 
               "db_env_set_func_realloc", 
               "db_env_set_func_pwrite", 
               "db_env_set_func_write", 
               "db_env_set_checkpoint_callback",
57
               "db_env_set_checkpoint_callback2",
58
               "setup_dlmalloc", "dlfree", "dlmalloc", "dlrealloc" ]:
59
        exceptsymbols[n] = 1
60
    return checkglobals(libname, exceptsymbols, verbose)
61 62
    
sys.exit(main())